فهرست منبع

Fix default window sizing and sidebar layout

Force a consistent launch window size and prevent state restoration from overriding it. Stabilize the home sidebar stack so icons/labels don't shift or clip when resizing.

Made-with: Cursor
huzaifahayat12 3 ماه پیش
والد
کامیت
2744ccd9f9
2فایلهای تغییر یافته به همراه41 افزوده شده و 3 حذف شده
  1. 24 2
      zoom_app/AppDelegate.swift
  2. 17 1
      zoom_app/ViewController.swift

+ 24 - 2
zoom_app/AppDelegate.swift

@@ -10,11 +10,19 @@ import Cocoa
 @main
 class AppDelegate: NSObject, NSApplicationDelegate {
 
+    private enum DefaultWindowSize {
+        static let width: CGFloat = 1020
+        static let height: CGFloat = 690
+    }
+    
     
 
 
     func applicationDidFinishLaunching(_ aNotification: Notification) {
-        // Insert code here to initialize your application
+        // Force a consistent launch size (avoid state restoration overriding it).
+        DispatchQueue.main.async { [weak self] in
+            self?.applyDefaultWindowSizeIfNeeded()
+        }
     }
 
     func applicationWillTerminate(_ aNotification: Notification) {
@@ -22,9 +30,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
     }
 
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
-        return true
+        // If enabled, macOS can restore the last window frame (size/position) on next launch.
+        // This app wants a consistent default launch size instead.
+        return false
     }
 
+    private func applyDefaultWindowSizeIfNeeded() {
+        let targetSize = NSSize(width: DefaultWindowSize.width, height: DefaultWindowSize.height)
+
+        for window in NSApplication.shared.windows {
+            // Only touch the main app window (not OAuth popups, alerts, etc.).
+            guard window.contentViewController is ViewController else { continue }
+
+            window.isRestorable = false
+            window.setContentSize(targetSize)
+            window.center()
+        }
+    }
 
 }
 

+ 17 - 1
zoom_app/ViewController.swift

@@ -1149,6 +1149,10 @@ class ViewController: NSViewController {
         stack.orientation = .vertical
         stack.spacing = style == .home ? 12 : 16
         stack.alignment = .centerX
+        stack.distribution = .fill
+        // Keep sidebar items pinned to the top; don't let extra height stretch/shift them.
+        stack.setContentHuggingPriority(.required, for: .vertical)
+        stack.setContentCompressionResistancePriority(.required, for: .vertical)
         stack.translatesAutoresizingMaskIntoConstraints = false
         sidebar.addSubview(stack)
 
@@ -1160,6 +1164,13 @@ class ViewController: NSViewController {
             row.layer?.backgroundColor = selectedRow ? sidebarActiveBackground.withAlphaComponent(0.95).cgColor : NSColor.clear.cgColor
             row.layer?.cornerRadius = style == .home ? 12 : 10
             row.widthAnchor.constraint(equalToConstant: style == .home ? 68 : 70).isActive = true
+            // Prevent rows from stretching/collapsing when the window resizes.
+            row.setContentHuggingPriority(.required, for: .vertical)
+            row.setContentCompressionResistancePriority(.required, for: .vertical)
+            if style == .home {
+                // Must be tall enough for icon (26) + paddings + label without clipping.
+                row.heightAnchor.constraint(equalToConstant: 66).isActive = true
+            }
 
             if style == .home {
                 let iconContainer = NSView()
@@ -1237,7 +1248,11 @@ class ViewController: NSViewController {
         if style == .home {
             let spacer = NSView()
             spacer.translatesAutoresizingMaskIntoConstraints = false
-            spacer.heightAnchor.constraint(greaterThanOrEqualToConstant: 12).isActive = true
+            // Keep sidebar icons at the same vertical positions even when the window grows.
+            // A flexible spacer will expand with height and push icons away from their default placement.
+            spacer.heightAnchor.constraint(equalToConstant: 12).isActive = true
+            spacer.setContentHuggingPriority(.required, for: .vertical)
+            spacer.setContentCompressionResistancePriority(.required, for: .vertical)
             stack.addArrangedSubview(spacer)
             
             let settingsBadge = NSView()
@@ -1274,6 +1289,7 @@ class ViewController: NSViewController {
             stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
         } else {
             stack.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: 18).isActive = true
+            stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
         }
 
         return sidebar