@@ -78,7 +78,6 @@ import { createDesktopToolRunner } from '@/main/desktop-executor/runner'
7878import { createDesktopExecutorService } from '@/main/desktop-executor/service'
7979import { createSleepBlocker } from '@/main/desktop-executor/sleep-blocker'
8080import { createDesktopSettingsService , wasOpenedAtLogin } from '@/main/desktop-settings'
81- import { showShellDialog } from '@/main/dialogs'
8281import { attachDownloadHandling , countProgressingAppDownloads } from '@/main/downloads'
8382import { createAuthFlow , createConnectFlow , createHandoffManager } from '@/main/handoff'
8483import {
@@ -126,6 +125,7 @@ import { createRunLedger } from '@/main/terminal/run-ledger'
126125import { installTray , type TrayHandle } from '@/main/tray'
127126import { checkForUpdatesInteractive , initUpdater , type UpdaterHandle } from '@/main/updater'
128127import { installBrowserUserAgent } from '@/main/user-agent'
128+ import { showShellDialogOver } from '@/main/visible-dialog'
129129import {
130130 createMainWindow ,
131131 guardVisibilityListenersAfterDestroy ,
@@ -318,6 +318,8 @@ function main(): void {
318318 let appSession : Session | null = null
319319 let sessionLifecycle : ReturnType < typeof createSessionLifecycleCoordinator > | null = null
320320 let resumingQuitAfterTeardown = false
321+ let quitPromptOpen = false
322+ let reopeningWindowAfterQuitCancel = false
321323 let committedRelaunchPending = false
322324 let tray : TrayHandle | null = null
323325 let updater : UpdaterHandle | null = null
@@ -559,7 +561,7 @@ function main(): void {
559561 if ( activate ) void opened . then ( showMainWindow )
560562 } ,
561563 allowHttpLocalhost : allowHttpLocalhost ( ) ,
562- isCommittedRelaunchPending : isExitCommitted ,
564+ isExitCommitted,
563565 }
564566 }
565567
@@ -965,17 +967,22 @@ function main(): void {
965967 defaultId : 1 ,
966968 cancelId : 1 ,
967969 }
968- // A sheet on a hidden or minimized window would be a prompt nobody can see.
969- const win = getMainWindow ( )
970- const { response } = await ( win ?. isVisible ( ) && ! win . isMinimized ( )
971- ? showShellDialog ( win , options )
972- : showShellDialog ( options ) )
973- return response === 0
970+ quitPromptOpen = true
971+ try {
972+ const { response } = await showShellDialogOver ( getMainWindow ( ) , options )
973+ return response === 0
974+ } finally {
975+ quitPromptOpen = false
976+ }
974977 } ,
975978 quit : ( ) => app . quit ( ) ,
976979 onCancel : ( ) => {
977980 // Closing the last window quit Sim on Windows and Linux; staying means keeping a window.
978- if ( process . platform !== 'darwin' && getWindows ( ) . length === 0 ) void ensureMainWindow ( )
981+ if ( process . platform === 'darwin' || getWindows ( ) . length > 0 ) return
982+ reopeningWindowAfterQuitCancel = true
983+ void ensureMainWindow ( ) . finally ( ( ) => {
984+ reopeningWindowAfterQuitCancel = false
985+ } )
979986 } ,
980987 } )
981988
@@ -989,7 +996,8 @@ function main(): void {
989996 } )
990997
991998 app . on ( 'window-all-closed' , ( ) => {
992- if ( process . platform !== 'darwin' ) {
999+ // The quit prompt closing, or a cancelled quit's window still opening, is not a new quit.
1000+ if ( process . platform !== 'darwin' && ! quitPromptOpen && ! reopeningWindowAfterQuitCancel ) {
9931001 app . quit ( )
9941002 }
9951003 } )
@@ -1018,12 +1026,11 @@ function main(): void {
10181026 } )
10191027 return
10201028 }
1021- // A committed relaunch has already asked about, or deliberately skipped, the work it
1022- // interrupts, and a quit resuming after teardown was already let through. The resume is
1023- // one quit only: if something cancels it, the next quit is checked again.
1024- const resumedAfterTeardown = resumingQuitAfterTeardown
1029+ // Waiting on teardown is one quit only: if something cancels it, the next quit waits again.
10251030 resumingQuitAfterTeardown = false
1026- if ( quitGuard . holdQuit ( { bypass : committedRelaunchPending || resumedAfterTeardown } ) ) {
1031+ // A committed relaunch has already asked about, or deliberately skipped, the work it
1032+ // interrupts. Every other quit, including one resuming after teardown, is checked here.
1033+ if ( quitGuard . holdQuit ( { bypass : committedRelaunchPending } ) ) {
10271034 event . preventDefault ( )
10281035 return
10291036 }
0 commit comments