From e6aaa226271d64166d477e7e1550aacf222cb675 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:46:27 -0500 Subject: [PATCH 1/4] Don't open the running VMs question twice The tray's Quit opened a second copy of the "VMs are still running" question on top of the one already up, and answering both ran shutDownAllAndQuit twice: two balloons, two power button presses per guest and two Force off questions. The still working question from #139 already had a flag for this; give the running VMs question the same one, and leave it up when the window is closed while it is open. --- src/main/index.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 56c7642..525871e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -19,6 +19,8 @@ let shuttingDown = false let endWorkWait: ((quit: boolean) => void) | null = null // the still working question is open. Quit and close don't open a second one meanwhile let askingAboutWork = false +// the running VMs question is open. Same rule: no second copy from the tray or the window +let askingAboutVms = false // a second copy would start the same VMs again and fight over their disks, so it only // brings this window to the front @@ -81,8 +83,8 @@ function createWindow(): void { if (quitting || !backend) return if (backend.runner.runningNames().length === 0 && !hasWork()) return e.preventDefault() - // the still working question is up on this window, it gets answered there - if (askingAboutWork) return + // a question is already up on this window, it gets answered there + if (askingAboutWork || askingAboutVms) return // already waiting for the guests or the work: just put the window away again if (shuttingDown || endWorkWait) win.hide() else if (settings.closeBehavior === 'tray') hideToTray() @@ -176,7 +178,7 @@ function hideToTray(announce = true): void { /** Quit from the tray: same question as closing the window, minus the tray option */ async function requestQuit(): Promise { - if (shuttingDown || endWorkWait || askingAboutWork) return + if (shuttingDown || endWorkWait || askingAboutWork || askingAboutVms) return if (backend && hasWork() && !(await workFirst())) return if (!backend || backend.runner.runningNames().length === 0) { quitting = true @@ -274,7 +276,7 @@ const KEEP = 'Keep them running in the tray' const SHUT = 'Shut down VMs and quit' async function askAndQuit(fromClose: boolean): Promise { - if (shuttingDown) return + if (shuttingDown || askingAboutVms) return // after Quit when it's done the window is in the tray showWindow() const names = backend!.runner.runningNames() @@ -293,7 +295,13 @@ async function askAndQuit(fromClose: boolean): Promise { checkboxLabel: fromClose ? "Don't ask again (change this in Settings)" : undefined, noLink: true } - const r = mainWindow ? await dialog.showMessageBox(mainWindow, opts) : await dialog.showMessageBox(opts) + askingAboutVms = true + let r: Electron.MessageBoxReturnValue + try { + r = mainWindow ? await dialog.showMessageBox(mainWindow, opts) : await dialog.showMessageBox(opts) + } finally { + askingAboutVms = false + } const choice = buttons[r.response] if (r.checkboxChecked && (choice === KEEP || choice === SHUT)) rememberClose(choice === KEEP ? 'tray' : 'quit') if (choice === KEEP) return hideToTray() From 1fb9e6d7a06f22ab5e4bc86e20e6855e1049021b Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:46:37 -0500 Subject: [PATCH 2/4] Tray Quit brings an open question to the front With the guard in place, Quit from the tray did nothing at all while a question was open, and if the window had been minimized the question was out of sight. Show the window instead so the click points at the question that is waiting for an answer. --- src/main/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index 525871e..56ff7aa 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -178,7 +178,9 @@ function hideToTray(announce = true): void { /** Quit from the tray: same question as closing the window, minus the tray option */ async function requestQuit(): Promise { - if (shuttingDown || endWorkWait || askingAboutWork || askingAboutVms) return + if (shuttingDown || endWorkWait) return + // a question is already up: show it instead of a second copy, so the click isn't a no-op + if (askingAboutWork || askingAboutVms) return showWindow() if (backend && hasWork() && !(await workFirst())) return if (!backend || backend.runner.runningNames().length === 0) { quitting = true From 6d14b6db4e8240c7d2b170942645c3c27eb521b8 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:54:35 -0500 Subject: [PATCH 3/4] Keep a question up when the window is closed under it Two gaps from reviewing this change: - the close handler decided on runningNames() and hasWork() before it looked at the open question, so a guest powering itself off while the question was up let the X close the window with the message box on it, and window-all-closed then quit the app - the Force off question at the end of shutDownAllAndQuit had no flag of its own, so closing the window hid the window it was attached to --- src/main/index.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index 56ff7aa..4dfe011 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -81,10 +81,12 @@ function createWindow(): void { // and closing it with only a compact or a profile save going cut that off win.on('close', (e) => { if (quitting || !backend) return + // a question is already up on this window, it gets answered there. This comes first because + // the last guest can power itself off while the question is up, and closing the window then + // takes the question with it and quits through window-all-closed + if (askingAboutWork || askingAboutVms) return e.preventDefault() if (backend.runner.runningNames().length === 0 && !hasWork()) return e.preventDefault() - // a question is already up on this window, it gets answered there - if (askingAboutWork || askingAboutVms) return // already waiting for the guests or the work: just put the window away again if (shuttingDown || endWorkWait) win.hide() else if (settings.closeBehavior === 'tray') hideToTray() @@ -391,7 +393,14 @@ async function shutDownAllAndQuit(): Promise { noLink: true } showWindow() - const r = mainWindow ? await dialog.showMessageBox(mainWindow, opts) : await dialog.showMessageBox(opts) + // same as the other questions: closing the window leaves this one up instead of hiding it + askingAboutVms = true + let r: Electron.MessageBoxReturnValue + try { + r = mainWindow ? await dialog.showMessageBox(mainWindow, opts) : await dialog.showMessageBox(opts) + } finally { + askingAboutVms = false + } if (r.response !== 0) { shuttingDown = false updateTrayMenu() From dbb205ea2bafef09bcc99018c8ce5c6bf73a1a94 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:55:23 -0500 Subject: [PATCH 4/4] Say what askingAboutVms covers now that it guards two questions --- src/main/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/index.ts b/src/main/index.ts index 4dfe011..3030dc2 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -19,7 +19,8 @@ let shuttingDown = false let endWorkWait: ((quit: boolean) => void) | null = null // the still working question is open. Quit and close don't open a second one meanwhile let askingAboutWork = false -// the running VMs question is open. Same rule: no second copy from the tray or the window +// a question about running VMs is open (still running, or Force off at the end of a shut down). +// Same rule: no second copy from the tray or the window, and closing the window leaves it up let askingAboutVms = false // a second copy would start the same VMs again and fight over their disks, so it only