fix: honor hide-from-dock when launching at login without window (#396)#398
Open
postoso wants to merge 1 commit into
Open
fix: honor hide-from-dock when launching at login without window (#396)#398postoso wants to merge 1 commit into
postoso wants to merge 1 commit into
Conversation
…ic-dev#396) On login launches the SwiftUI main window is often not ready during the early reveal retries, so openMainWindowOnLaunch falls back to a LaunchServices reopen (NSWorkspace.openApplication) to create it. On a bundled app with LSUIElement=false, that reopen restores the bundle default activation policy (.regular) even when reopened without activation, so the Dock icon comes back even though the user enabled "Hide from dock". The window stays hidden, so the only visible symptom is the unexpected Dock icon. Re-apply the configured activation policy (showInDock ? .regular : .accessory) in the reopen completion so the setting is honored on login launches. The completion runs off the main thread, so the policy update hops back to main before touching NSApp. The existing line-145 policy call is factored into applyDockVisibilityPolicy() and reused. Edge case in the altic-dev#379 login-launch feature.
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.
Fixes #396.
Edge case in the login-launch feature from #379. With "Launch at startup" on, "Show window when launched at login" off, and "Hide from dock" on, 1.6.0 launches silently at login but the Dock icon still shows even though hide-from-dock is enabled. The window is correctly hidden, so the lone Dock icon is the only visible symptom.
Root cause
On login launches the SwiftUI main window often is not ready during the early reveal retries in openMainWindowOnLaunch, so it falls back to a LaunchServices reopen (NSWorkspace.openApplication) to create it. Because the app bundle ships LSUIElement=false, that reopen restores the bundle default activation policy (.regular) even when reopened with activates=false. Hide-from-dock is applied at runtime via setActivationPolicy(.accessory), and nothing re-applies it after the reopen, so the Dock icon comes back.
I confirmed the reopen behavior with a small standalone AppKit probe: an LSUIElement=false bundle set .accessory, reopened itself with activates=false, and came back as .regular. Re-asserting .accessory in the reopen completion put it back and it stuck. Ordering the window front (orderFrontRegardless) and NSApp.activate on their own did not change the policy.
Fix
Re-apply the configured activation policy (showInDock ? .regular : .accessory) in the reopen completion handler so the setting is honored on login launches. The completion runs off the main thread, so the policy update hops back to main before touching NSApp. The existing policy call is factored into a small applyDockVisibilityPolicy() helper and reused. This also covers login + show-window, which can hit the same reopen fallback.
Testing
I could not reproduce a real login-item launch end to end since it only happens at actual login. On-device check: set launch-at-startup on, show-at-login off, hide-from-dock on, reboot, log in, confirm no Dock icon. The FLUID_SIMULATE_LOGIN_LAUNCH=1 hook from #379 exercises the same branch.
No regression test: the failure lives in LaunchServices reopen plus process-activation glue with no clean unit-testable seam in the current test target. A showInDock to policy mapping test would only assert a one-line ternary that was never the broken part, so it would not catch this.