Skip to content

fix(window): restore macOS main window - #1916

Merged
zerob13 merged 1 commit into
devfrom
fix/macos-main-window-reactivation
Jul 10, 2026
Merged

fix(window): restore macOS main window#1916
zerob13 merged 1 commit into
devfrom
fix/macos-main-window-reactivation

Conversation

@zerob13

@zerob13 zerob13 commented Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • track when the main window is hidden by close-to-tray on macOS
  • restore only close-hidden windows when the Dock activates the app
  • preserve native macOS Hide behavior and clear stale restore state on direct window shows
  • add regression coverage for close-to-hide, Dock activation, and native app hiding

Behavior

BEFORE

Cmd+W -> window.hide() -> Dock activate -> no action

AFTER

Cmd+W -> mark close-hidden -> window.hide()
                             -> Dock activate -> show + focus

Cmd+H -> app.isHidden() -> clear close-hidden mark
                         -> preserve native Hide behavior

Validation

  • pnpm run format
  • pnpm run format:check
  • pnpm run i18n
  • pnpm run lint
  • pnpm run typecheck
  • pnpm exec vitest run test/main/presenter/windowPresenter.test.ts test/main/presenter/lifecyclePresenter/hooks/ready/eventListenerSetupHook.test.ts test/main/presenter/trayPresenter.test.ts (13 tests passed)

Known unrelated test failures

The full test:main suite currently has two reproducible failures outside this change:

  • test/main/routes/debug/createMockChatSession.test.ts: expected mock session plan block is missing
  • test/main/presenter/agentSessionPresenter/integration.test.ts: long converted steer rebudget assertion fails

Summary by CodeRabbit

  • Bug Fixes

    • Improved macOS window restoration when a main window is hidden to the system tray.
    • Prevented unnecessary window creation or display when restoring an existing hidden window.
    • Improved handling of macOS app hide and activation events for more predictable window visibility and focus behavior.
  • Tests

    • Added coverage for close-to-tray restoration and macOS lifecycle edge cases.

@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 72396516-645c-4e6a-8fe9-acc876036d22

📥 Commits

Reviewing files that changed from the base of the PR and between 959b882 and 1d05340.

📒 Files selected for processing (5)
  • src/main/presenter/lifecyclePresenter/hooks/ready/eventListenerSetupHook.ts
  • src/main/presenter/windowPresenter/index.ts
  • src/shared/types/presenters/window.presenter.d.ts
  • test/main/presenter/lifecyclePresenter/hooks/ready/eventListenerSetupHook.test.ts
  • test/main/presenter/windowPresenter.test.ts

📝 Walkthrough

Walkthrough

The main window now records close-to-tray state, exposes restoration and clearing methods, restores before macOS activation window handling, and clears state after confirmed macOS hiding. Tests cover activation, deactivation timing, state transitions, and presenter behavior.

Changes

Close-to-tray restoration

Layer / File(s) Summary
Window state tracking and presenter API
src/main/presenter/windowPresenter/index.ts, src/shared/types/presenters/window.presenter.d.ts, test/main/presenter/windowPresenter.test.ts
The presenter tracks when the main window is hidden by an intercepted close, clears that state on show, focus, or destruction, and exposes restoration and clearing methods with corresponding tests.
macOS lifecycle integration
src/main/presenter/lifecyclePresenter/hooks/ready/eventListenerSetupHook.ts, test/main/presenter/lifecyclePresenter/hooks/ready/eventListenerSetupHook.test.ts
Activation attempts close-to-tray restoration before window enumeration, while deferred deactivation handling clears state only when app.isHidden() is true. Tests cover both paths.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant macOS
  participant eventListenerSetupHook
  participant WindowPresenter
  macOS->>eventListenerSetupHook: activate
  eventListenerSetupHook->>WindowPresenter: restoreMainWindowHiddenByClose()
  WindowPresenter-->>eventListenerSetupHook: restored or not restored
  macOS->>eventListenerSetupHook: did-resign-active
  eventListenerSetupHook->>macOS: check isHidden() after timeout
  eventListenerSetupHook->>WindowPresenter: clearMainWindowHiddenByClose()
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately summarizes the main change: restoring the macOS main window.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/macos-main-window-reactivation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@zerob13
zerob13 merged commit 36bf179 into dev Jul 10, 2026
2 checks passed
@zhangmo8
zhangmo8 deleted the fix/macos-main-window-reactivation branch July 10, 2026 05:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant