Skip to content

fix(macos): sync dock visibility when main window is hidden on close#1865

Open
ManthanNimodiya wants to merge 1 commit into
CapSoftware:mainfrom
ManthanNimodiya:fix/macos-app-switcher-persistence
Open

fix(macos): sync dock visibility when main window is hidden on close#1865
ManthanNimodiya wants to merge 1 commit into
CapSoftware:mainfrom
ManthanNimodiya:fix/macos-app-switcher-persistence

Conversation

@ManthanNimodiya
Copy link
Copy Markdown
Contributor

@ManthanNimodiya ManthanNimodiya commented May 21, 2026

What does this PR fix?

Fixes #1859,
Cap remains visible in the macOS Dock and App Switcher after closing the main window even when no windows are open.

Root cause

The CloseRequested handler for the Main window calls api.prevent_close() and window.hide() — the window is never destroyed.
Since the Destroyedevent is the only trigger for a dock visibility sync in this flow, no sync ever runs after Main is hidden.
The activation policy stays Regular, keeping Cap in the Dock and App Switcher indefinitely.

Fix

Added a schedule_macos_dock_visibility_sync call immediately after window.hide() in the Main window close handler.
This ensures the dock and app switcher state is correctly updated based on the user's 'Always show dock icon' setting.

Changes

  • apps/desktop/src-tauri/src/lib.rs: 3 lines added to Main CloseRequested handler

Greptile Summary

This PR fixes a macOS Dock/App Switcher visibility bug where Cap remained present in the Dock after the main window was hidden on close. Because the window is never destroyed (only hidden via api.prevent_close() + window.hide()), the existing Destroyed-event-triggered sync never fired, leaving the activation policy stuck on Regular.

  • Adds a single #[cfg(target_os = \"macos\")] schedule_macos_dock_visibility_sync(app) call right after window.hide() in the CapWindowId::Main close handler — exactly mirroring the pattern already used in several other places in windows.rs.
  • The sync function uses a generation-counter debounce (100 ms delay) to coalesce rapid events and avoid races, so the new call integrates cleanly with the rest of the dock-visibility logic.

Confidence Score: 5/5

Safe to merge — the change is a minimal, targeted addition to a macOS-only code path that follows a well-established pattern already used throughout the codebase.

The three added lines call an existing, well-tested helper that is already invoked in four other window-event handlers. The helper's debounce mechanism means the new call cannot race with or duplicate existing syncs. No existing behaviour is altered on non-macOS builds.

No files require special attention.

Important Files Changed

Filename Overview
apps/desktop/src-tauri/src/lib.rs Adds a macOS-only schedule_macos_dock_visibility_sync call immediately after window.hide() in the Main window CloseRequested handler, using the established debounced-generation pattern already present in the codebase.

Reviews (1): Last reviewed commit: "fix(macos): sync dock visibility when ma..." | Re-trigger Greptile

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

Labels

contributor:verified Contributor passed trust analysis. pr:verified PR passed security analysis.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Cap remains active in macOS App Switcher (Cmd+Tab) after closing Main Window with 'X'

1 participant