From 28419447891edb17101876fe9ca3c749b4802313 Mon Sep 17 00:00:00 2001 From: Hailey Date: Wed, 9 Oct 2024 15:29:25 -0700 Subject: Ensure app clip works even with `starter-pack` (#5664) --- modules/BlueskyClip/ViewController.swift | 44 ++++++++++++++++++---- .../StarterPack/StarterPackLandingScreen.tsx | 2 +- src/view/com/auth/SplashScreen.web.tsx | 14 +++++++ src/view/screens/Home.tsx | 39 ++++++++++++++----- 4 files changed, 81 insertions(+), 18 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")!)) } } diff --git a/src/screens/StarterPack/StarterPackLandingScreen.tsx b/src/screens/StarterPack/StarterPackLandingScreen.tsx index 68ff3aa7b..86ff5976e 100644 --- a/src/screens/StarterPack/StarterPackLandingScreen.tsx +++ b/src/screens/StarterPack/StarterPackLandingScreen.tsx @@ -356,7 +356,7 @@ function LandingScreenLoaded({ ) } -function AppClipOverlay({ +export function AppClipOverlay({ visible, setIsVisible, }: { diff --git a/src/view/com/auth/SplashScreen.web.tsx b/src/view/com/auth/SplashScreen.web.tsx index dee0d6b70..a850ea80a 100644 --- a/src/view/com/auth/SplashScreen.web.tsx +++ b/src/view/com/auth/SplashScreen.web.tsx @@ -9,6 +9,7 @@ import {useKawaiiMode} from '#/state/preferences/kawaii' import {ErrorBoundary} from '#/view/com/util/ErrorBoundary' import {Logo} from '#/view/icons/Logo' import {Logotype} from '#/view/icons/Logotype' +import {AppClipOverlay} from '#/screens/StarterPack/StarterPackLandingScreen' import {atoms as a, useTheme} from '#/alf' import {AppLanguageDropdown} from '#/components/AppLanguageDropdown' import {Button, ButtonText} from '#/components/Button' @@ -28,6 +29,15 @@ export const SplashScreen = ({ const {_} = useLingui() const t = useTheme() const {isTabletOrMobile: isMobileWeb} = useWebMediaQueries() + const [showClipOverlay, setShowClipOverlay] = React.useState(false) + + React.useEffect(() => { + const getParams = new URLSearchParams(window.location.search) + const clip = getParams.get('clip') + if (clip === 'true') { + setShowClipOverlay(true) + } + }, []) const kawaii = useKawaiiMode() @@ -119,6 +129,10 @@ export const SplashScreen = ({