|
@@ -257,6 +257,7 @@ private extension ViewController {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
browserController.load(url: url, policy: policy)
|
|
browserController.load(url: url, policy: policy)
|
|
|
|
|
+ browserController.applyDefaultFrameCenteredOnVisibleScreen()
|
|
|
browserController.showWindow(nil)
|
|
browserController.showWindow(nil)
|
|
|
browserController.window?.makeKeyAndOrderFront(nil)
|
|
browserController.window?.makeKeyAndOrderFront(nil)
|
|
|
browserController.window?.orderFrontRegardless()
|
|
browserController.window?.orderFrontRegardless()
|
|
@@ -2309,16 +2310,22 @@ private enum InAppBrowserWebKitSupport {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private final class InAppBrowserWindowController: NSWindowController {
|
|
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()
|
|
private let browserViewController = InAppBrowserContainerViewController()
|
|
|
|
|
|
|
|
init() {
|
|
init() {
|
|
|
let browserWindow = NSWindow(
|
|
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],
|
|
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
|
|
backing: .buffered,
|
|
backing: .buffered,
|
|
|
defer: false
|
|
defer: false
|
|
|
)
|
|
)
|
|
|
browserWindow.title = "Browser"
|
|
browserWindow.title = "Browser"
|
|
|
|
|
+ browserWindow.isRestorable = false
|
|
|
|
|
+ browserWindow.setFrameAutosaveName("")
|
|
|
|
|
+ browserWindow.minSize = browserWindow.frameRect(forContentRect: NSRect(origin: .zero, size: Self.minimumContentSize)).size
|
|
|
browserWindow.center()
|
|
browserWindow.center()
|
|
|
browserWindow.contentViewController = browserViewController
|
|
browserWindow.contentViewController = browserViewController
|
|
|
super.init(window: browserWindow)
|
|
super.init(window: browserWindow)
|
|
@@ -2329,6 +2336,21 @@ private final class InAppBrowserWindowController: NSWindowController {
|
|
|
nil
|
|
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) {
|
|
func load(url: URL, policy: InAppBrowserURLPolicy) {
|
|
|
browserViewController.setNavigationPolicy(policy)
|
|
browserViewController.setNavigationPolicy(policy)
|
|
|
browserViewController.load(url: url)
|
|
browserViewController.load(url: url)
|