[AltStoreCore] Fixes signing-in to Patreon with Google account

This commit is contained in:
Riley Testut
2023-12-07 15:53:15 -06:00
committed by Magesh K
parent 74b6fb6ec0
commit 1fbec33719

View File

@@ -97,9 +97,12 @@ public extension PatreonAPI
let configuration = WKWebViewConfiguration()
configuration.setURLSchemeHandler(self, forURLScheme: "altstore")
configuration.websiteDataStore = .default()
configuration.preferences.javaScriptCanOpenWindowsAutomatically = true
configuration.applicationNameForUserAgent = "Version/17.1.2 Mobile/15E148 Safari/604.1" // Required for "Sign-in With Google" to work in WKWebView
let webViewController = WebViewController(url: requestURL, configuration: configuration)
webViewController.delegate = self
webViewController.webView.uiDelegate = self
self.webViewController = webViewController
let callbackURL = try await withCheckedThrowingContinuation { continuation in
@@ -479,3 +482,25 @@ extension PatreonAPI: WKURLSchemeHandler
Logger.main.debug("WKWebView stopped handling url scheme.")
}
}
extension PatreonAPI: WKUIDelegate
{
public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView?
{
// Signing in with Google requires us to use separate windows/"tabs"
Logger.main.debug("Intercepting new window request: \(navigationAction.request)")
let webViewController = WebViewController(request: navigationAction.request, configuration: configuration)
webViewController.delegate = self
webViewController.webView.uiDelegate = self
self.webViewController?.navigationController?.pushViewController(webViewController, animated: true)
return webViewController.webView
}
public func webViewDidClose(_ webView: WKWebView)
{
self.webViewController?.navigationController?.popToRootViewController(animated: true)
}
}