diff --git a/macos/Sources/App/macOS/AppDelegate.swift b/macos/Sources/App/macOS/AppDelegate.swift index 57e0212bb..f83b438f7 100644 --- a/macos/Sources/App/macOS/AppDelegate.swift +++ b/macos/Sources/App/macOS/AppDelegate.swift @@ -110,7 +110,7 @@ class AppDelegate: NSObject, } /// Tracks the windows that we hid for toggleVisibility. - private var hiddenState: ToggleVisibilityState? = nil + private(set) var hiddenState: ToggleVisibilityState? = nil /// The observer for the app appearance. private var appearanceObserver: NSKeyValueObservation? = nil @@ -280,6 +280,11 @@ class AppDelegate: NSObject, } } + func applicationDidHide(_ notification: Notification) { + // Keep track of our hidden state to restore properly + self.hiddenState = .init() + } + func applicationDidBecomeActive(_ notification: Notification) { // If we're back manually then clear the hidden state because macOS handles it. self.hiddenState = nil @@ -1084,8 +1089,6 @@ class AppDelegate: NSObject, guard let keyWindow = NSApp.keyWindow, !keyWindow.styleMask.contains(.fullScreen) else { return } - // Keep track of our hidden state to restore properly - self.hiddenState = .init() NSApp.hide(nil) return } @@ -1134,11 +1137,11 @@ class AppDelegate: NSObject, } } - private struct ToggleVisibilityState { + struct ToggleVisibilityState { let hiddenWindows: [Weak] let keyWindow: Weak? - init() { + fileprivate init() { // We need to know the key window so that we can bring focus back to the // right window if it was hidden. self.keyWindow = if let keyWindow = NSApp.keyWindow { diff --git a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift index 4669e108a..b3ad88666 100644 --- a/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift +++ b/macos/Sources/Features/QuickTerminal/QuickTerminalController.swift @@ -513,6 +513,10 @@ class QuickTerminalController: BaseTerminalController { if !window.isOnActiveSpace { self.previousApp = nil window.orderOut(self) + // If our application is hidden previously, we hide it again + if (NSApp.delegate as? AppDelegate)?.hiddenState != nil { + NSApp.hide(nil) + } return } @@ -549,6 +553,10 @@ class QuickTerminalController: BaseTerminalController { // This causes the window to be removed from the screen list and macOS // handles what should be focused next. window.orderOut(self) + // If our application is hidden previously, we hide it again + if (NSApp.delegate as? AppDelegate)?.hiddenState != nil { + NSApp.hide(nil) + } }) }