diff --git a/src/lib/hooks/useUpdateCheck.ts b/src/lib/hooks/useUpdateCheck.ts index bb8ef56331..5ae93c913b 100644 --- a/src/lib/hooks/useUpdateCheck.ts +++ b/src/lib/hooks/useUpdateCheck.ts @@ -1,10 +1,11 @@ import React from 'react' import {Alert, AppState, AppStateStatus} from 'react-native' +import app from 'react-native-version-number' import * as Updates from 'expo-updates' import {useUpdates} from 'expo-updates' + import {logger} from '#/logger' import {IS_TESTFLIGHT} from '#/env' -import app from 'react-native-version-number' export function useUpdateCheck() { const appState = React.useRef('active') @@ -16,10 +17,12 @@ export function useUpdateCheck() { const setCheckTimeout = React.useCallback(() => { timeout.current = setTimeout(async () => { try { + Alert.alert('Try') await Updates.setExtraParamAsync( 'buildNumber', app.buildVersion.toString(), ) + Alert.alert('Here') await Updates.setExtraParamAsync( 'channel', IS_TESTFLIGHT ? 'testflight' : 'production', @@ -42,58 +45,62 @@ export function useUpdateCheck() { }, 15e3) }, []) + const onIsTestFlight = React.useCallback(() => { + setTimeout(async () => { + await Updates.setExtraParamAsync( + 'buildNumber', + app.buildVersion.toString(), + ) + await Updates.setExtraParamAsync( + 'channel', + IS_TESTFLIGHT ? 'testflight' : 'production', + ) + + const res = await Updates.checkForUpdateAsync() + console.log(res) + if (res.isAvailable) { + await Updates.fetchUpdateAsync() + + Alert.alert( + 'Update Available', + 'A new version of the app is available. Relaunch now?', + [ + { + text: 'No', + style: 'cancel', + }, + { + text: 'Relaunch', + style: 'default', + onPress: async () => { + await Updates.reloadAsync() + }, + }, + ], + ) + } else { + Alert.alert('No Update Available', 'No update available at this time.') + } + }, 3000) + }, []) + React.useEffect(() => { // For Testflight users, we can prompt the user to update immediately whenever there's an available update. This // is suspect however with the Apple App Store guidelines, so we don't want to prompt production users to update // immediately. - if (IS_TESTFLIGHT) { - ;(async () => { - await Updates.setExtraParamAsync( - 'buildNumber', - app.buildVersion.toString(), - ) - await Updates.setExtraParamAsync( - 'channel', - IS_TESTFLIGHT ? 'testflight' : 'production', - ) - - const res = await Updates.checkForUpdateAsync() - if (res.isAvailable) { - await Updates.fetchUpdateAsync() - Alert.alert( - 'Update Available', - 'A new version of the app is available. Relaunch now?', - [ - { - text: 'No', - style: 'cancel', - }, - { - text: 'Relaunch', - style: 'default', - onPress: async () => { - await Updates.reloadAsync() - }, - }, - ], - ) - } else { - Alert.alert( - 'No Update Available', - 'No update available at this time.', - ) - } - })() + if (IS_TESTFLIGHT) { + onIsTestFlight() return - } - if (__DEV__ || ranInitialCheck.current) { + } else if (__DEV__ || ranInitialCheck.current) { return + } else { + Alert.alert('not testfight') } setCheckTimeout() ranInitialCheck.current = true - }, [setCheckTimeout]) + }, [onIsTestFlight, setCheckTimeout]) // After the app has been minimized for 30 minutes, we want to either A. install an update if one has become available // or B check for an update again.