Pārlūkot izejas kodu

Fix OAuth MainActor await warning, hover closures, WKWebView layout

Use MainActor.run for synchronous openAuthURLInApp to satisfy await.
Replace unused guard let self with guard self != nil in meet card hovers.
Lay out OAuth WKWebView with frame-based container to avoid Auto Layout conflicts.

Made-with: Cursor
huzaifahayat12 1 nedēļu atpakaļ
vecāks
revīzija
936d994bf2

+ 28 - 12
classroom_app/Auth/GoogleOAuthService.swift

@@ -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),

+ 2 - 2
classroom_app/ViewController.swift

@@ -2750,12 +2750,12 @@ private extension ViewController {
2750 2750
         let hoverColor = baseColor.blended(withFraction: darkModeEnabled ? 0.24 : 0.16, of: classroomHoverTint) ?? baseColor
2751 2751
         let hoverBorderColor = baseBorderColor.blended(withFraction: darkModeEnabled ? 0.45 : 0.32, of: classroomHoverTint) ?? baseBorderColor
2752 2752
         instant.onHoverChanged = { [weak self] hovering in
2753
-            guard let self else { return }
2753
+            guard self != nil else { return }
2754 2754
             instant.layer?.backgroundColor = (hovering ? hoverColor : baseColor).cgColor
2755 2755
             instant.layer?.borderColor = (hovering ? hoverBorderColor : baseBorderColor).cgColor
2756 2756
         }
2757 2757
         codeCard.onHoverChanged = { [weak self] hovering in
2758
-            guard let self else { return }
2758
+            guard self != nil else { return }
2759 2759
             codeCard.layer?.backgroundColor = (hovering ? hoverColor : baseColor).cgColor
2760 2760
             codeCard.layer?.borderColor = (hovering ? hoverBorderColor : baseBorderColor).cgColor
2761 2761
         }