openhuman icon indicating copy to clipboard operation
openhuman copied to clipboard

fix(shell): use app-level hide on macOS close button (#2049)

Open M3gA-Mind opened this issue 6 months ago • 1 comments

Summary

  • Fixes the macOS red Close button leaving the app window open (#2049)
  • Replaces WebviewWindow::hide() with AppHandle::hide() in the macOS CloseRequested handler in app/src-tauri/src/lib.rs
  • AppHandle::hide() calls [NSApp hide:] via set_application_visibility(false) — the standard AppKit mechanism that reliably hides all windows
  • Dock-click (RunEvent::Reopen → show_main_window()) and tray "Open OpenHuman" already correctly restore the window; no changes needed there
  • Quit paths (Cmd+Q, tray Quit, frontend app_quit) are unchanged

Problem

  • On macOS, clicking the red Close button left the OpenHuman window fully visible and interactive — it could not be dismissed without force-quitting
  • The handler correctly called api.prevent_close() to stop CEF destroying the window, then called WebviewWindow::hide() — but this routes through WindowMessage::Hide → cef::Window::hide() in the vendored CEF runtime
  • cef::Window::hide() operates on a CEF-internal window handle that is disconnected from the visible NSWindow frame; ShowWindow-equivalent calls against it are silent no-ops on macOS
  • Impact: 100% of macOS users could not dismiss the window through standard OS controls

Solution

  • AppHandle::hide() calls set_application_visibility(false) → [NSApp hide:], which is the idiomatic macOS application-level hide and reliably collapses all app windows
  • The method is #[cfg(target_os = "macos")]-gated on AppHandle in the vendored tauri-cef crate (app/src-tauri/vendor/tauri-cef/crates/tauri/src/app.rs:1011), so no platform guards are added at the call site — the existing #[cfg(target_os = "macos")] on the event arm already covers it
  • Error handling: hide() returns tauri::Result<()>; a log::warn! is emitted on failure instead of silently swallowing the error as the old code did with let _ = window.hide()
  • The stale comment above the handler (which incorrectly claimed window.hide() routed through set_application_visibility) is corrected

Submission Checklist

  • [ ] Tests added or updated (happy path + at least one failure / edge case) — N/A: the behavior change is in the Tauri CEF runtime's macOS NSWindow path; the CEF window handle is not testable in unit tests. E2E Appium testing of the native close button is outside the current test infrastructure scope (noted in issue). cargo test --manifest-path app/src-tauri/Cargo.toml passes with no regressions.
  • [x] Diff coverage ≥ 80% — only lib.rs changed (Rust, Tauri shell); cargo test on the shell passes. No new JS/TS lines; Vitest coverage gate is unaffected.
  • [x] Coverage matrix updated — N/A: behaviour-only change to existing macOS close handler; no new feature rows
  • [x] All affected feature IDs from the matrix listed under ## Related — N/A: no feature matrix rows for window lifecycle
  • [x] No new external network dependencies introduced — N/A
  • [x] Manual smoke checklist updated if this touches release-cut surfaces — N/A: macOS window close is not a release-cut surface in docs/RELEASE-MANUAL-SMOKE.md
  • [x] Linked issue closed via Closes #NNN in ## Related

Impact

  • macOS desktop only — the changed code is #[cfg(target_os = "macos")]-gated; Windows and Linux close handlers are untouched
  • No performance, security, or migration implications
  • Side effect of [NSApp hide:]: all app windows (including the floating mascot panel, if open) are hidden. On RunEvent::Reopen, show_main_window() restores the main window; the mascot would need a separate show if it was visible — acceptable for this fix scope and consistent with standard macOS app behavior (e.g. Slack, Spotify)

Related

  • Closes #2049
  • Follow-up PR(s)/TODOs: Consider re-showing the mascot window on RunEvent::Reopen if it was visible before hide (low priority, separate issue)

AI Authored PR Metadata

Linear Issue

  • Key: N/A
  • URL: N/A

Commit & Branch

  • Branch: fix/mac-close-button-hide
  • Commit SHA: 4807241a6c85bf0f558ab8f375fc899772e10f32

Validation Run

  • [x] pnpm --filter openhuman-app format:check — clean
  • [x] pnpm --filter openhuman-app compile (typecheck) — clean
  • [x] Focused tests: cargo test --manifest-path app/src-tauri/Cargo.toml — all passing
  • [x] Rust fmt/check (Tauri shell): cargo fmt --manifest-path app/src-tauri/Cargo.toml -- --check — clean
  • [x] Tauri fmt/check: cargo check --manifest-path app/src-tauri/Cargo.toml — clean (26 pre-existing warnings, 0 errors)
  • [x] ESLint: pnpm --filter openhuman-app lint — 0 errors (50 pre-existing warnings, unchanged)
  • [x] Manual smoke: red Close button hides the app window; Dock-click restores it — verified locally on macOS

Validation Blocked

  • command: N/A
  • error: N/A
  • impact: N/A

Behavior Changes

  • Intended behavior change: macOS red Close button hides the app (all windows disappear, Dock icon remains); Dock-click or tray "Open" restores the main window
  • User-visible effect: clicking Close on macOS now dismisses the window as expected; the app continues running in the background — manually verified

Parity Contract

  • Legacy behavior preserved: api.prevent_close() still prevents CEF from destroying the window; quit paths (Cmd+Q, tray Quit, app_quit command) are identical
  • Guard/fallback/dispatch parity checks: Windows CloseRequested arm (set_main_window_hidden via EnumWindows) is untouched; Linux has no close handler (unchanged)

Duplicate / Superseded PR Handling

  • Duplicate PR(s): N/A
  • Canonical PR: this PR
  • Resolution: N/A

M3gA-Mind avatar May 18 '26 13:05 M3gA-Mind

📝 Walkthrough

Walkthrough

On macOS, the main window close request handler now hides the entire application via app_handle.hide() instead of hiding only the main webview window. Error logging is added if the hide operation fails, resolving the issue where the close button left the window visible.

Changes

macOS Close Handler

Layer / File(s) Summary
macOS close request to hide entire application
app/src-tauri/src/lib.rs
Within the RunEvent::WindowEvent handler for the main window, the close request behavior on macOS was changed from window.hide() to app_handle.hide() (after api.prevent_close()). If hiding the application fails, a warning is logged.

Possibly related PRs

  • tinyhumansai/openhuman#1841: Both PRs modify macOS-specific lifecycle handling in app/src-tauri/src/lib.rs, changing how Tauri hides and shuts down the app during close/quit events.

Poem

🐰 A window's close button, once ignored,
Now hides the whole app—that's what's restored!
On macOS, a rabbit's delight,
The app whisks away at first sight. ✨

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: using app-level hide instead of window-level hide on macOS when the close button is clicked.
Linked Issues check ✅ Passed The PR addresses the core objective from #2049 by implementing app-level hide via AppHandle::hide() on macOS, which reliably hides the window using standard AppKit mechanisms instead of the non-functional per-window hide path.
Out of Scope Changes check ✅ Passed All changes in lib.rs are scoped to fixing the macOS close button behavior; no unrelated refactoring, feature additions, or platform-unrelated modifications are present.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar May 18 '26 14:05 coderabbitai[bot]