Skip to content

feat(desktop): add close-to-tray behavior - #35259

Closed
SOSANA wants to merge 4 commits into
anomalyco:devfrom
SOSANA:desktop-tray-close
Closed

feat(desktop): add close-to-tray behavior#35259
SOSANA wants to merge 4 commits into
anomalyco:devfrom
SOSANA:desktop-tray-close

Conversation

@SOSANA

@SOSANA SOSANA commented Jul 4, 2026

Copy link
Copy Markdown

Issue for this PR

Refs #27463, #18134, #26666

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

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-closed or activate handler before, so closing the last window relied on Electron defaults (full quit on Linux/Windows, destroyed window with no restore on macOS).

  • Linux/Windows: closing the last window hides it to a tray icon with a Show OpenCode / Quit menu; clicking the tray also restores the window.
  • macOS: the red close button hides the window (app + Dock icon stay); clicking the Dock icon restores it via an app.on("activate") handler.
  • Only the last window triggers hide-to-tray; other windows close normally.
  • Tray Quit calls app.quit(), which fires before-quit (sets the quit flag + stops sidecars) before any window close event, so it quits cleanly with full sidecar teardown and no orphans.
  • The tray is held at module scope (let tray) so it is not garbage-collected mid-session (a GC'd Tray drops its icon and breaks tray interactions).

Implementation: window-registry.ts exposes isQuitting() to gate the close intercept; windows.ts hides the last window on close (real quits set the flag first via before-quit/will-quit/session-end), adds showMainWindow(), and exports iconPath(); new tray.ts registers activate on all platforms and the tray + menu on non-darwin; index.ts wires setupTrayAndLifecycle() after window restore.

No QR/auth/network/settings UI (out of scope per #18796).

How did you verify your code works?

Check Result
bun run --cwd packages/desktop typecheck (tsgo -b) pass
oxlint on changed files 0 errors / 0 warnings
prettier --check on changed files clean
bun test (full desktop suite) 67/67 pass — incl. new window-registry isQuitting gate test and 5 new tray lifecycle tests (activate restore, linux tray+menu creation, tray click/Show restore, Quit→app.quit, macOS skips tray)
electron-vite build blocked — pre-existing esbuild failure ("Unterminated string literal") in the embedded opencode/dist/node/node.js server bundle; reproduces on plain dev without these changes, so it is environmental, not caused by this PR
Manual Linux-deb tray verification pending — needs a GUI machine with the packaged app (Electron binary could not be fetched in the dev environment)

A reviewer can confirm the close-to-tray logic by: (1) the isQuitting() gate test and the tray lifecycle tests, and (2) tracing app.quit()before-quit (setAppQuitting + stopSidecars, index.ts) → window close (handler returns early because isQuitting() is true) → clean quit. Hide-to-tray only triggers when isQuitting() is false and exactly one window remains.

Screenshots / recordings

Will add tray screenshots after manual verification on a GUI machine.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

SOSANA added 2 commits July 3, 2026 21:50
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
@SOSANA
SOSANA requested review from Brendonovich and Hona as code owners July 4, 2026 01:52
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jul 4, 2026
@SOSANA

SOSANA commented Jul 4, 2026

Copy link
Copy Markdown
Author

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.

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

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>
@SOSANA

SOSANA commented Jul 6, 2026

Copy link
Copy Markdown
Author

The three CI workflows (typecheck, nix-eval, test) are stuck in action_required for this fork PR and need a maintainer with admin rights to approve them so the checks can run. Only pr-standards has executed (passing).

Could a maintainer approve the pending workflow runs? Links:

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant