فهرست منبع

Fix macOS traffic light behavior without changing window chrome.

Route title-bar clicks through to native controls, keep close from quitting the app, and reopen the main window from the Dock.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 3 هفته پیش
والد
کامیت
c686241b97

+ 9 - 0
clone _of_clarus_ai_chat_bot/AppDelegate.swift

@@ -19,4 +19,13 @@ class AppDelegate: NSObject, NSApplicationDelegate {
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
         true
     }
+
+    func applicationShouldHandleReopen(_ sender: NSApplication, hasVisibleWindows flag: Bool) -> Bool {
+        if !flag {
+            sender.windows.forEach { window in
+                window.makeKeyAndOrderFront(self)
+            }
+        }
+        return true
+    }
 }

+ 26 - 0
clone _of_clarus_ai_chat_bot/Utilities/MainHostingView.swift

@@ -0,0 +1,26 @@
+import AppKit
+import SwiftUI
+
+private enum TrafficLightHitRegion {
+    static let size = NSSize(width: 78, height: 32)
+}
+
+/// Passes mouse events in the traffic-light region through to the native window controls.
+final class MainHostingView<Content: View>: NSHostingView<Content> {
+    override func hitTest(_ point: NSPoint) -> NSView? {
+        if isTrafficLightPoint(point) {
+            return nil
+        }
+        return super.hitTest(point)
+    }
+
+    private func isTrafficLightPoint(_ point: NSPoint) -> Bool {
+        let trafficLightArea = NSRect(
+            x: 0,
+            y: isFlipped ? 0 : bounds.height - TrafficLightHitRegion.size.height,
+            width: TrafficLightHitRegion.size.width,
+            height: TrafficLightHitRegion.size.height
+        )
+        return trafficLightArea.contains(point)
+    }
+}

+ 5 - 0
clone _of_clarus_ai_chat_bot/Utilities/WindowConfigurator.swift

@@ -8,5 +8,10 @@ enum WindowConfigurator {
         window.titleVisibility = .hidden
         window.isMovableByWindowBackground = true
         window.backgroundColor = NSColor(AppTheme.pageBackground)
+
+        for buttonType in [NSWindow.ButtonType.closeButton, .miniaturizeButton, .zoomButton] {
+            window.standardWindowButton(buttonType)?.isEnabled = true
+            window.standardWindowButton(buttonType)?.isHidden = false
+        }
     }
 }

+ 1 - 1
clone _of_clarus_ai_chat_bot/ViewController.swift

@@ -13,7 +13,7 @@ final class ViewController: NSViewController {
 
     override func loadView() {
         let homeView = HomeView(viewModel: viewModel)
-        let hostingView = NSHostingView(rootView: homeView)
+        let hostingView = MainHostingView(rootView: homeView)
         hostingView.translatesAutoresizingMaskIntoConstraints = false
         hostingView.safeAreaRegions = .container