Procházet zdrojové kódy

Fix in-app browser window size on each open

Disable frame autosave and restoration, apply a default 1100×760 content size centered on the visible screen every time the browser opens, and enforce a minimum content size so the window cannot collapse to a thin strip.

Made-with: Cursor
huzaifahayat12 před 3 měsíci
rodič
revize
bacd037d93
1 změnil soubory, kde provedl 23 přidání a 1 odebrání
  1. 23 1
      meetings_app/ViewController.swift

+ 23 - 1
meetings_app/ViewController.swift

@@ -257,6 +257,7 @@ private extension ViewController {
         }
 
         browserController.load(url: url, policy: policy)
+        browserController.applyDefaultFrameCenteredOnVisibleScreen()
         browserController.showWindow(nil)
         browserController.window?.makeKeyAndOrderFront(nil)
         browserController.window?.orderFrontRegardless()
@@ -2309,16 +2310,22 @@ private enum InAppBrowserWebKitSupport {
 }
 
 private final class InAppBrowserWindowController: NSWindowController {
+    private static let defaultContentSize = NSSize(width: 1100, height: 760)
+    private static let minimumContentSize = NSSize(width: 800, height: 520)
+
     private let browserViewController = InAppBrowserContainerViewController()
 
     init() {
         let browserWindow = NSWindow(
-            contentRect: NSRect(x: 0, y: 0, width: 1100, height: 760),
+            contentRect: NSRect(origin: .zero, size: Self.defaultContentSize),
             styleMask: [.titled, .closable, .miniaturizable, .resizable],
             backing: .buffered,
             defer: false
         )
         browserWindow.title = "Browser"
+        browserWindow.isRestorable = false
+        browserWindow.setFrameAutosaveName("")
+        browserWindow.minSize = browserWindow.frameRect(forContentRect: NSRect(origin: .zero, size: Self.minimumContentSize)).size
         browserWindow.center()
         browserWindow.contentViewController = browserViewController
         super.init(window: browserWindow)
@@ -2329,6 +2336,21 @@ private final class InAppBrowserWindowController: NSWindowController {
         nil
     }
 
+    /// Resets size and position each time the browser is shown so a previously tiny window is never reused.
+    func applyDefaultFrameCenteredOnVisibleScreen() {
+        guard let w = window, let screen = w.screen ?? NSScreen.main else { return }
+        let windowFrame = w.frameRect(forContentRect: NSRect(origin: .zero, size: Self.defaultContentSize))
+        let vf = screen.visibleFrame
+        var frame = windowFrame
+        frame.origin.x = vf.midX - frame.width / 2
+        frame.origin.y = vf.midY - frame.height / 2
+        if frame.maxX > vf.maxX { frame.origin.x = vf.maxX - frame.width }
+        if frame.minX < vf.minX { frame.origin.x = vf.minX }
+        if frame.maxY > vf.maxY { frame.origin.y = vf.maxY - frame.height }
+        if frame.minY < vf.minY { frame.origin.y = vf.minY }
+        w.setFrame(frame, display: true)
+    }
+
     func load(url: URL, policy: InAppBrowserURLPolicy) {
         browserViewController.setNavigationPolicy(policy)
         browserViewController.load(url: url)