From af124cc8b88f8bbccb290539efea4935153b38e9 Mon Sep 17 00:00:00 2001 From: Hailey Date: Sun, 16 Jun 2024 21:24:50 -0700 Subject: [PATCH] add android handling --- src/lib/browser.native.ts | 1 + src/lib/browser.ts | 2 + .../StarterPack/StarterPackLandingScreen.tsx | 60 +++++++++++++++---- src/state/persisted/schema.ts | 1 - src/state/preferences/starter-pack.tsx | 1 - 5 files changed, 50 insertions(+), 15 deletions(-) diff --git a/src/lib/browser.native.ts b/src/lib/browser.native.ts index fb9be56f10..8e045138c8 100644 --- a/src/lib/browser.native.ts +++ b/src/lib/browser.native.ts @@ -1,3 +1,4 @@ export const isSafari = false export const isFirefox = false export const isTouchDevice = true +export const isAndroidWeb = false diff --git a/src/lib/browser.ts b/src/lib/browser.ts index d178a9a64e..08c43fbfdf 100644 --- a/src/lib/browser.ts +++ b/src/lib/browser.ts @@ -5,3 +5,5 @@ export const isSafari = /^((?!chrome|android).)*safari/i.test( export const isFirefox = /firefox|fxios/i.test(navigator.userAgent) export const isTouchDevice = 'ontouchstart' in window || navigator.maxTouchPoints > 1 +export const isAndroidWeb = + /android/i.test(navigator.userAgent) && isTouchDevice diff --git a/src/screens/StarterPack/StarterPackLandingScreen.tsx b/src/screens/StarterPack/StarterPackLandingScreen.tsx index 2b4b3bd290..3ced61fa25 100644 --- a/src/screens/StarterPack/StarterPackLandingScreen.tsx +++ b/src/screens/StarterPack/StarterPackLandingScreen.tsx @@ -5,6 +5,7 @@ import {AppBskyGraphDefs, AppBskyGraphStarterpack} from '@atproto/api' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' +import {isAndroidWeb} from 'lib/browser' import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' import { useSetUsedStarterPack, @@ -17,15 +18,27 @@ import {CenteredView} from 'view/com/util/Views' import {Logo} from 'view/icons/Logo' import {atoms as a, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' +import {useDialogControl} from '#/components/Dialog' import {Divider} from '#/components/Divider' import * as FeedCard from '#/components/FeedCard' import {LinearGradientBackground} from '#/components/LinearGradientBackground' import {ListMaybePlaceholder} from '#/components/Lists' import {Default as ProfileCardInner} from '#/components/ProfileCard' +import * as Prompt from '#/components/Prompt' import {Text} from '#/components/Typography' const AnimatedPressable = Animated.createAnimatedComponent(Pressable) +interface AppClipMessage { + action: 'present' | 'store' + keyToStoreAs?: string + jsonToStore?: string +} + +function postAppClipMessage(message: AppClipMessage) { + window.webkit.messageHandlers.onMessage.postMessage(JSON.stringify(message)) +} + function parseStarterPackHttpUri(uri: string): {name?: string; rkey?: string} { const parsed = new URL(uri) const [_, _path, name, rkey] = parsed.pathname.split('/') @@ -35,14 +48,8 @@ function parseStarterPackHttpUri(uri: string): {name?: string; rkey?: string} { } } -interface AppClipMessage { - action: 'present' | 'store' - keyToStoreAs?: string - jsonToStore?: string -} - -function postAppClipMessage(message: AppClipMessage) { - window.webkit.messageHandlers.onMessage.postMessage(JSON.stringify(message)) +function createGooglePlayLink(name: string, rkey: string) { + return `https://play.google.com/store/apps/details?id=xyz.blueskyweb.app&referrer=utm_source%3Dbluesky%26utm_medium%3Dstarterpack%26utm_content%3Dstarterpack-${name}-${rkey}` } export function LandingScreen({ @@ -104,24 +111,30 @@ function LandingScreenInner({ const setUsedStarterPack = useSetUsedStarterPack() const usedStarterPack = useUsedStarterPack() const {isTabletOrDesktop} = useWebMediaQueries() + const androidDialogControl = useDialogControl() const [appClipOverlayVisible, setAppClipOverlayVisible] = React.useState(false) const listItemsCount = starterPack.list?.listItemCount ?? 0 + const onContinue = () => { + setUsedStarterPack({ + uri: starterPack.uri, + }) + setScreenState(LoggedOutScreenState.S_CreateAccount) + } + const onJoinPress = () => { if (usedStarterPack?.isClip) { setAppClipOverlayVisible(true) postAppClipMessage({ action: 'present', }) + } else if (isAndroidWeb) { + androidDialogControl.open() } else { - setUsedStarterPack({ - uri: starterPack.uri, - cid: starterPack.cid, - }) - setScreenState(LoggedOutScreenState.S_CreateAccount) + onContinue() } } @@ -275,6 +288,27 @@ function LandingScreenInner({ visible={appClipOverlayVisible} setIsVisible={setAppClipOverlayVisible} /> + + + + + + { + const rkey = parseStarterPackHttpUri(starterPack.uri).rkey + if (!rkey) return + + window.location.href = createGooglePlayLink(creator.handle, rkey) + }} + /> + + ) } diff --git a/src/state/persisted/schema.ts b/src/state/persisted/schema.ts index 90d71e7242..ba282f2748 100644 --- a/src/state/persisted/schema.ts +++ b/src/state/persisted/schema.ts @@ -91,7 +91,6 @@ export const schema = z.object({ usedStarterPack: z .object({ uri: z.string(), - cid: z.string().optional(), initialFeed: z.string().optional(), isClip: z.boolean().optional(), lastUsedUri: z.string().optional(), diff --git a/src/state/preferences/starter-pack.tsx b/src/state/preferences/starter-pack.tsx index 7099845a32..f237838570 100644 --- a/src/state/preferences/starter-pack.tsx +++ b/src/state/preferences/starter-pack.tsx @@ -5,7 +5,6 @@ import * as persisted from '#/state/persisted' type StateContext = | { uri: string - cid?: string initialFeed?: string isClip?: boolean lastUsedUri?: string