From fbd86a7cc3c791a161f150f3e2a07d7432a5b39c Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Wed, 13 Sep 2023 20:08:55 +0200 Subject: fix(frontend): keep live while model generation Do not close the connection in a background tab if the model generation is still running, because closing the connection will immediately cancel generation. --- subprojects/frontend/src/xtext/XtextClient.ts | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'subprojects/frontend/src/xtext/XtextClient.ts') diff --git a/subprojects/frontend/src/xtext/XtextClient.ts b/subprojects/frontend/src/xtext/XtextClient.ts index 77980d35..4df4f57a 100644 --- a/subprojects/frontend/src/xtext/XtextClient.ts +++ b/subprojects/frontend/src/xtext/XtextClient.ts @@ -9,6 +9,7 @@ import type { CompletionResult, } from '@codemirror/autocomplete'; import type { Transaction } from '@codemirror/state'; +import { type IReactionDisposer, reaction } from 'mobx'; import type PWAStore from '../PWAStore'; import type EditorStore from '../editor/EditorStore'; @@ -43,6 +44,8 @@ export default class XtextClient { private readonly modelGenerationService: ModelGenerationService; + private readonly keepAliveDisposer: IReactionDisposer; + constructor( private readonly store: EditorStore, private readonly pwaStore: PWAStore, @@ -65,6 +68,11 @@ export default class XtextClient { store, this.updateService, ); + this.keepAliveDisposer = reaction( + () => store.generating, + (generating) => this.webSocketClient.setKeepAlive(generating), + { fireImmediately: true }, + ); } start(): void { @@ -157,6 +165,7 @@ export default class XtextClient { } dispose(): void { + this.keepAliveDisposer(); this.webSocketClient.disconnect(); } } -- cgit v1.2.3-70-g09d2