|
|
@@ -11,6 +11,7 @@ import Cocoa
|
|
|
class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
private var statusItem: NSStatusItem?
|
|
|
private weak var launcherWindowReference: NSWindow?
|
|
|
+ private var launcherWindowResignObserver: NSObjectProtocol?
|
|
|
|
|
|
private var launcherWindow: NSWindow? {
|
|
|
if let launcherWindowReference, launcherWindowReference.contentViewController is ViewController {
|
|
|
@@ -151,6 +152,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
|
|
|
private func configureMainWindowIfNeeded() {
|
|
|
guard let window = launcherWindow else { return }
|
|
|
+ observeLauncherWindowResign(window)
|
|
|
window.title = "My Apps"
|
|
|
window.styleMask.insert(.titled)
|
|
|
window.isOpaque = false
|
|
|
@@ -178,6 +180,21 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private func observeLauncherWindowResign(_ window: NSWindow) {
|
|
|
+ if let observer = launcherWindowResignObserver {
|
|
|
+ NotificationCenter.default.removeObserver(observer)
|
|
|
+ launcherWindowResignObserver = nil
|
|
|
+ }
|
|
|
+
|
|
|
+ launcherWindowResignObserver = NotificationCenter.default.addObserver(
|
|
|
+ forName: NSWindow.didResignKeyNotification,
|
|
|
+ object: window,
|
|
|
+ queue: .main
|
|
|
+ ) { [weak self] _ in
|
|
|
+ self?.hideMainWindow()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private func applyRoundedCorners(to window: NSWindow) {
|
|
|
let cornerRadius: CGFloat = 16
|
|
|
window.hasShadow = true
|
|
|
@@ -187,10 +204,16 @@ class AppDelegate: NSObject, NSApplicationDelegate {
|
|
|
}
|
|
|
|
|
|
func applicationWillTerminate(_ aNotification: Notification) {
|
|
|
+ if let observer = launcherWindowResignObserver {
|
|
|
+ NotificationCenter.default.removeObserver(observer)
|
|
|
+ launcherWindowResignObserver = nil
|
|
|
+ }
|
|
|
// Insert code here to tear down your application
|
|
|
}
|
|
|
|
|
|
- func applicationDidResignActive(_ notification: Notification) {}
|
|
|
+ func applicationDidResignActive(_ notification: Notification) {
|
|
|
+ hideMainWindow()
|
|
|
+ }
|
|
|
|
|
|
func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
|
|
|
showMainWindow()
|