From a5a1774f581f82fd18ff40d827ec8338e60e4efb Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:18:45 -0500 Subject: [PATCH 1/4] Force off question: Don't quit instead of Cancel, and say what already happened By the time this question shows, every guest has had its power button pressed. Cancel read like undoing that, but it only abandons the quit, and the guests keep shutting down. The button is now Don't quit, and the detail says the guests were already asked to shut down. It also names the VMs that did shut down within the wait, so after Don't quit it isn't a surprise that they are off. --- src/main/quitFlow.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/quitFlow.ts b/src/main/quitFlow.ts index d43cc04..2d8aa2c 100644 --- a/src/main/quitFlow.ts +++ b/src/main/quitFlow.ts @@ -74,6 +74,8 @@ const KEEP = 'Keep them running in the tray' const SHUT = 'Shut down VMs and quit' const FORCE = 'Force off and quit' const MORE = 'Wait another minute' +// not Cancel: the guests already got the power button, and nothing here can take that back +const STAY = "Don't quit" const MINUTE = 60_000 /** VMs whose work the user chose to leave unfinished. Quitting doesn't wait for theirs */ @@ -313,13 +315,21 @@ export class QuitFlow { waiting = waiting.filter((_n, i) => !done[i]) if (!waiting.length) return true const minutes = Math.max(1, Math.round((host.now() - since) / MINUTE)) + const off = names.filter((n) => !waiting.includes(n)) host.show() const { choice } = await this.question({ type: 'warning', title: 'Still running', message: `${waiting.join(', ')} ${waiting.length === 1 ? 'has' : 'have'} not shut down ${minutes === 1 ? 'within a minute' : `in ${minutes} minutes`}.`, - detail: `A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside ${waiting.length === 1 ? 'it' : 'them'}.`, - buttons: [MORE, FORCE, 'Cancel'], + detail: [ + // so Don't quit doesn't leave the user wondering where the other VMs went + off.length ? `${off.join(', ')} ${off.length === 1 ? 'is' : 'are'} already off.` : '', + `A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside ${waiting.length === 1 ? 'it' : 'them'}.`, + `Don't quit keeps the app open, but ${waiting.length === 1 ? 'the guest was' : 'the guests were'} already asked to shut down and may still turn off.` + ] + .filter(Boolean) + .join('\n\n'), + buttons: [MORE, FORCE, STAY], cancelId: 2, defaultId: 0, noLink: true From fe1d74c9e6ddaeee0a61be6beaf1dce350df6aa2 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:18:46 -0500 Subject: [PATCH 2/4] Test the Force off question's wording and the VMs it lists as off --- tests/quitFlow.test.ts | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/quitFlow.test.ts b/tests/quitFlow.test.ts index a6dc7bf..d4a2c38 100644 --- a/tests/quitFlow.test.ts +++ b/tests/quitFlow.test.ts @@ -8,6 +8,7 @@ const WAIT = "Quit when it's done" const NOW = 'Quit anyway' const MORE = 'Wait another minute' const FORCE = 'Force off and quit' +const STAY = "Don't quit" class FakeRunner { running = new Set() @@ -347,8 +348,8 @@ describe('QuitFlow after Quit anyway', () => { expect([...t.runner.held]).toEqual([]) }) - it('lets go of the hold on Cancel in the Force off question', async () => { - const t = setup({ running: ['win11'], work: { win11: 'saving' }, answer: (q) => (q.title === 'Still working' ? NOW : q.title === 'Still running' ? 'Cancel' : SHUT) }) + it("lets go of the hold on Don't quit in the Force off question", async () => { + const t = setup({ running: ['win11'], work: { win11: 'saving' }, answer: (q) => (q.title === 'Still working' ? NOW : q.title === 'Still running' ? STAY : SHUT) }) t.runner.stuck.add('win11') await t.flow.requestQuit() expect(t.titles()).toContain('Still running') @@ -428,8 +429,8 @@ describe('QuitFlow guests that do not shut down', () => { expect(t.log).toContain('quit') }) - it('stops the quit on Cancel and puts the tray back', async () => { - const t = setup({ running: ['win11'], closeBehavior: 'quit', answer: () => 'Cancel' }) + it("stops the quit on Don't quit and puts the tray back", async () => { + const t = setup({ running: ['win11'], closeBehavior: 'quit', answer: () => STAY }) t.runner.stuck.add('win11') t.flow.onClose() await settle() @@ -437,6 +438,28 @@ describe('QuitFlow guests that do not shut down', () => { expect(t.log).not.toContain('quit') expect(t.log.filter((l) => l === 'updateTray').length).toBeGreaterThan(1) }) + + it("says the shut down can't be taken back, and which VMs are already off", async () => { + const t = setup({ running: ['win11', 'kali', 'debian'], closeBehavior: 'quit', answer: () => STAY }) + t.runner.stuck.add('win11') + t.flow.onClose() + await settle() + const q = t.asked[0] + expect(q.buttons).toEqual([MORE, FORCE, STAY]) + expect(q.buttons[q.cancelId]).toBe(STAY) + expect(q.detail).toMatch(/^kali, debian are already off\./) + expect(q.detail).toContain('the guest was already asked to shut down') + }) + + it('names nothing as off when every guest is still up', async () => { + const t = setup({ running: ['win11', 'kali'], closeBehavior: 'quit', answer: () => STAY }) + t.runner.stuck.add('win11') + t.runner.stuck.add('kali') + t.flow.onClose() + await settle() + expect(t.asked[0].detail).not.toContain('already off') + expect(t.asked[0].detail).toContain('the guests were already asked') + }) }) describe('trayMenu', () => { From 017d96f181d6c495e41cb5b8d27d0828bdbbe06b Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:20:32 -0500 Subject: [PATCH 3/4] Force off question: tell apart the guests the power button never reached pressPower swallowed a failed shutdown (no QMP connection), and the question then said that guest was already asked to shut down. It now returns whether the press went through, and the question says which VMs the app couldn't reach, and that only Force off will turn those off. --- src/main/quitFlow.ts | 31 +++++++++++++++++++++++-------- tests/quitFlow.test.ts | 25 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/main/quitFlow.ts b/src/main/quitFlow.ts index 2d8aa2c..9b030ac 100644 --- a/src/main/quitFlow.ts +++ b/src/main/quitFlow.ts @@ -284,19 +284,24 @@ export class QuitFlow { // profile save or delete gets the power button press once that's done, not while the guest // hibernates. Unless the user already said to leave that work unfinished: then waiting for it // only makes the quit look stuck, and a hibernate the power button turns into a shutdown is fine + // VMs the power button press didn't reach (no QMP connection): they won't turn off on their own + const unreached = new Set() + const press = async (n: string): Promise => { + if (!(await this.pressPower(n))) unreached.add(n) + } await Promise.all( names.map(async (n) => { - if (abandoned.has(n)) return this.pressPower(n) + if (abandoned.has(n)) return press(n) const saving = host.vmWork()[n] === 'saving' await this.workDone(n) if (!runner.isRunning(n)) return // a session save boots the VM again right before it ends, and the guest misses a power button // press while it's still resuming from hibernate. It has the agent, so wait for that to answer if (saving) await host.guestBack(n, 120_000) - await this.pressPower(n) + await press(n) }) ) - if (!(await this.waitForShutdown(names))) return this.release(abandoned) + if (!(await this.waitForShutdown(names, unreached))) return this.release(abandoned) host.quit() } @@ -305,7 +310,7 @@ export class QuitFlow { * false if the user cancelled. A Windows guest installing updates on shutdown regularly needs * longer than a minute, so the question offers another minute as well as Force off. */ - private async waitForShutdown(names: string[]): Promise { + private async waitForShutdown(names: string[], unreached: ReadonlySet): Promise { const host = this.host let waiting = names // real time, not rounds of the question: it counts a question left unanswered for a while too @@ -316,6 +321,8 @@ export class QuitFlow { if (!waiting.length) return true const minutes = Math.max(1, Math.round((host.now() - since) / MINUTE)) const off = names.filter((n) => !waiting.includes(n)) + const asked = waiting.filter((n) => !unreached.has(n)) + const notAsked = waiting.filter((n) => unreached.has(n)) host.show() const { choice } = await this.question({ type: 'warning', @@ -325,7 +332,12 @@ export class QuitFlow { // so Don't quit doesn't leave the user wondering where the other VMs went off.length ? `${off.join(', ')} ${off.length === 1 ? 'is' : 'are'} already off.` : '', `A guest installing updates on shutdown can take a few minutes. Force off loses anything unsaved inside ${waiting.length === 1 ? 'it' : 'them'}.`, - `Don't quit keeps the app open, but ${waiting.length === 1 ? 'the guest was' : 'the guests were'} already asked to shut down and may still turn off.` + asked.length + ? `Don't quit keeps the app open, but ${asked.length === waiting.length ? (asked.length === 1 ? 'the guest was' : 'the guests were') : asked.join(', ') + (asked.length === 1 ? ' was' : ' were')} already asked to shut down and may still turn off.` + : '', + notAsked.length + ? `The app couldn't reach ${notAsked.join(', ')} to ask ${notAsked.length === 1 ? 'it' : 'them'} to shut down, so ${notAsked.length === 1 ? 'it' : 'they'} won't turn off by ${notAsked.length === 1 ? 'itself' : 'themselves'}. Force off is the way to turn ${notAsked.length === 1 ? 'it' : 'them'} off.` + : '' ] .filter(Boolean) .join('\n\n'), @@ -345,14 +357,17 @@ export class QuitFlow { } } - private async pressPower(name: string): Promise { + /** false if the press didn't reach a running guest */ + private async pressPower(name: string): Promise { const runner = this.host.runner - if (!runner.isRunning(name)) return + if (!runner.isRunning(name)) return true try { if (runner.state(name).status === 'paused') await runner.resume(name) await runner.shutdown(name) + return true } catch { - // no QMP connection: it ends up in the force off question + // no QMP connection: it ends up in the force off question, which says so + return false } } diff --git a/tests/quitFlow.test.ts b/tests/quitFlow.test.ts index d4a2c38..5d47f5e 100644 --- a/tests/quitFlow.test.ts +++ b/tests/quitFlow.test.ts @@ -15,6 +15,8 @@ class FakeRunner { statuses: Record = {} /** guests that ignore the power button, so waitForExit times out */ stuck = new Set() + /** guests whose QMP connection is gone, so the power button can't be pressed */ + unreachable = new Set() calls: string[] = [] /** VMs the flow has said must not be started again */ held = new Set() @@ -33,6 +35,7 @@ class FakeRunner { this.statuses[name] = 'running' } async shutdown(name: string): Promise { + if (this.unreachable.has(name)) throw new Error('QMP is not connected') this.calls.push(`shutdown:${name}`) if (!this.stuck.has(name)) this.running.delete(name) } @@ -451,6 +454,28 @@ describe('QuitFlow guests that do not shut down', () => { expect(q.detail).toContain('the guest was already asked to shut down') }) + it("doesn't say a guest it couldn't reach was asked to shut down", async () => { + const t = setup({ running: ['win11', 'kali'], closeBehavior: 'quit', answer: () => STAY }) + t.runner.stuck.add('win11') + t.runner.stuck.add('kali') + t.runner.unreachable.add('kali') + t.flow.onClose() + await settle() + const detail = t.asked[0].detail ?? '' + expect(detail).toContain('but win11 was already asked to shut down') + expect(detail).toContain("The app couldn't reach kali to ask it to shut down, so it won't turn off by itself.") + }) + + it('leaves out the asked sentence when no guest could be reached', async () => { + const t = setup({ running: ['win11'], closeBehavior: 'quit', answer: () => STAY }) + t.runner.stuck.add('win11') + t.runner.unreachable.add('win11') + t.flow.onClose() + await settle() + expect(t.asked[0].detail).not.toContain('already asked') + expect(t.asked[0].detail).toContain("couldn't reach win11") + }) + it('names nothing as off when every guest is still up', async () => { const t = setup({ running: ['win11', 'kali'], closeBehavior: 'quit', answer: () => STAY }) t.runner.stuck.add('win11') From ed0c8b69de050535a4504b20ca3be8dff7bc01e9 Mon Sep 17 00:00:00 2001 From: Ari <149393150+A21-devs@users.noreply.github.com> Date: Sat, 5 Dec 2026 15:21:43 -0500 Subject: [PATCH 4/4] Force off question: no Wait another minute when no guest got the power button If every guest still up is one the app couldn't reach, waiting can't help, so the question offers only Force off and Don't quit. --- src/main/quitFlow.ts | 5 +++-- tests/quitFlow.test.ts | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/quitFlow.ts b/src/main/quitFlow.ts index 9b030ac..5c1229d 100644 --- a/src/main/quitFlow.ts +++ b/src/main/quitFlow.ts @@ -341,8 +341,9 @@ export class QuitFlow { ] .filter(Boolean) .join('\n\n'), - buttons: [MORE, FORCE, STAY], - cancelId: 2, + // waiting longer only helps a guest that got the power button + buttons: asked.length ? [MORE, FORCE, STAY] : [FORCE, STAY], + cancelId: asked.length ? 2 : 1, defaultId: 0, noLink: true }) diff --git a/tests/quitFlow.test.ts b/tests/quitFlow.test.ts index 5d47f5e..6b92334 100644 --- a/tests/quitFlow.test.ts +++ b/tests/quitFlow.test.ts @@ -474,6 +474,9 @@ describe('QuitFlow guests that do not shut down', () => { await settle() expect(t.asked[0].detail).not.toContain('already asked') expect(t.asked[0].detail).toContain("couldn't reach win11") + // another minute can't help, so it isn't offered + expect(t.asked[0].buttons).toEqual([FORCE, STAY]) + expect(t.asked[0].buttons[t.asked[0].cancelId]).toBe(STAY) }) it('names nothing as off when every guest is still up', async () => {