fix(gui): don't let minimize-to-tray block app quit and OS shutdown - #240
Merged
dbfx merged 2 commits intoJul 27, 2026
Merged
Conversation
When minimizeToTray is enabled, the main window's close handler calls
e.preventDefault() unconditionally. Since app.quit() closes all windows
before quitting, the prevented close aborts the whole quit flow: Cmd+Q
and the app menu's Quit just hide the window, and on macOS the app
blocks system shutdown until it is force-quit.
Set a flag in before-quit and let close proceed once it is set. This
also makes the removeAllListeners('close') workaround in the tray Quit
items unnecessary.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
On macOS autoUpdater.quitAndInstall() closes all windows before before-quit is emitted, so the flag set there is too late and the minimize-to-tray close interceptor would still block update restarts. before-quit-for-update fires before the windows close. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
dbfx
approved these changes
Jul 27, 2026
Contributor
|
Thank you @esrever10 ! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #239.
Problem
With Minimize to tray enabled, the main window's
closehandler callse.preventDefault()unconditionally.app.quit()closes all windows before quitting, so the prevented close aborts the whole quit flow: Cmd+Q and the menu Quit just hide the window, and on macOS the app blocks system shutdown/restart until it is force-quit. See #239 for full details.Fix
The standard Electron pattern for tray apps:
isQuittingflag, set inbefore-quitand inbefore-quit-for-update(on macOSautoUpdater.quitAndInstall()closes windows beforebefore-quitfires, so without the latter the interceptor would still block update restarts)closeinterceptor returns early whenisQuittingis set, so windows close and quit proceedsremoveAllListeners('close')workaround from the two tray Quit items (createTray/rebuildTrayMenu) —app.quit()now works on its ownBehavior is otherwise unchanged: clicking the window's close button with minimize-to-tray enabled still hides to tray.
Testing
electron-vite buildpassesvitest run: 2054 tests pass (the twoelectron-binary-dependent test files don't run in my environment; unrelated to this change)before-quit→ windowcloseordering; with the flag set the interceptor no longer prevents close, so Cmd+Q, Dock → Quit, tray → Quit, and OS shutdown all proceed🤖 Generated with Claude Code