fix(macos): restore the hidden window on Dock-icon click (#248) - #378
Open
aniketshukla1 wants to merge 1 commit into
Open
fix(macos): restore the hidden window on Dock-icon click (#248)#378aniketshukla1 wants to merge 1 commit into
aniketshukla1 wants to merge 1 commit into
Conversation
Close-to-tray hides the main window instead of quitting (on_window_event's CloseRequested handler), but the RunEvent handler only dealt with Exit. macOS fires RunEvent::Reopen when the Dock icon is clicked, and Tauri does nothing with it by default — so the app activates (menu bar switches) but no window appears, and the user has no way to get it back short of relaunching. Handle RunEvent::Reopen by reshowing the main window via the existing show_main helper (unminimize + show + set_focus) — the same path the tray "Open" item already uses. Reopen is macOS-only, so the arm is #[cfg(target_os = "macos")]. Verified against the pinned tauri 2.11.5 source: RunEvent::Reopen is a macOS-gated non_exhaustive struct variant emitted for applicationShouldHandleReopen (the Dock-icon click).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #248.
After the window is dismissed, clicking the Dock icon activates OpenWorker (the menu bar switches) but no window appears, and
open -a OpenWorkerdoesn't bring it back — onlyopen -n(a brand-new instance) does.Cause
Close-to-tray hides the main window rather than quitting:
But the top-level
RunEventhandler only dealt withExitRequested/Exit. On macOS a Dock-icon click firesRunEvent::Reopen(theapplicationShouldHandleReopendelegate callback), and Tauri does nothing with it by default — so a hidden window is never reshown.Fix
Handle
RunEvent::Reopenby reshowing the main window through the existingshow_mainhelper — the exact path the tray Open item already uses:Reopenis macOS-only, so the arm is#[cfg(target_os = "macos")]. The{ .. }pattern intentionally ignores thehas_visible_windowsfield: reshowing/focusing on any reopen is the desired behavior and is a harmless no-op when a window is already up.Verification
I confirmed the API against the pinned tauri 2.11.5 source in the cargo cache:
So the variant is macOS-gated (the
#[cfg]wrapper is required), it's a non-exhaustive struct variant (the{ .. }pattern is correct), and it's emitted exactly for the Dock-icon reopen this issue is about.show_main(&AppHandle)is already called identically by the tray menu handler.I did not run a full
cargo buildlocally:generate_context!()embedsfrontendDist(../dist), so compiling requires a completenpm run build+ Tauri toolchain pass. The change is a 3-line addition that reuses an existing helper and mirrors the existingRunEventmatching in the same closure; happy to adjust if CI surfaces anything.