feat(desktop): add close-to-tray behavior - #35259
Conversation
Closing the last window hides it to the system tray (Linux/Windows) or keeps it restorable from the Dock (macOS) instead of quitting. Adds a tray menu with Show OpenCode and Quit; Quit reuses the existing before-quit sidecar teardown so no orphan sidecar processes remain. Refs anomalyco#27463, anomalyco#18134
Closing the last window hides it to the system tray (Linux/Windows) or keeps it restorable from the Dock (macOS) instead of quitting. Adds a tray menu with Show OpenCode and Quit; Quit reuses the existing before-quit sidecar teardown so no orphan sidecar processes remain. Refs anomalyco#27463, anomalyco#18134
|
Updated the PR description to follow the PR template (issue ref, type of change, what/why, verification, screenshots, checklist). Please re-check compliance when the bot next runs. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
|
The three CI workflows ( Could a maintainer approve the pending workflow runs? Links: |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Refs #27463, #18134, #26666
Type of change
What does this PR do?
Closing the last OpenCode desktop window now hides it to the tray/Dock instead of quitting, so background work keeps running. There was no
window-all-closedoractivatehandler before, so closing the last window relied on Electron defaults (full quit on Linux/Windows, destroyed window with no restore on macOS).app.on("activate")handler.app.quit(), which firesbefore-quit(sets the quit flag + stops sidecars) before any windowcloseevent, so it quits cleanly with full sidecar teardown and no orphans.let tray) so it is not garbage-collected mid-session (a GC'dTraydrops its icon and breaks tray interactions).Implementation:
window-registry.tsexposesisQuitting()to gate the close intercept;windows.tshides the last window on close (real quits set the flag first viabefore-quit/will-quit/session-end), addsshowMainWindow(), and exportsiconPath(); newtray.tsregistersactivateon all platforms and the tray + menu on non-darwin;index.tswiressetupTrayAndLifecycle()after window restore.No QR/auth/network/settings UI (out of scope per #18796).
How did you verify your code works?
bun run --cwd packages/desktop typecheck(tsgo -b)oxlinton changed filesprettier --checkon changed filesbun test(full desktop suite)window-registryisQuittinggate test and 5 newtraylifecycle tests (activate restore, linux tray+menu creation, tray click/Show restore, Quit→app.quit, macOS skips tray)electron-vite buildopencode/dist/node/node.jsserver bundle; reproduces on plaindevwithout these changes, so it is environmental, not caused by this PRA reviewer can confirm the close-to-tray logic by: (1) the
isQuitting()gate test and the tray lifecycle tests, and (2) tracingapp.quit()→before-quit(setAppQuitting+stopSidecars, index.ts) → windowclose(handler returns early becauseisQuitting()is true) → clean quit. Hide-to-tray only triggers whenisQuitting()is false and exactly one window remains.Screenshots / recordings
Will add tray screenshots after manual verification on a GUI machine.
Checklist