Просмотр исходного кода

Fix custom range apply behavior and ignore about:blank handoffs.

Enable the To-do Apply button only for Custom range, and prevent about/javascript intermediary URLs from launching Finder during sign-in and in-app browsing.

Made-with: Cursor
huzaifahayat12 3 часов назад
Родитель
Сommit
9e7f0c6fac
2 измененных файлов с 34 добавлено и 4 удалено
  1. 14 2
      classroom_app/Auth/GoogleOAuthService.swift
  2. 20 2
      classroom_app/ViewController.swift

+ 14 - 2
classroom_app/Auth/GoogleOAuthService.swift

@@ -549,6 +549,14 @@ private final class InAppOAuthWindowController: NSWindowController, WKNavigation
549 549
         webView.load(URLRequest(url: url))
550 550
     }
551 551
 
552
+    private func shouldOpenURLExternally(_ url: URL) -> Bool {
553
+        let scheme = (url.scheme ?? "").lowercased()
554
+        guard !scheme.isEmpty else { return false }
555
+        // Google auth popups can navigate through about:blank/javascript:
556
+        // as an intermediate step. Don't hand these to NSWorkspace.
557
+        return scheme != "about" && scheme != "javascript"
558
+    }
559
+
552 560
     func webView(
553 561
         _ webView: WKWebView,
554 562
         decidePolicyFor navigationAction: WKNavigationAction,
@@ -563,7 +571,9 @@ private final class InAppOAuthWindowController: NSWindowController, WKNavigation
563 571
             decisionHandler(.allow)
564 572
             return
565 573
         }
566
-        NSWorkspace.shared.open(url)
574
+        if shouldOpenURLExternally(url) {
575
+            NSWorkspace.shared.open(url)
576
+        }
567 577
         decisionHandler(.cancel)
568 578
     }
569 579
 
@@ -578,7 +588,9 @@ private final class InAppOAuthWindowController: NSWindowController, WKNavigation
578 588
             if scheme == "http" || scheme == "https" {
579 589
                 webView.load(URLRequest(url: requestURL))
580 590
             } else {
581
-                NSWorkspace.shared.open(requestURL)
591
+                if shouldOpenURLExternally(requestURL) {
592
+                    NSWorkspace.shared.open(requestURL)
593
+                }
582 594
             }
583 595
         }
584 596
         return nil

+ 20 - 2
classroom_app/ViewController.swift

@@ -354,6 +354,7 @@ final class ViewController: NSViewController {
354 354
     private weak var schedulePageFilterDropdown: NSPopUpButton?
355 355
     private weak var schedulePageFromDatePicker: NSDatePicker?
356 356
     private weak var schedulePageToDatePicker: NSDatePicker?
357
+    private weak var schedulePageApplyButton: NSButton?
357 358
     private weak var schedulePageRangeErrorLabel: NSTextField?
358 359
     private weak var schedulePageCardsStack: NSStackView?
359 360
     private weak var schedulePageCardsScrollView: NSScrollView?
@@ -3461,6 +3462,7 @@ private extension ViewController {
3461 3462
         filterRow.addArrangedSubview(filterRowSpacer)
3462 3463
 
3463 3464
         let applyButton = makeSchedulePagePillButton(title: "Apply", action: #selector(schedulePageApplyDateRangePressed(_:)))
3465
+        schedulePageApplyButton = applyButton
3464 3466
         filterRow.addArrangedSubview(applyButton)
3465 3467
         filterRow.setCustomSpacing(22, after: applyButton)
3466 3468
         let resetButton = makeSchedulePagePillButton(title: "Reset", action: #selector(schedulePageResetFiltersPressed(_:)))
@@ -6225,7 +6227,9 @@ private extension ViewController {
6225 6227
         let isCustom = schedulePageFilter == .customRange
6226 6228
         schedulePageFromDatePicker?.isEnabled = isCustom
6227 6229
         schedulePageToDatePicker?.isEnabled = isCustom
6230
+        schedulePageApplyButton?.isEnabled = isCustom
6228 6231
         let dim: CGFloat = isCustom ? 1.0 : 0.65
6232
+        schedulePageApplyButton?.alphaValue = isCustom ? 1.0 : 0.65
6229 6233
         schedulePageFromDatePicker?.alphaValue = 1
6230 6234
         schedulePageToDatePicker?.alphaValue = 1
6231 6235
         schedulePageFromDatePicker?.superview?.alphaValue = dim
@@ -7401,6 +7405,16 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7401 7405
         NSWorkspace.shared.open(url)
7402 7406
     }
7403 7407
 
7408
+    private func shouldOpenURLExternally(_ url: URL) -> Bool {
7409
+        let scheme = (url.scheme ?? "").lowercased()
7410
+        guard !scheme.isEmpty else { return false }
7411
+        // Some auth and popup flows briefly navigate through internal URLs like
7412
+        // about:blank or javascript: before redirecting to a real destination.
7413
+        // Opening these via NSWorkspace triggers Finder's "no application set"
7414
+        // dialog, so keep them in-app and ignore external handoff.
7415
+        return scheme != "about" && scheme != "javascript"
7416
+    }
7417
+
7404 7418
     func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
7405 7419
         processTerminateRetryCount = 0
7406 7420
         syncAddressFieldFromWebView()
@@ -7455,7 +7469,9 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7455 7469
         }
7456 7470
         let scheme = (url.scheme ?? "").lowercased()
7457 7471
         if scheme != "http" && scheme != "https" {
7458
-            openExternally(url)
7472
+            if shouldOpenURLExternally(url) {
7473
+                openExternally(url)
7474
+            }
7459 7475
             decisionHandler(.cancel)
7460 7476
             return
7461 7477
         }
@@ -7480,7 +7496,9 @@ private final class InAppBrowserContainerViewController: NSViewController, WKNav
7480 7496
         if navigationAction.targetFrame == nil, let requestURL = navigationAction.request.url {
7481 7497
             let scheme = (requestURL.scheme ?? "").lowercased()
7482 7498
             if scheme != "http" && scheme != "https" {
7483
-                openExternally(requestURL)
7499
+                if shouldOpenURLExternally(requestURL) {
7500
+                    openExternally(requestURL)
7501
+                }
7484 7502
             } else if inAppBrowserURLAllowed(requestURL, policy: navigationPolicy) {
7485 7503
                 webView.load(URLRequest(url: requestURL))
7486 7504
             } else {