@@ -80,19 +80,20 @@ const FAILURE_DEDUPE_MS = 5_000
8080 * the structured log because rejected values can contain request payloads or
8181 * credentials; the event kind and crash dumps are enough for triage.
8282 *
83- * The recovery prompt never outlives a quit: a failure once quitting has begun
84- * exits without asking (a dialog opened during shutdown can only fall back to
85- * a blocking native alert), and a quit while the prompt is open answers it as
86- * Quit.
83+ * The recovery prompt never outlives a quit: a failure once a quit is committed
84+ * (`will-quit`) exits without asking, since a dialog opened during shutdown can
85+ * only fall back to a blocking native alert, and any quit request while the
86+ * prompt is open answers it as Quit. A `before-quit` that another listener
87+ * cancels leaves later failures their prompt.
8788 */
8889export function installMainProcessFailureObservers ( {
8990 events,
9091 getWindow,
9192 processSource = process ,
9293} : MainProcessFailureObserverDeps ) : void {
9394 let fatalRecoveryOpen = false
94- let quitStarted = false
95- const quitSignal = new AbortController ( )
95+ let quitCommitted = false
96+ let openPrompt : AbortController | null = null
9697 let lastChildFailure = ''
9798 let lastChildFailureAt = 0
9899
@@ -124,18 +125,20 @@ export function installMainProcessFailureObservers({
124125 fatalRecoveryOpen = true
125126 events . record ( name , { valueType : value instanceof Error ? 'Error' : typeof value } )
126127 logger . error ( 'Fatal main-process failure' , { kind : name } )
127- if ( quitStarted ) {
128+ if ( quitCommitted ) {
128129 app . exit ( 1 )
129130 return
130131 }
132+ const promptAbort = new AbortController ( )
133+ openPrompt = promptAbort
131134 const options = {
132135 type : 'error' as const ,
133136 buttons : [ 'Restart Sim' , 'Quit Sim' ] ,
134137 defaultId : 0 ,
135138 cancelId : 1 ,
136139 message : 'Sim encountered a problem' ,
137140 detail : 'Restart Sim to recover. Diagnostic details were saved locally.' ,
138- signal : quitSignal . signal ,
141+ signal : promptAbort . signal ,
139142 }
140143 const win = getWindow ( )
141144 const prompt =
@@ -157,14 +160,17 @@ export function installMainProcessFailureObservers({
157160 reportFatal ( 'main_uncaught_exception' , error )
158161 }
159162
160- const onQuitStarted = ( ) : void => {
161- quitStarted = true
162- quitSignal . abort ( )
163+ const answerOpenPromptAsQuit = ( ) : void => {
164+ openPrompt ?. abort ( )
165+ }
166+ const onWillQuit = ( ) : void => {
167+ quitCommitted = true
168+ answerOpenPromptAsQuit ( )
163169 }
164170
165171 app . on ( 'child-process-gone' , onChildProcessGone )
166- app . on ( 'before-quit' , onQuitStarted )
167- app . on ( 'will-quit' , onQuitStarted )
172+ app . on ( 'before-quit' , answerOpenPromptAsQuit )
173+ app . on ( 'will-quit' , onWillQuit )
168174 processSource . on ( 'unhandledRejection' , onUnhandledRejection )
169175 processSource . on ( 'uncaughtException' , onUncaughtException )
170176}
0 commit comments