From 11c7c61d713351b487db486b689aa7107d2a767c Mon Sep 17 00:00:00 2001 From: postoso Date: Mon, 22 Jun 2026 12:14:43 -0400 Subject: [PATCH] fix: honor hide-from-dock when launching at login without window (#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 #379 login-launch feature. --- Sources/Fluid/AppDelegate.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/Fluid/AppDelegate.swift b/Sources/Fluid/AppDelegate.swift index c745f004..b70fa9f2 100644 --- a/Sources/Fluid/AppDelegate.swift +++ b/Sources/Fluid/AppDelegate.swift @@ -141,8 +141,16 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele == OSType(keyAELaunchedAsLogInItem) } - private func openMainWindowOnLaunch() { + /// Apply the user's dock-visibility preference ("Hide from dock", issue #162). + /// Re-applied after operations that can reset the process activation policy - notably the + /// LaunchServices reopen below, which restores the bundle default (.regular) even when the + /// app is reopened without activation, so hide-from-dock is honored on login launches (#396). + private func applyDockVisibilityPolicy() { NSApp.setActivationPolicy(SettingsStore.shared.showInDock ? .regular : .accessory) + } + + private func openMainWindowOnLaunch() { + self.applyDockVisibilityPolicy() // Users can opt out of showing the window for login-item launches (#369). // The window must still be CREATED either way - ContentView's appearance @@ -215,10 +223,17 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele } DebugLogger.shared.info("Requesting LaunchServices reopen to create SwiftUI main window", source: "AppDelegate") - NSWorkspace.shared.openApplication(at: Bundle.main.bundleURL, configuration: configuration) { _, error in + NSWorkspace.shared.openApplication(at: Bundle.main.bundleURL, configuration: configuration) { [weak self] _, error in if let error { DebugLogger.shared.error("LaunchServices reopen failed: \(error.localizedDescription)", source: "AppDelegate") } + // The reopen restores the app's bundle default activation policy (.regular), which + // would surface the Dock icon even when the user enabled "Hide from dock". Re-apply + // the configured policy so login launches honor the setting (#396). The completion + // runs off the main thread, so hop back before touching NSApp. + DispatchQueue.main.async { + self?.applyDockVisibilityPolicy() + } } }