|
@@ -257,6 +257,7 @@ private extension ViewController {
|
|
257
|
}
|
257
|
}
|
|
258
|
|
258
|
|
|
259
|
browserController.load(url: url, policy: policy)
|
259
|
browserController.load(url: url, policy: policy)
|
|
|
|
260
|
+ browserController.applyDefaultFrameCenteredOnVisibleScreen()
|
|
260
|
browserController.showWindow(nil)
|
261
|
browserController.showWindow(nil)
|
|
261
|
browserController.window?.makeKeyAndOrderFront(nil)
|
262
|
browserController.window?.makeKeyAndOrderFront(nil)
|
|
262
|
browserController.window?.orderFrontRegardless()
|
263
|
browserController.window?.orderFrontRegardless()
|
|
@@ -2309,16 +2310,22 @@ private enum InAppBrowserWebKitSupport {
|
|
2309
|
}
|
2310
|
}
|
|
2310
|
|
2311
|
|
|
2311
|
private final class InAppBrowserWindowController: NSWindowController {
|
2312
|
private final class InAppBrowserWindowController: NSWindowController {
|
|
|
|
2313
|
+ private static let defaultContentSize = NSSize(width: 1100, height: 760)
|
|
|
|
2314
|
+ private static let minimumContentSize = NSSize(width: 800, height: 520)
|
|
|
|
2315
|
+
|
|
2312
|
private let browserViewController = InAppBrowserContainerViewController()
|
2316
|
private let browserViewController = InAppBrowserContainerViewController()
|
|
2313
|
|
2317
|
|
|
2314
|
init() {
|
2318
|
init() {
|
|
2315
|
let browserWindow = NSWindow(
|
2319
|
let browserWindow = NSWindow(
|
|
2316
|
- contentRect: NSRect(x: 0, y: 0, width: 1100, height: 760),
|
|
|
|
|
|
2320
|
+ contentRect: NSRect(origin: .zero, size: Self.defaultContentSize),
|
|
2317
|
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
2321
|
styleMask: [.titled, .closable, .miniaturizable, .resizable],
|
|
2318
|
backing: .buffered,
|
2322
|
backing: .buffered,
|
|
2319
|
defer: false
|
2323
|
defer: false
|
|
2320
|
)
|
2324
|
)
|
|
2321
|
browserWindow.title = "Browser"
|
2325
|
browserWindow.title = "Browser"
|
|
|
|
2326
|
+ browserWindow.isRestorable = false
|
|
|
|
2327
|
+ browserWindow.setFrameAutosaveName("")
|
|
|
|
2328
|
+ browserWindow.minSize = browserWindow.frameRect(forContentRect: NSRect(origin: .zero, size: Self.minimumContentSize)).size
|
|
2322
|
browserWindow.center()
|
2329
|
browserWindow.center()
|
|
2323
|
browserWindow.contentViewController = browserViewController
|
2330
|
browserWindow.contentViewController = browserViewController
|
|
2324
|
super.init(window: browserWindow)
|
2331
|
super.init(window: browserWindow)
|
|
@@ -2329,6 +2336,21 @@ private final class InAppBrowserWindowController: NSWindowController {
|
|
2329
|
nil
|
2336
|
nil
|
|
2330
|
}
|
2337
|
}
|
|
2331
|
|
2338
|
|
|
|
|
2339
|
+ /// Resets size and position each time the browser is shown so a previously tiny window is never reused.
|
|
|
|
2340
|
+ func applyDefaultFrameCenteredOnVisibleScreen() {
|
|
|
|
2341
|
+ guard let w = window, let screen = w.screen ?? NSScreen.main else { return }
|
|
|
|
2342
|
+ let windowFrame = w.frameRect(forContentRect: NSRect(origin: .zero, size: Self.defaultContentSize))
|
|
|
|
2343
|
+ let vf = screen.visibleFrame
|
|
|
|
2344
|
+ var frame = windowFrame
|
|
|
|
2345
|
+ frame.origin.x = vf.midX - frame.width / 2
|
|
|
|
2346
|
+ frame.origin.y = vf.midY - frame.height / 2
|
|
|
|
2347
|
+ if frame.maxX > vf.maxX { frame.origin.x = vf.maxX - frame.width }
|
|
|
|
2348
|
+ if frame.minX < vf.minX { frame.origin.x = vf.minX }
|
|
|
|
2349
|
+ if frame.maxY > vf.maxY { frame.origin.y = vf.maxY - frame.height }
|
|
|
|
2350
|
+ if frame.minY < vf.minY { frame.origin.y = vf.minY }
|
|
|
|
2351
|
+ w.setFrame(frame, display: true)
|
|
|
|
2352
|
+ }
|
|
|
|
2353
|
+
|
|
2332
|
func load(url: URL, policy: InAppBrowserURLPolicy) {
|
2354
|
func load(url: URL, policy: InAppBrowserURLPolicy) {
|
|
2333
|
browserViewController.setNavigationPolicy(policy)
|
2355
|
browserViewController.setNavigationPolicy(policy)
|
|
2334
|
browserViewController.load(url: url)
|
2356
|
browserViewController.load(url: url)
|