|
@@ -13,6 +13,7 @@ enum AppWindowConfiguration {
|
|
|
|
|
|
|
|
@MainActor
|
|
@MainActor
|
|
|
static func apply(to window: NSWindow) {
|
|
static func apply(to window: NSWindow) {
|
|
|
|
|
+ MainWindowCloseBehavior.install(on: window)
|
|
|
window.minSize = minimumContentSize
|
|
window.minSize = minimumContentSize
|
|
|
window.isRestorable = false
|
|
window.isRestorable = false
|
|
|
window.title = AppMarketingLinks.appDisplayName
|
|
window.title = AppMarketingLinks.appDisplayName
|
|
@@ -102,5 +103,39 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
return false
|
|
return false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// Keep running in the Dock when the user closes the last window (standard single-window macOS apps).
|
|
|
|
|
+ func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool {
|
|
|
|
|
+ false
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// Clicking the Dock icon after closing the window should bring it back.
|
|
|
|
|
+ func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
|
|
|
+ guard !flag else { return true }
|
|
|
|
|
+ let window = AppWindowConfiguration.mainWindow(in: sender)
|
|
|
|
|
+ ?? sender.windows.first(where: { $0.canBecomeKey })
|
|
|
|
|
+ window?.makeKeyAndOrderFront(self)
|
|
|
|
|
+ sender.activate(ignoringOtherApps: true)
|
|
|
|
|
+ return true
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// MARK: - Main window close (hide on red button, do not quit)
|
|
|
|
|
+
|
|
|
|
|
+@MainActor
|
|
|
|
|
+private enum MainWindowCloseBehavior {
|
|
|
|
|
+ private final class WindowDelegate: NSObject, NSWindowDelegate {
|
|
|
|
|
+ static let shared = WindowDelegate()
|
|
|
|
|
|
|
|
|
|
+ func windowShouldClose(_ sender: NSWindow) -> Bool {
|
|
|
|
|
+ sender.orderOut(nil)
|
|
|
|
|
+ return false
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ static func install(on window: NSWindow) {
|
|
|
|
|
+ window.isReleasedWhenClosed = false
|
|
|
|
|
+ if window.delegate !== WindowDelegate.shared {
|
|
|
|
|
+ window.delegate = WindowDelegate.shared
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|