diff options
author | Hailey <me@haileyok.com> | 2024-10-09 15:29:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-09 15:29:25 -0700 |
commit | 28419447891edb17101876fe9ca3c749b4802313 (patch) | |
tree | f87a5dc1f8ad5781fc528411182b1e829920c8a1 /modules | |
parent | 9f070cd9cdc5387e664180c5b771d07595acc261 (diff) | |
download | voidsky-28419447891edb17101876fe9ca3c749b4802313.tar.zst |
Ensure app clip works even with `starter-pack` (#5664)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/BlueskyClip/ViewController.swift | 44 |
1 files changed, 36 insertions, 8 deletions
diff --git a/modules/BlueskyClip/ViewController.swift b/modules/BlueskyClip/ViewController.swift index b178644b8..5385ab700 100644 --- a/modules/BlueskyClip/ViewController.swift +++ b/modules/BlueskyClip/ViewController.swift @@ -42,7 +42,7 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele let payload = try? JSONDecoder().decode(WebViewActionPayload.self, from: data) else { return } - + switch payload.action { case .present: guard let url = self.starterPackUrl else { @@ -66,23 +66,51 @@ class ViewController: UIViewController, WKScriptMessageHandler, WKNavigationDele guard let url = navigationAction.request.url else { return .allow } - + // Store the previous one to compare later, but only set starterPackUrl when we find the right one prevUrl = url // pathComponents starts with "/" as the first component, then each path name. so... // ["/", "start", "name", "rkey"] - if url.pathComponents.count == 4, - url.pathComponents[1] == "start" { + if isStarterPackUrl(url){ self.starterPackUrl = url } - + return .allow } + + func isStarterPackUrl(_ url: URL) -> Bool { + var host: String? + if #available(iOS 16.0, *) { + host = url.host() + } else { + host = url.host + } + + switch host { + case "bsky.app": + if url.pathComponents.count == 4, + (url.pathComponents[1] == "start" || url.pathComponents[1] == "starter-pack") { + return true + } + return false + case "go.bsky.app": + if url.pathComponents.count == 2 { + return true + } + return false + default: + return false + } + } func handleURL(url: URL) { - let urlString = "\(url.absoluteString)?clip=true" - if let url = URL(string: urlString) { - self.webView?.load(URLRequest(url: url)) + if isStarterPackUrl(url) { + let urlString = "\(url.absoluteString)?clip=true" + if let url = URL(string: urlString) { + self.webView?.load(URLRequest(url: url)) + } + } else { + self.webView?.load(URLRequest(url: URL(string: "https://bsky.app/?splash=true&clip=true")!)) } } |