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/webSocketMachine.ts | 40 +++++++++++++++++++--- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'subprojects/frontend/src/xtext/webSocketMachine.ts') diff --git a/subprojects/frontend/src/xtext/webSocketMachine.ts b/subprojects/frontend/src/xtext/webSocketMachine.ts index 2fb1f52f..9113286f 100644 --- a/subprojects/frontend/src/xtext/webSocketMachine.ts +++ b/subprojects/frontend/src/xtext/webSocketMachine.ts @@ -27,6 +27,8 @@ export type WebSocketEvent = | { type: 'PAGE_RESUME' } | { type: 'ONLINE' } | { type: 'OFFLINE' } + | { type: 'GENERATION_STARTED' } + | { type: 'GENERATION_ENDED' } | { type: 'ERROR'; message: string }; export default createMachine( @@ -105,7 +107,7 @@ export default createMachine( initial: 'opening', states: { opening: { - always: [{ target: '#timedOut', in: '#tabHidden' }], + always: [{ target: '#timedOut', in: '#mayDisconnect' }], after: { OPEN_TIMEOUT: { actions: 'raiseTimeoutError', @@ -143,7 +145,7 @@ export default createMachine( initial: 'active', states: { active: { - always: [{ target: 'inactive', in: '#tabHidden' }], + always: [{ target: 'inactive', in: '#mayDisconnect' }], }, inactive: { always: [{ target: 'active', in: '#tabVisible' }], @@ -173,14 +175,44 @@ export default createMachine( visibleOrUnknown: { id: 'tabVisible', on: { - TAB_HIDDEN: 'hidden', + TAB_HIDDEN: [ + { target: 'hidden.mayDisconnect', in: '#generationIdle' }, + { target: 'hidden.keepAlive', in: '#generationRunning' }, + ], }, }, hidden: { - id: 'tabHidden', on: { TAB_VISIBLE: 'visibleOrUnknown', }, + initial: 'mayDisconnect', + states: { + mayDisconnect: { + id: 'mayDisconnect', + always: { target: 'keepAlive', in: '#generationRunning' }, + }, + keepAlive: { + id: 'keepAlive', + always: { target: 'mayDisconnect', in: '#generationIdle' }, + }, + }, + }, + }, + }, + generation: { + initial: 'idle', + states: { + idle: { + id: 'generationIdle', + on: { + GENERATION_STARTED: 'running', + }, + }, + running: { + id: 'generationRunning', + on: { + GENERATION_ENDED: 'idle', + }, }, }, }, -- cgit v1.2.3-54-g00ecf