|
|
@@ -154,7 +154,10 @@ final class GoogleOAuthService: NSObject {
|
|
154
|
154
|
]
|
|
155
|
155
|
|
|
156
|
156
|
guard let authURL = components.url else { throw GoogleOAuthError.invalidCallbackURL }
|
|
157
|
|
- guard await openAuthURLInApp(authURL) else { throw GoogleOAuthError.unableToOpenBrowser }
|
|
|
157
|
+ let opened = await MainActor.run { [self] in
|
|
|
158
|
+ openAuthURLInApp(authURL)
|
|
|
159
|
+ }
|
|
|
160
|
+ guard opened else { throw GoogleOAuthError.unableToOpenBrowser }
|
|
158
|
161
|
defer {
|
|
159
|
162
|
Task { @MainActor [weak self] in
|
|
160
|
163
|
self?.closeInAppOAuthWindow()
|
|
|
@@ -489,6 +492,28 @@ extension GoogleOAuthError: LocalizedError {
|
|
489
|
492
|
}
|
|
490
|
493
|
}
|
|
491
|
494
|
|
|
|
495
|
+@MainActor
|
|
|
496
|
+private final class OAuthWebViewContainerView: NSView {
|
|
|
497
|
+ private let webView: WKWebView
|
|
|
498
|
+
|
|
|
499
|
+ init(webView: WKWebView) {
|
|
|
500
|
+ self.webView = webView
|
|
|
501
|
+ super.init(frame: .zero)
|
|
|
502
|
+ autoresizingMask = [.width, .height]
|
|
|
503
|
+ addSubview(webView)
|
|
|
504
|
+ }
|
|
|
505
|
+
|
|
|
506
|
+ @available(*, unavailable)
|
|
|
507
|
+ required init?(coder: NSCoder) {
|
|
|
508
|
+ nil
|
|
|
509
|
+ }
|
|
|
510
|
+
|
|
|
511
|
+ override func layout() {
|
|
|
512
|
+ super.layout()
|
|
|
513
|
+ webView.frame = bounds
|
|
|
514
|
+ }
|
|
|
515
|
+}
|
|
|
516
|
+
|
|
492
|
517
|
@MainActor
|
|
493
|
518
|
private final class InAppOAuthWindowController: NSWindowController, WKNavigationDelegate, WKUIDelegate {
|
|
494
|
519
|
private let webView: WKWebView
|
|
|
@@ -499,17 +524,8 @@ private final class InAppOAuthWindowController: NSWindowController, WKNavigation
|
|
499
|
524
|
config.defaultWebpagePreferences.allowsContentJavaScript = true
|
|
500
|
525
|
}
|
|
501
|
526
|
self.webView = WKWebView(frame: .zero, configuration: config)
|
|
502
|
|
- webView.translatesAutoresizingMaskIntoConstraints = false
|
|
503
|
|
-
|
|
504
|
|
- let container = NSView()
|
|
505
|
|
- container.translatesAutoresizingMaskIntoConstraints = false
|
|
506
|
|
- container.addSubview(webView)
|
|
507
|
|
- NSLayoutConstraint.activate([
|
|
508
|
|
- webView.leadingAnchor.constraint(equalTo: container.leadingAnchor),
|
|
509
|
|
- webView.trailingAnchor.constraint(equalTo: container.trailingAnchor),
|
|
510
|
|
- webView.topAnchor.constraint(equalTo: container.topAnchor),
|
|
511
|
|
- webView.bottomAnchor.constraint(equalTo: container.bottomAnchor)
|
|
512
|
|
- ])
|
|
|
527
|
+ // Frame-based layout avoids Auto Layout conflicts with WKWebView’s internal constraints.
|
|
|
528
|
+ let container = OAuthWebViewContainerView(webView: webView)
|
|
513
|
529
|
|
|
514
|
530
|
let window = NSWindow(
|
|
515
|
531
|
contentRect: NSRect(x: 0, y: 0, width: 980, height: 760),
|