From 8d039a3597231a1b8388e58a3d841cec2e13a63c Mon Sep 17 00:00:00 2001 From: Hailey Date: Thu, 24 Jul 2025 14:20:30 -0700 Subject: [PATCH] tweak to use intent --- src/lib/hooks/useIntentHandler.ts | 23 ++++++++++++-- src/lib/hooks/useOTAUpdates.ts | 8 ++--- src/screens/Settings/Settings.tsx | 53 ++++--------------------------- 3 files changed, 31 insertions(+), 53 deletions(-) diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts index 6b1083aa4b..a3ec054b3d 100644 --- a/src/lib/hooks/useIntentHandler.ts +++ b/src/lib/hooks/useIntentHandler.ts @@ -1,8 +1,9 @@ import React from 'react' +import {Alert} from 'react-native' import * as Linking from 'expo-linking' import {useOpenComposer} from '#/lib/hooks/useOpenComposer' -import {logEvent} from '#/lib/statsig/statsig' +import {logger} from '#/logger' import {isNative} from '#/platform/detection' import {useSession} from '#/state/session' import {useCloseAllActiveElements} from '#/state/util' @@ -12,8 +13,10 @@ import { } from '#/components/ageAssurance/AgeAssuranceRedirectDialog' import {useIntentDialogs} from '#/components/intents/IntentDialogs' import {Referrer} from '../../../modules/expo-bluesky-swiss-army' +import {IS_TESTFLIGHT} from '../app-info.web' +import {useApplyPullRequestOTAUpdate} from './useOTAUpdates' -type IntentType = 'compose' | 'verify-email' | 'age-assurance' +type IntentType = 'compose' | 'verify-email' | 'age-assurance' | 'apply-ota' const VALID_IMAGE_REGEX = /^[\w.:\-_/]+\|\d+(\.\d+)?\|\d+(\.\d+)?$/ @@ -27,12 +30,13 @@ export function useIntentHandler() { const ageAssuranceRedirectDialogControl = useAgeAssuranceRedirectDialogControl() const {currentAccount} = useSession() + const {tryApplyUpdate} = useApplyPullRequestOTAUpdate() React.useEffect(() => { const handleIncomingURL = (url: string) => { const referrerInfo = Referrer.getReferrerInfo() if (referrerInfo && referrerInfo.hostname !== 'bsky.app') { - logEvent('deepLink:referrerReceived', { + logger.metric('deepLink:referrerReceived', { to: url, referrer: referrerInfo?.referrer, hostname: referrerInfo?.hostname, @@ -92,6 +96,18 @@ export function useIntentHandler() { } return } + case 'apply-ota': { + if (!IS_TESTFLIGHT) { + return + } + + const channel = params.get('channel') + if (!channel) { + Alert.alert('Error', 'No channel provided to look for.') + } else { + tryApplyUpdate(channel) + } + } default: { return } @@ -111,6 +127,7 @@ export function useIntentHandler() { verifyEmailIntent, ageAssuranceRedirectDialogControl, currentAccount, + tryApplyUpdate, ]) } diff --git a/src/lib/hooks/useOTAUpdates.ts b/src/lib/hooks/useOTAUpdates.ts index f679ee3db4..a57816f36e 100644 --- a/src/lib/hooks/useOTAUpdates.ts +++ b/src/lib/hooks/useOTAUpdates.ts @@ -73,7 +73,7 @@ export function useApplyPullRequestOTAUpdate() { const isCurrentlyRunningPullRequestDeployment = currentChannel?.startsWith('pull-request') - const onTryApplyUpdate = async (channel: string) => { + const tryApplyUpdate = async (channel: string) => { setPending(true) if (currentChannel === channel) { const res = await checkForUpdateAsync() @@ -134,7 +134,7 @@ export function useApplyPullRequestOTAUpdate() { setPending(false) } - const onRevertToEmbedded = async () => { + const revertToEmbedded = async () => { try { await updateTestflight() } catch (e: any) { @@ -143,8 +143,8 @@ export function useApplyPullRequestOTAUpdate() { } return { - onTryApplyUpdate, - onRevertToEmbedded, + tryApplyUpdate, + revertToEmbedded, currentChannel, isCurrentlyRunningPullRequestDeployment, pending, diff --git a/src/screens/Settings/Settings.tsx b/src/screens/Settings/Settings.tsx index 5d20aeffd5..9596c24794 100644 --- a/src/screens/Settings/Settings.tsx +++ b/src/screens/Settings/Settings.tsx @@ -1,5 +1,5 @@ import {useState} from 'react' -import {Alert, LayoutAnimation, Pressable, View} from 'react-native' +import {LayoutAnimation, Pressable, View} from 'react-native' import {Linking} from 'react-native' import {useReducedMotion} from 'react-native-reanimated' import {type AppBskyActorDefs, moderateProfile} from '@atproto/api' @@ -366,6 +366,11 @@ function DevOptions() { const onboardingDispatch = useOnboardingDispatch() const navigation = useNavigation() const {mutate: deleteChatDeclarationRecord} = useDeleteActorDeclaration() + const { + revertToEmbedded, + isCurrentlyRunningPullRequestDeployment, + currentChannel, + } = useApplyPullRequestOTAUpdate() const [actyNotifNudged, setActyNotifNudged] = useActivitySubscriptionsNudged() const resetOnboarding = async () => { @@ -394,41 +399,6 @@ function DevOptions() { setActyNotifNudged(false) } - const { - onTryApplyUpdate, - onRevertToEmbedded, - isCurrentlyRunningPullRequestDeployment, - currentChannel, - } = useApplyPullRequestOTAUpdate() - - const onPressApplyPullRequest = async () => { - Alert.prompt( - 'Apply Pull Request', - "Enter a channel name below to apply a pull request. Channel names usually look like 'pull-request-'", - [ - { - text: 'Cancel', - style: 'cancel', - }, - { - text: 'Apply', - style: 'default', - onPress: async channel => { - if (!channel) { - Alert.alert('Error', 'No channel provided to look for.') - return - } - await onTryApplyUpdate(channel ?? '') - }, - }, - ], - 'plain-text', - isCurrentlyRunningPullRequestDeployment - ? currentChannel - : 'pull-request-', - ) - } - return ( <> Clear all storage data (restart after this) - {isNative ? ( - - - Apply Pull Request - - - ) : null} {isNative && isCurrentlyRunningPullRequestDeployment ? ( Unapply Pull Request {currentChannel}