瀏覽代碼

Update launcher window to hide on blur and reopen on click.

The status bar icon now toggles hide/show instead of minimizing, the window auto-hides when the app resigns active state, and Dock/status icon interaction restores the main window.

Made-with: Cursor
huzaifahayat12 3 月之前
父節點
當前提交
4d51083a6c
共有 1 個文件被更改,包括 26 次插入8 次删除
  1. 26 8
      google_apps/AppDelegate.swift

+ 26 - 8
google_apps/AppDelegate.swift

@@ -93,12 +93,7 @@ class AppDelegate: NSObject, NSApplicationDelegate {
 
     @objc
     private func openMainWindowFromStatusBar() {
-        configureMainWindowIfNeeded()
-        NSApp.setActivationPolicy(.regular)
-        NSApp.activate(ignoringOtherApps: true)
-        if let window = NSApp.windows.first {
-            window.makeKeyAndOrderFront(nil)
-        }
+        showMainWindow()
     }
 
     @objc
@@ -106,13 +101,27 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         configureMainWindowIfNeeded()
         guard let window = NSApp.windows.first else { return }
 
-        if window.isVisible && !window.isMiniaturized {
-            window.miniaturize(nil)
+        if window.isVisible {
+            hideMainWindow()
             return
         }
 
+        showMainWindow()
+    }
+
+    private func hideMainWindow() {
+        guard let window = NSApp.windows.first else { return }
+        if window.isMiniaturized {
+            window.deminiaturize(nil)
+        }
+        window.orderOut(nil)
+    }
+
+    private func showMainWindow() {
+        configureMainWindowIfNeeded()
         NSApp.setActivationPolicy(.regular)
         NSApp.activate(ignoringOtherApps: true)
+        guard let window = NSApp.windows.first else { return }
         if window.isMiniaturized {
             window.deminiaturize(nil)
         }
@@ -158,6 +167,15 @@ class AppDelegate: NSObject, NSApplicationDelegate {
         // Insert code here to tear down your application
     }
 
+    func applicationDidResignActive(_ notification: Notification) {
+        hideMainWindow()
+    }
+
+    func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
+        showMainWindow()
+        return true
+    }
+
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
         return true
     }