feat(desktop): make macOS close behavior a user preference (#4024)
Summary
On macOS, closing Buzz's main window unconditionally called prevent_close() and hid the window, leaving the process running with no visible window. That preserves background local-agent work — but for users on window switchers that exclude hidden windows (e.g. bettertouchtool), Buzz disappears from the switcher while still running, with no way back through normal window switching.
Introduce a persisted close behavior preference with three modes:
- Keep running in background (default): unchanged — close hides the window, Buzz and local agents keep running (reopen via the tray icon).
- Minimize to Dock: close minimizes the window so Buzz stays visible to window switchers that exclude hidden windows, keeping agents running.
- Quit when window closes: close quits Buzz like a conventional app.
The default is unchanged (keepRunning), so existing installs behave identically until the user opts in.
Fixes #4024.
Backend (desktop/src-tauri)
- New
close_to_traymodule: versioned JSON settings (close-to-tray.json), load/save viaatomic_write_json_restricted,load_for_appfallback tokeepRunning, plusget_close_to_tray_behavior/set_close_to_tray_behaviorTauri commands. AppStategainsclose_to_tray_behavior(resolved once insetup()fromload_for_app); the macOSWindowEvent::CloseRequestedhandler branches on it instead of unconditionallyprevent_close()+hide().QuitWhenCloseddeliberately skipsprevent_close().- Commands registered in
invoke_handler.
Frontend (desktop/src)
closeToTrayLogic: behavior union + option metadata + validation (node-tested);invokeis resolved lazily so pure validation stays unit-testable without the Tauri bridge.CloseToTraySettingsCard: macOS-only (rendersnullelsewhere and outside the Tauri shell) radio dropdown in the Agents settings panel with per-option descriptions. Optimistic update with reload-on-failure.
Verification
| Check | Result |
|---|---|
cargo check (desktop src-tauri) |
0 warnings |
cargo test --lib close_to_tray |
5/5 pass |
cargo clippy --lib (close_to_tray) |
clean |
frontend validation logic (node --experimental-strip-types) |
valid (default valid, 3 unique options, junk rejected, safe fallback) |
| diff audit (7 files, +515/−5; sidecar stubs excluded) | clean |
Backend tests cover: missing file → default, save/load round-trip, unversioned → default fallback, newer-version → error, invalid JSON → error.
Not verified here: full frontend typecheck/npm test — desktop deps are not installed in this environment (pre-existing baseline gap: package.json's npm test needs the test-loader's typescript dependency installed). The macOS close behavior itself was not exercised on a live build (no local desktop run); the handler branch logic is a direct 1:1 mapping from preference to prevent_close/hide/minimize.
Notes for reviewer
QuitWhenClosedskipsprevent_close()entirely, matching the requested "quit like a normal app" semantics; this means background agents stop until Buzz is reopened — called out in the card copy.- Windows/Linux are untouched: the close handler and card are both
#cfg(target_os = "macos")/isMacPlatform()gated, preserving prior cross-platform behavior.