Merge branch 'window-activation': windows front and center, Cmd-Tab entry while open
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
commit
ecb6728f42
|
|
@ -48,6 +48,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
func applicationDidFinishLaunching(_: Notification) {
|
func applicationDidFinishLaunching(_: Notification) {
|
||||||
Settings.registerDefaults()
|
Settings.registerDefaults()
|
||||||
|
|
||||||
|
NotificationCenter.default.addObserver(
|
||||||
|
self,
|
||||||
|
selector: #selector(windowWillClose(_:)),
|
||||||
|
name: NSWindow.willCloseNotification,
|
||||||
|
object: nil
|
||||||
|
)
|
||||||
|
|
||||||
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
|
||||||
statusItem.button?.imagePosition = .imageLeft // icon stays visible next to the count
|
statusItem.button?.imagePosition = .imageLeft // icon stays visible next to the count
|
||||||
setMenuBarIcon("brewbar-uptodate")
|
setMenuBarIcon("brewbar-uptodate")
|
||||||
|
|
@ -117,10 +124,31 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
settingsWindow = SettingsWindowController(appDelegate: self)
|
settingsWindow = SettingsWindowController(appDelegate: self)
|
||||||
}
|
}
|
||||||
settingsWindow?.syncUI()
|
settingsWindow?.syncUI()
|
||||||
settingsWindow?.showWindow(nil)
|
presentWindow(of: settingsWindow)
|
||||||
// accessory app: without activation the window can open behind others
|
}
|
||||||
|
|
||||||
|
// MARK: - Window presentation
|
||||||
|
|
||||||
|
/// Accessory apps never appear in Cmd-Tab and their windows can open
|
||||||
|
/// behind other apps. While one of our windows is open we temporarily
|
||||||
|
/// become a regular app (Dock icon + Cmd-Tab entry); windowWillClose
|
||||||
|
/// drops back to accessory once the last window is gone.
|
||||||
|
func presentWindow(of controller: NSWindowController?) {
|
||||||
|
NSApp.setActivationPolicy(.regular)
|
||||||
|
controller?.showWindow(nil)
|
||||||
NSApp.activate(ignoringOtherApps: true)
|
NSApp.activate(ignoringOtherApps: true)
|
||||||
settingsWindow?.window?.makeKeyAndOrderFront(nil)
|
controller?.window?.makeKeyAndOrderFront(nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func windowWillClose(_: Notification) {
|
||||||
|
// async so the closing window's isVisible has flipped to false
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
let ourWindows = [self.logWindow?.window, self.settingsWindow?.window]
|
||||||
|
let stillOpen = ourWindows.compactMap { $0 }.contains { $0.isVisible }
|
||||||
|
if !stillOpen {
|
||||||
|
NSApp.setActivationPolicy(.accessory)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func resolveBrewPath() -> String {
|
func resolveBrewPath() -> String {
|
||||||
|
|
@ -433,7 +461,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
||||||
if logWindow == nil {
|
if logWindow == nil {
|
||||||
logWindow = LogWindowController()
|
logWindow = LogWindowController()
|
||||||
}
|
}
|
||||||
logWindow?.showWindow(nil)
|
|
||||||
logWindow?.update(text: logBuffer)
|
logWindow?.update(text: logBuffer)
|
||||||
|
presentWindow(of: logWindow)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue