Repository navigation
Don't open the running VMs question twice #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e6aaa22
1fb9e6d
6d14b6d
dbb205e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,9 @@ 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 | ||
| // 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 | ||
| // brings this window to the front | ||
|
|
@@ -79,10 +82,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 | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This early return runs before the new question checks below, so it decides on state that can have changed while the question was up. If the last guest powers itself off while "VMs are still running" is open (the question is asked about VMs that are running, and a guest shutting down from its own menu is normal), |
||
| e.preventDefault() | ||
| // the still working question is up on this window, it gets answered there | ||
| if (askingAboutWork) 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 +181,9 @@ function hideToTray(announce = true): void { | |
|
|
||
| /** Quit from the tray: same question as closing the window, minus the tray option */ | ||
| async function requestQuit(): Promise<void> { | ||
| if (shuttingDown || endWorkWait || askingAboutWork) 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 | ||
|
|
@@ -274,7 +281,7 @@ const KEEP = 'Keep them running in the tray' | |
| const SHUT = 'Shut down VMs and quit' | ||
|
|
||
| async function askAndQuit(fromClose: boolean): Promise<void> { | ||
| 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 +300,13 @@ async function askAndQuit(fromClose: boolean): Promise<void> { | |
| 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() | ||
|
|
@@ -381,7 +394,14 @@ async function shutDownAllAndQuit(): Promise<void> { | |
| 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() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the flag now covers two questions, this one and the Force off question in
shutDownAllAndQuit, so the comment reads a bit narrow. The second one also behaves slightly differently from whatrequestQuitpromises:shuttingDownis true by then, so Quit from the tray returns on the line above instead of showing the window with the question on it. Not worth another flag, but the comment could say the flag means "a question about running VMs is open".