Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 52 additions & 5 deletions Sources/Fluid/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
private var shouldSuppressNextReopenActivation = false
private var wasLaunchedAsLoginItem = false
private var hasDeferredMLXUpgradeOffer = false
private weak var mainWindowHiddenByAppHide: NSWindow?
private var shouldSuppressMainWindowLaunchReveal = false

func applicationDidFinishLaunching(_ notification: Notification) {
// Bring up file logging + crash handlers immediately during launch.
Expand Down Expand Up @@ -128,16 +130,55 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
return true
}

self.mainWindowHiddenByAppHide = nil
self.shouldSuppressMainWindowLaunchReveal = false

// Ensure dock-icon reopen always foregrounds FluidVoice.
sender.activate(ignoringOtherApps: true)

return !self.bringMainWindowToFrontIfPresent()
}

func applicationWillHide(_ notification: Notification) {
// A system-hidden login launch is not a user request to suppress its configured reveal.
if self.wasLaunchedAsLoginItem,
!self.didRevealMainWindowOnLaunch,
!NSApp.isActive
{
return
}

// A nonactivating recording panel can make AppKit unhide the process. Remember
// the visible main window so the panel does not restore it along with itself.
self.shouldSuppressMainWindowLaunchReveal = true
self.mainWindowHiddenByAppHide = NSApp.windows.first {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Track every visible main window during hide

When multiple FluidVoice windows are visibleβ€”supported by the WindowGroup declared in Sources/Fluid/fluidApp.swift:25β€”this first records only one of them. applicationDidHide therefore orders out only that window, so when the recording panel unhides the process, the other main windows can reappear despite Command-H; retain and order out all matching visible main windows instead.

Useful? React with πŸ‘Β / πŸ‘Ž.

self.isMainWindow($0) && $0.isVisible && !$0.isMiniaturized
}
if self.mainWindowHiddenByAppHide != nil {
self.didRevealMainWindowOnLaunch = true
}
}

func applicationDidHide(_ notification: Notification) {
self.mainWindowHiddenByAppHide?.orderOut(nil)
}

func applicationDidBecomeActive(_ notification: Notification) {
guard self.hasDeferredMLXUpgradeOffer else { return }
self.hasDeferredMLXUpgradeOffer = false
self.scheduleMLXUpgradeOffer()
self.shouldSuppressMainWindowLaunchReveal = false

if let mainWindow = self.mainWindowHiddenByAppHide {
self.mainWindowHiddenByAppHide = nil
if mainWindow.alphaValue <= 0.01 {
mainWindow.alphaValue = 1
}
mainWindow.orderFrontRegardless()
mainWindow.makeKeyAndOrderFront(nil)
}

if self.hasDeferredMLXUpgradeOffer {
self.hasDeferredMLXUpgradeOffer = false
self.scheduleMLXUpgradeOffer()
}
}

func userNotificationCenter(
Expand Down Expand Up @@ -200,7 +241,8 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
guard let self else { return }
guard self.didRevealMainWindowOnLaunch == false else { return }

if revealWindow {
let shouldRevealWindow = revealWindow && !self.shouldSuppressMainWindowLaunchReveal

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor show-at-login after an initially hidden launch

When macOS delivers applicationWillHide before the delayed launch attempts and showMainWindowAtLoginLaunch is enabled, this condition makes shouldRevealWindow false, so the code takes bootMainWindowHiddenIfPresent(), marks launch complete, and never reveals the window requested by the preference. Although the hidden boot now completes, the newly retained shouldSuppressMainWindowLaunchReveal branch is fresh evidence that the enabled-preference path remains bypassed; distinguish an explicit Command-H from the system's initially hidden login launch before suppressing the reveal.

Useful? React with πŸ‘Β / πŸ‘Ž.

if shouldRevealWindow {
NSApp.unhide(nil)
NSApp.activate(ignoringOtherApps: true)

Expand All @@ -209,13 +251,18 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
return
}
} else if self.bootMainWindowHiddenIfPresent() {
if self.shouldSuppressMainWindowLaunchReveal,
self.mainWindowHiddenByAppHide == nil
{
self.mainWindowHiddenByAppHide = NSApp.windows.first(where: self.isMainWindow)
}
self.didRevealMainWindowOnLaunch = true
return
}

DebugLogger.shared.debug("Main window not ready during launch reveal retry", source: "AppDelegate")
if delay >= 0.6 {
self.requestMainWindowReopenIfNeeded(activate: revealWindow)
self.requestMainWindowReopenIfNeeded(activate: shouldRevealWindow)
}
}
}
Expand Down
Loading