Преглед изворни кода

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 пре 5 дана
родитељ
комит
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
10 10
 @main
11 11
 class AppDelegate: NSObject, NSApplicationDelegate {
12 12
 
13
+    private enum DefaultWindowSize {
14
+        static let width: CGFloat = 1020
15
+        static let height: CGFloat = 690
16
+    }
17
+    
13 18
     
14 19
 
15 20
 
16 21
     func applicationDidFinishLaunching(_ aNotification: Notification) {
17
-        // Insert code here to initialize your application
22
+        // Force a consistent launch size (avoid state restoration overriding it).
23
+        DispatchQueue.main.async { [weak self] in
24
+            self?.applyDefaultWindowSizeIfNeeded()
25
+        }
18 26
     }
19 27
 
20 28
     func applicationWillTerminate(_ aNotification: Notification) {
@@ -22,9 +30,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
22 30
     }
23 31
 
24 32
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
25
-        return true
33
+        // If enabled, macOS can restore the last window frame (size/position) on next launch.
34
+        // This app wants a consistent default launch size instead.
35
+        return false
26 36
     }
27 37
 
38
+    private func applyDefaultWindowSizeIfNeeded() {
39
+        let targetSize = NSSize(width: DefaultWindowSize.width, height: DefaultWindowSize.height)
40
+
41
+        for window in NSApplication.shared.windows {
42
+            // Only touch the main app window (not OAuth popups, alerts, etc.).
43
+            guard window.contentViewController is ViewController else { continue }
44
+
45
+            window.isRestorable = false
46
+            window.setContentSize(targetSize)
47
+            window.center()
48
+        }
49
+    }
28 50
 
29 51
 }
30 52
 

+ 17 - 1
zoom_app/ViewController.swift

@@ -1149,6 +1149,10 @@ class ViewController: NSViewController {
1149 1149
         stack.orientation = .vertical
1150 1150
         stack.spacing = style == .home ? 12 : 16
1151 1151
         stack.alignment = .centerX
1152
+        stack.distribution = .fill
1153
+        // Keep sidebar items pinned to the top; don't let extra height stretch/shift them.
1154
+        stack.setContentHuggingPriority(.required, for: .vertical)
1155
+        stack.setContentCompressionResistancePriority(.required, for: .vertical)
1152 1156
         stack.translatesAutoresizingMaskIntoConstraints = false
1153 1157
         sidebar.addSubview(stack)
1154 1158
 
@@ -1160,6 +1164,13 @@ class ViewController: NSViewController {
1160 1164
             row.layer?.backgroundColor = selectedRow ? sidebarActiveBackground.withAlphaComponent(0.95).cgColor : NSColor.clear.cgColor
1161 1165
             row.layer?.cornerRadius = style == .home ? 12 : 10
1162 1166
             row.widthAnchor.constraint(equalToConstant: style == .home ? 68 : 70).isActive = true
1167
+            // Prevent rows from stretching/collapsing when the window resizes.
1168
+            row.setContentHuggingPriority(.required, for: .vertical)
1169
+            row.setContentCompressionResistancePriority(.required, for: .vertical)
1170
+            if style == .home {
1171
+                // Must be tall enough for icon (26) + paddings + label without clipping.
1172
+                row.heightAnchor.constraint(equalToConstant: 66).isActive = true
1173
+            }
1163 1174
 
1164 1175
             if style == .home {
1165 1176
                 let iconContainer = NSView()
@@ -1237,7 +1248,11 @@ class ViewController: NSViewController {
1237 1248
         if style == .home {
1238 1249
             let spacer = NSView()
1239 1250
             spacer.translatesAutoresizingMaskIntoConstraints = false
1240
-            spacer.heightAnchor.constraint(greaterThanOrEqualToConstant: 12).isActive = true
1251
+            // Keep sidebar icons at the same vertical positions even when the window grows.
1252
+            // A flexible spacer will expand with height and push icons away from their default placement.
1253
+            spacer.heightAnchor.constraint(equalToConstant: 12).isActive = true
1254
+            spacer.setContentHuggingPriority(.required, for: .vertical)
1255
+            spacer.setContentCompressionResistancePriority(.required, for: .vertical)
1241 1256
             stack.addArrangedSubview(spacer)
1242 1257
             
1243 1258
             let settingsBadge = NSView()
@@ -1274,6 +1289,7 @@ class ViewController: NSViewController {
1274 1289
             stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
1275 1290
         } else {
1276 1291
             stack.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: 18).isActive = true
1292
+            stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
1277 1293
         }
1278 1294
 
1279 1295
         return sidebar