فهرست منبع

Fix launcher hide behavior when clicking desktop.

The launcher now hides when the app resigns active state and when its window resigns key status, covering desktop clicks that previously left the window visible.

Made-with: Cursor
huzaifahayat12 3 ماه پیش
والد
کامیت
185a9551fe
1فایلهای تغییر یافته به همراه24 افزوده شده و 1 حذف شده
  1. 24 1
      google_apps/AppDelegate.swift

+ 24 - 1
google_apps/AppDelegate.swift

@@ -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()