|
@@ -53,6 +53,7 @@ struct RedditWebView: NSViewRepresentable {
|
|
|
var lastLoadedURL: URL?
|
|
var lastLoadedURL: URL?
|
|
|
private var prefillWorkItem: DispatchWorkItem?
|
|
private var prefillWorkItem: DispatchWorkItem?
|
|
|
private var canGoBackObservation: NSKeyValueObservation?
|
|
private var canGoBackObservation: NSKeyValueObservation?
|
|
|
|
|
+ private var urlObservation: NSKeyValueObservation?
|
|
|
var onCanGoBackChange: (Bool) -> Void
|
|
var onCanGoBackChange: (Bool) -> Void
|
|
|
private let onAuthError: (String) -> Void
|
|
private let onAuthError: (String) -> Void
|
|
|
|
|
|
|
@@ -69,13 +70,25 @@ struct RedditWebView: NSViewRepresentable {
|
|
|
|
|
|
|
|
canGoBackObservation = webView.observe(\.canGoBack, options: [.initial, .new]) { [weak self] webView, _ in
|
|
canGoBackObservation = webView.observe(\.canGoBack, options: [.initial, .new]) { [weak self] webView, _ in
|
|
|
DispatchQueue.main.async {
|
|
DispatchQueue.main.async {
|
|
|
- self?.onCanGoBackChange(webView.canGoBack)
|
|
|
|
|
|
|
+ self?.reportBackButtonVisibility(for: webView)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ urlObservation = webView.observe(\.url, options: [.new]) { [weak self] webView, _ in
|
|
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
|
+ self?.reportBackButtonVisibility(for: webView)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private func reportBackButtonVisibility(for webView: WKWebView) {
|
|
|
|
|
+ let isOnHome = webView.url.map(RedditWebAuthHelper.isRedditHomeURL) ?? false
|
|
|
|
|
+ onCanGoBackChange(webView.canGoBack && !isOnHome)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
|
|
|
startObservingNavigation(in: webView)
|
|
startObservingNavigation(in: webView)
|
|
|
|
|
+ reportBackButtonVisibility(for: webView)
|
|
|
webView.evaluateJavaScript(RedditPostBoundaryStyle.injectionScript, completionHandler: nil)
|
|
webView.evaluateJavaScript(RedditPostBoundaryStyle.injectionScript, completionHandler: nil)
|
|
|
webView.evaluateJavaScript(RedditHomeChromeStyle.injectionScript, completionHandler: nil)
|
|
webView.evaluateJavaScript(RedditHomeChromeStyle.injectionScript, completionHandler: nil)
|
|
|
webView.evaluateJavaScript(RedditAuthChromeStyle.injectionScript, completionHandler: nil)
|
|
webView.evaluateJavaScript(RedditAuthChromeStyle.injectionScript, completionHandler: nil)
|
|
@@ -149,8 +162,11 @@ struct RedditWebView: NSViewRepresentable {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if RedditWebAuthHelper.isOAuthProviderURL(url) {
|
|
if RedditWebAuthHelper.isOAuthProviderURL(url) {
|
|
|
- beginOAuthSignIn(url: url)
|
|
|
|
|
|
|
+ // Always route OAuth through ASWebAuthenticationSession. Reddit's login
|
|
|
|
|
+ // modal runs in a subframe; letting WebKit handle Google/Apple SSO there
|
|
|
|
|
+ // triggers SOAuthorizationCoordinator subframe errors and breaks sign-in.
|
|
|
decisionHandler(.cancel)
|
|
decisionHandler(.cancel)
|
|
|
|
|
+ beginOAuthSignIn(url: url)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|