buzz icon indicating copy to clipboard operation
buzz copied to clipboard

feat(desktop): make macOS close behavior a user preference (#4024)

Open iroiro147 opened this issue 4 months ago • 0 comments

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_tray module: versioned JSON settings (close-to-tray.json), load/save via atomic_write_json_restricted, load_for_app fallback to keepRunning, plus get_close_to_tray_behavior / set_close_to_tray_behavior Tauri commands.
  • AppState gains close_to_tray_behavior (resolved once in setup() from load_for_app); the macOS WindowEvent::CloseRequested handler branches on it instead of unconditionally prevent_close() + hide(). QuitWhenClosed deliberately skips prevent_close().
  • Commands registered in invoke_handler.

Frontend (desktop/src)

  • closeToTrayLogic: behavior union + option metadata + validation (node-tested); invoke is resolved lazily so pure validation stays unit-testable without the Tauri bridge.
  • CloseToTraySettingsCard: macOS-only (renders null elsewhere 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

  • QuitWhenClosed skips prevent_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.

iroiro147 avatar Aug 01 '26 01:08 iroiro147