Sfoglia il codice sorgente

Lock the main window to a 1080×680 default and minimum size.

Centralize window configuration so the app opens centered and can only be resized larger via delegate, layout, and SwiftUI constraints.

Co-authored-by: Cursor <cursoragent@cursor.com>
AhtashamShahzad1 3 settimane fa
parent
commit
d9050582d7

+ 4 - 13
clone _of_clarus_ai_chat_bot/AppDelegate.swift

@@ -10,22 +10,13 @@ import Cocoa
 @main
 class AppDelegate: NSObject, NSApplicationDelegate {
     func applicationDidFinishLaunching(_ notification: Notification) {
-        configureMainWindow()
+        DispatchQueue.main.async {
+            guard let window = NSApplication.shared.windows.first else { return }
+            WindowConfiguration.applyLaunchConfiguration(to: window)
+        }
     }
 
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
         true
     }
-
-    private func configureMainWindow() {
-        guard let window = NSApplication.shared.windows.first else { return }
-
-        window.title = "AI ChatBot Assistant"
-        window.setContentSize(NSSize(width: 1280, height: 820))
-        window.minSize = NSSize(width: 960, height: 640)
-        window.center()
-        window.isOpaque = true
-        window.appearance = NSAppearance(named: .aqua)
-        WindowConfigurator.applyUnifiedChrome(to: window)
-    }
 }

+ 3 - 3
clone _of_clarus_ai_chat_bot/Base.lproj/Main.storyboard

@@ -685,8 +685,8 @@
                 <windowController id="B8D-0N-5wS" sceneMemberID="viewController">
                     <window key="window" title="AI ChatBot Assistant" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="YES" animationBehavior="default" id="IQv-IB-iLA">
                         <windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
-                        <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
-                        <rect key="contentRect" x="196" y="120" width="1280" height="820"/>
+                        <windowPositionMask key="initialPositionMask"/>
+                        <rect key="contentRect" x="0.0" y="0.0" width="1080" height="680"/>
                         <rect key="screenRect" x="0.0" y="0.0" width="1680" height="1027"/>
                         <connections>
                             <outlet property="delegate" destination="B8D-0N-5wS" id="98r-iN-zZc"/>
@@ -705,7 +705,7 @@
             <objects>
                 <viewController id="XfG-lQ-9wD" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
                     <view key="view" id="m2S-Jp-Qdl">
-                        <rect key="frame" x="0.0" y="0.0" width="1280" height="820"/>
+                        <rect key="frame" x="0.0" y="0.0" width="1080" height="680"/>
                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                     </view>
                 </viewController>

+ 2 - 0
clone _of_clarus_ai_chat_bot/Utilities/AppTheme.swift

@@ -18,6 +18,8 @@ enum AppTheme {
     static let upgradeDescription = Color(red: 0.55, green: 0.48, blue: 0.45)
     static let upgradeButtonBorder = Color(red: 0.92, green: 0.90, blue: 0.89)
 
+    static let windowMinWidth: CGFloat = 1080
+    static let windowMinHeight: CGFloat = 680
     static let sidebarWidth: CGFloat = 248
     static let cornerRadiusLarge: CGFloat = 20
     static let cornerRadiusMedium: CGFloat = 12

+ 14 - 0
clone _of_clarus_ai_chat_bot/Utilities/MainWindowDelegate.swift

@@ -0,0 +1,14 @@
+import Cocoa
+
+final class MainWindowDelegate: NSObject, NSWindowDelegate {
+    func windowWillResize(_ sender: NSWindow, to frameSize: NSSize) -> NSSize {
+        let minimumFrameSize = sender.frameRect(
+            forContentRect: NSRect(origin: .zero, size: WindowConfiguration.minimumContentSize)
+        ).size
+
+        return NSSize(
+            width: max(frameSize.width, minimumFrameSize.width),
+            height: max(frameSize.height, minimumFrameSize.height)
+        )
+    }
+}

+ 40 - 0
clone _of_clarus_ai_chat_bot/Utilities/WindowConfiguration.swift

@@ -0,0 +1,40 @@
+import Cocoa
+
+enum WindowConfiguration {
+    static let defaultContentSize = NSSize(
+        width: AppTheme.windowMinWidth,
+        height: AppTheme.windowMinHeight
+    )
+    static let minimumContentSize = defaultContentSize
+
+    private static let windowDelegate = MainWindowDelegate()
+
+    static func applyLaunchConfiguration(to window: NSWindow) {
+        window.title = "AI ChatBot Assistant"
+        attachDelegate(to: window)
+        applySharedChrome(to: window)
+        window.setContentSize(defaultContentSize)
+        window.center()
+    }
+
+    static func applySharedChrome(to window: NSWindow) {
+        attachDelegate(to: window)
+        window.isOpaque = true
+        window.appearance = NSAppearance(named: .aqua)
+        WindowConfigurator.applyUnifiedChrome(to: window)
+        applySizeConstraints(to: window)
+    }
+
+    private static func attachDelegate(to window: NSWindow) {
+        window.delegate = windowDelegate
+    }
+
+    private static func applySizeConstraints(to window: NSWindow) {
+        window.contentMinSize = minimumContentSize
+
+        let minimumFrameSize = window.frameRect(
+            forContentRect: NSRect(origin: .zero, size: minimumContentSize)
+        ).size
+        window.minSize = minimumFrameSize
+    }
+}

+ 26 - 4
clone _of_clarus_ai_chat_bot/ViewController.swift

@@ -14,16 +14,38 @@ final class ViewController: NSViewController {
     override func loadView() {
         let homeView = HomeView(viewModel: viewModel)
         let hostingView = NSHostingView(rootView: homeView)
-        hostingView.autoresizingMask = [.width, .height]
+        hostingView.translatesAutoresizingMaskIntoConstraints = false
         hostingView.safeAreaRegions = .container
-        self.view = hostingView
+
+        let containerView = NSView()
+        containerView.translatesAutoresizingMaskIntoConstraints = false
+        containerView.addSubview(hostingView)
+
+        let minimumWidth = WindowConfiguration.minimumContentSize.width
+        let minimumHeight = WindowConfiguration.minimumContentSize.height
+
+        NSLayoutConstraint.activate([
+            hostingView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
+            hostingView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
+            hostingView.topAnchor.constraint(equalTo: containerView.topAnchor),
+            hostingView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor),
+            containerView.widthAnchor.constraint(greaterThanOrEqualToConstant: minimumWidth),
+            containerView.heightAnchor.constraint(greaterThanOrEqualToConstant: minimumHeight),
+        ])
+
+        self.view = containerView
     }
 
     override func viewDidAppear() {
         super.viewDidAppear()
 
-        if let window = view.window {
-            WindowConfigurator.applyUnifiedChrome(to: window)
+        guard let window = view.window else { return }
+        WindowConfiguration.applySharedChrome(to: window)
+
+        let contentSize = window.contentRect(forFrameRect: window.frame).size
+        if contentSize.width < WindowConfiguration.minimumContentSize.width
+            || contentSize.height < WindowConfiguration.minimumContentSize.height {
+            WindowConfiguration.applyLaunchConfiguration(to: window)
         }
     }
 }

+ 1 - 0
clone _of_clarus_ai_chat_bot/Views/HomeView.swift

@@ -8,6 +8,7 @@ struct HomeView: View {
             SidebarView(viewModel: viewModel)
             MainContentView(viewModel: viewModel)
         }
+        .frame(minWidth: AppTheme.windowMinWidth, minHeight: AppTheme.windowMinHeight)
         .frame(maxWidth: .infinity, maxHeight: .infinity)
         .background(AppTheme.pageBackground.ignoresSafeArea())
         .preferredColorScheme(.light)