diff options
Diffstat (limited to 'subprojects/frontend/src')
-rw-r--r-- | subprojects/frontend/src/xtext/XtextClient.ts | 9 | ||||
-rw-r--r-- | subprojects/frontend/src/xtext/XtextWebSocketClient.ts | 6 | ||||
-rw-r--r-- | subprojects/frontend/src/xtext/webSocketMachine.ts | 40 |
3 files changed, 51 insertions, 4 deletions
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 { | |||
9 | CompletionResult, | 9 | CompletionResult, |
10 | } from '@codemirror/autocomplete'; | 10 | } from '@codemirror/autocomplete'; |
11 | import type { Transaction } from '@codemirror/state'; | 11 | import type { Transaction } from '@codemirror/state'; |
12 | import { type IReactionDisposer, reaction } from 'mobx'; | ||
12 | 13 | ||
13 | import type PWAStore from '../PWAStore'; | 14 | import type PWAStore from '../PWAStore'; |
14 | import type EditorStore from '../editor/EditorStore'; | 15 | import type EditorStore from '../editor/EditorStore'; |
@@ -43,6 +44,8 @@ export default class XtextClient { | |||
43 | 44 | ||
44 | private readonly modelGenerationService: ModelGenerationService; | 45 | private readonly modelGenerationService: ModelGenerationService; |
45 | 46 | ||
47 | private readonly keepAliveDisposer: IReactionDisposer; | ||
48 | |||
46 | constructor( | 49 | constructor( |
47 | private readonly store: EditorStore, | 50 | private readonly store: EditorStore, |
48 | private readonly pwaStore: PWAStore, | 51 | private readonly pwaStore: PWAStore, |
@@ -65,6 +68,11 @@ export default class XtextClient { | |||
65 | store, | 68 | store, |
66 | this.updateService, | 69 | this.updateService, |
67 | ); | 70 | ); |
71 | this.keepAliveDisposer = reaction( | ||
72 | () => store.generating, | ||
73 | (generating) => this.webSocketClient.setKeepAlive(generating), | ||
74 | { fireImmediately: true }, | ||
75 | ); | ||
68 | } | 76 | } |
69 | 77 | ||
70 | start(): void { | 78 | start(): void { |
@@ -157,6 +165,7 @@ export default class XtextClient { | |||
157 | } | 165 | } |
158 | 166 | ||
159 | dispose(): void { | 167 | dispose(): void { |
168 | this.keepAliveDisposer(); | ||
160 | this.webSocketClient.disconnect(); | 169 | this.webSocketClient.disconnect(); |
161 | } | 170 | } |
162 | } | 171 | } |
diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts index 963c1d4c..bb84223c 100644 --- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts +++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts | |||
@@ -270,6 +270,12 @@ export default class XtextWebSocketClient { | |||
270 | return promise; | 270 | return promise; |
271 | } | 271 | } |
272 | 272 | ||
273 | setKeepAlive(keepAlive: boolean): void { | ||
274 | this.interpreter.send({ | ||
275 | type: keepAlive ? 'GENERATION_STARTED' : 'GENERATION_ENDED', | ||
276 | }); | ||
277 | } | ||
278 | |||
273 | private updateVisibility(): void { | 279 | private updateVisibility(): void { |
274 | this.interpreter.send(document.hidden ? 'TAB_HIDDEN' : 'TAB_VISIBLE'); | 280 | this.interpreter.send(document.hidden ? 'TAB_HIDDEN' : 'TAB_VISIBLE'); |
275 | } | 281 | } |
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 = | |||
27 | | { type: 'PAGE_RESUME' } | 27 | | { type: 'PAGE_RESUME' } |
28 | | { type: 'ONLINE' } | 28 | | { type: 'ONLINE' } |
29 | | { type: 'OFFLINE' } | 29 | | { type: 'OFFLINE' } |
30 | | { type: 'GENERATION_STARTED' } | ||
31 | | { type: 'GENERATION_ENDED' } | ||
30 | | { type: 'ERROR'; message: string }; | 32 | | { type: 'ERROR'; message: string }; |
31 | 33 | ||
32 | export default createMachine( | 34 | export default createMachine( |
@@ -105,7 +107,7 @@ export default createMachine( | |||
105 | initial: 'opening', | 107 | initial: 'opening', |
106 | states: { | 108 | states: { |
107 | opening: { | 109 | opening: { |
108 | always: [{ target: '#timedOut', in: '#tabHidden' }], | 110 | always: [{ target: '#timedOut', in: '#mayDisconnect' }], |
109 | after: { | 111 | after: { |
110 | OPEN_TIMEOUT: { | 112 | OPEN_TIMEOUT: { |
111 | actions: 'raiseTimeoutError', | 113 | actions: 'raiseTimeoutError', |
@@ -143,7 +145,7 @@ export default createMachine( | |||
143 | initial: 'active', | 145 | initial: 'active', |
144 | states: { | 146 | states: { |
145 | active: { | 147 | active: { |
146 | always: [{ target: 'inactive', in: '#tabHidden' }], | 148 | always: [{ target: 'inactive', in: '#mayDisconnect' }], |
147 | }, | 149 | }, |
148 | inactive: { | 150 | inactive: { |
149 | always: [{ target: 'active', in: '#tabVisible' }], | 151 | always: [{ target: 'active', in: '#tabVisible' }], |
@@ -173,14 +175,44 @@ export default createMachine( | |||
173 | visibleOrUnknown: { | 175 | visibleOrUnknown: { |
174 | id: 'tabVisible', | 176 | id: 'tabVisible', |
175 | on: { | 177 | on: { |
176 | TAB_HIDDEN: 'hidden', | 178 | TAB_HIDDEN: [ |
179 | { target: 'hidden.mayDisconnect', in: '#generationIdle' }, | ||
180 | { target: 'hidden.keepAlive', in: '#generationRunning' }, | ||
181 | ], | ||
177 | }, | 182 | }, |
178 | }, | 183 | }, |
179 | hidden: { | 184 | hidden: { |
180 | id: 'tabHidden', | ||
181 | on: { | 185 | on: { |
182 | TAB_VISIBLE: 'visibleOrUnknown', | 186 | TAB_VISIBLE: 'visibleOrUnknown', |
183 | }, | 187 | }, |
188 | initial: 'mayDisconnect', | ||
189 | states: { | ||
190 | mayDisconnect: { | ||
191 | id: 'mayDisconnect', | ||
192 | always: { target: 'keepAlive', in: '#generationRunning' }, | ||
193 | }, | ||
194 | keepAlive: { | ||
195 | id: 'keepAlive', | ||
196 | always: { target: 'mayDisconnect', in: '#generationIdle' }, | ||
197 | }, | ||
198 | }, | ||
199 | }, | ||
200 | }, | ||
201 | }, | ||
202 | generation: { | ||
203 | initial: 'idle', | ||
204 | states: { | ||
205 | idle: { | ||
206 | id: 'generationIdle', | ||
207 | on: { | ||
208 | GENERATION_STARTED: 'running', | ||
209 | }, | ||
210 | }, | ||
211 | running: { | ||
212 | id: 'generationRunning', | ||
213 | on: { | ||
214 | GENERATION_ENDED: 'idle', | ||
215 | }, | ||
184 | }, | 216 | }, |
185 | }, | 217 | }, |
186 | }, | 218 | }, |