Skip to content

Commit

Permalink
show clip overlay on splash if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok committed Oct 9, 2024
1 parent 2a23a88 commit db89f79
Showing 1 changed file with 35 additions and 7 deletions.
42 changes: 35 additions & 7 deletions modules/BlueskyClip/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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" || url.pathComponents[1] == "starter-pack") {
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")!))
}
}

Expand Down

0 comments on commit db89f79

Please sign in to comment.