소스 검색

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
 @main
10
 @main
11
 class AppDelegate: NSObject, NSApplicationDelegate {
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
     func applicationDidFinishLaunching(_ aNotification: Notification) {
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
     func applicationWillTerminate(_ aNotification: Notification) {
28
     func applicationWillTerminate(_ aNotification: Notification) {
@@ -22,9 +30,23 @@ class AppDelegate: NSObject, NSApplicationDelegate {
22
     }
30
     }
23
 
31
 
24
     func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool {
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
         stack.orientation = .vertical
1149
         stack.orientation = .vertical
1150
         stack.spacing = style == .home ? 12 : 16
1150
         stack.spacing = style == .home ? 12 : 16
1151
         stack.alignment = .centerX
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
         stack.translatesAutoresizingMaskIntoConstraints = false
1156
         stack.translatesAutoresizingMaskIntoConstraints = false
1153
         sidebar.addSubview(stack)
1157
         sidebar.addSubview(stack)
1154
 
1158
 
@@ -1160,6 +1164,13 @@ class ViewController: NSViewController {
1160
             row.layer?.backgroundColor = selectedRow ? sidebarActiveBackground.withAlphaComponent(0.95).cgColor : NSColor.clear.cgColor
1164
             row.layer?.backgroundColor = selectedRow ? sidebarActiveBackground.withAlphaComponent(0.95).cgColor : NSColor.clear.cgColor
1161
             row.layer?.cornerRadius = style == .home ? 12 : 10
1165
             row.layer?.cornerRadius = style == .home ? 12 : 10
1162
             row.widthAnchor.constraint(equalToConstant: style == .home ? 68 : 70).isActive = true
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
             if style == .home {
1175
             if style == .home {
1165
                 let iconContainer = NSView()
1176
                 let iconContainer = NSView()
@@ -1237,7 +1248,11 @@ class ViewController: NSViewController {
1237
         if style == .home {
1248
         if style == .home {
1238
             let spacer = NSView()
1249
             let spacer = NSView()
1239
             spacer.translatesAutoresizingMaskIntoConstraints = false
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
             stack.addArrangedSubview(spacer)
1256
             stack.addArrangedSubview(spacer)
1242
             
1257
             
1243
             let settingsBadge = NSView()
1258
             let settingsBadge = NSView()
@@ -1274,6 +1289,7 @@ class ViewController: NSViewController {
1274
             stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
1289
             stack.bottomAnchor.constraint(lessThanOrEqualTo: sidebar.bottomAnchor, constant: -18).isActive = true
1275
         } else {
1290
         } else {
1276
             stack.topAnchor.constraint(equalTo: sidebar.topAnchor, constant: 18).isActive = true
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
         return sidebar
1295
         return sidebar