|
|
@@ -10,6 +10,16 @@ import Cocoa
|
|
|
@main
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
private var statusItem: NSStatusItem?
|
|
|
+ private weak var launcherWindowReference: NSWindow?
|
|
|
+
|
|
|
+ private var launcherWindow: NSWindow? {
|
|
|
+ if let launcherWindowReference {
|
|
|
+ return launcherWindowReference
|
|
|
+ }
|
|
|
+ let resolved = NSApp.windows.first
|
|
|
+ launcherWindowReference = resolved
|
|
|
+ return resolved
|
|
|
+ }
|
|
|
|
|
|
func applicationDidFinishLaunching(_ aNotification: Notification) {
|
|
|
applyBundledAppIcon()
|
|
|
@@ -99,9 +109,9 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
@objc
|
|
|
private func toggleMainWindowFromStatusBar() {
|
|
|
configureMainWindowIfNeeded()
|
|
|
- guard let window = NSApp.windows.first else { return }
|
|
|
+ guard let window = launcherWindow else { return }
|
|
|
|
|
|
- if window.isVisible {
|
|
|
+ if window.isVisible && window.isKeyWindow {
|
|
|
hideMainWindow()
|
|
|
return
|
|
|
}
|
|
|
@@ -110,7 +120,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
}
|
|
|
|
|
|
private func hideMainWindow() {
|
|
|
- guard let window = NSApp.windows.first else { return }
|
|
|
+ guard let window = launcherWindow else { return }
|
|
|
if window.isMiniaturized {
|
|
|
window.deminiaturize(nil)
|
|
|
}
|
|
|
@@ -121,26 +131,29 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
configureMainWindowIfNeeded()
|
|
|
NSApp.setActivationPolicy(.regular)
|
|
|
NSApp.activate(ignoringOtherApps: true)
|
|
|
- guard let window = NSApp.windows.first else { return }
|
|
|
+ guard let window = launcherWindow else { return }
|
|
|
if window.isMiniaturized {
|
|
|
window.deminiaturize(nil)
|
|
|
}
|
|
|
+ window.orderFrontRegardless()
|
|
|
window.makeKeyAndOrderFront(nil)
|
|
|
}
|
|
|
|
|
|
private func configureMainWindowIfNeeded() {
|
|
|
- guard let window = NSApp.windows.first else { return }
|
|
|
+ guard let window = launcherWindow else { return }
|
|
|
window.title = "My Apps"
|
|
|
- window.styleMask.remove(.titled)
|
|
|
+ window.styleMask.insert(.titled)
|
|
|
window.isOpaque = false
|
|
|
window.backgroundColor = .clear
|
|
|
applyRoundedCorners(to: window)
|
|
|
window.titlebarAppearsTransparent = true
|
|
|
window.titleVisibility = .hidden
|
|
|
window.styleMask.insert(.fullSizeContentView)
|
|
|
- // Avoid treating SwiftUI search fields as the draggable window background (clicks/typing fail otherwise).
|
|
|
- window.isMovableByWindowBackground = false
|
|
|
+ window.isMovableByWindowBackground = true
|
|
|
window.minSize = NSSize(width: 760, height: 520)
|
|
|
+ window.standardWindowButton(.closeButton)?.isHidden = true
|
|
|
+ window.standardWindowButton(.miniaturizeButton)?.isHidden = true
|
|
|
+ window.standardWindowButton(.zoomButton)?.isHidden = true
|
|
|
|
|
|
let targetContentSize = NSSize(width: 980, height: 700)
|
|
|
if window.contentRect(forFrameRect: window.frame).size.width < targetContentSize.width ||
|
|
|
@@ -167,9 +180,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
// Insert code here to tear down your application
|
|
|
}
|
|
|
|
|
|
- func applicationDidResignActive(_ notification: Notification) {
|
|
|
- hideMainWindow()
|
|
|
- }
|
|
|
+ func applicationDidResignActive(_ notification: Notification) {}
|
|
|
|
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
|
showMainWindow()
|