Bluesky app fork with some witchin' additions 💫

ota helper in dev mode (#7911)

authored by samuel.fm and committed by

GitHub 9fde3957 dae152da

+87
+2
src/screens/Settings/AboutSettings.tsx
··· 17 17 import {Newspaper_Stroke2_Corner2_Rounded as NewspaperIcon} from '#/components/icons/Newspaper' 18 18 import {Wrench_Stroke2_Corner2_Rounded as WrenchIcon} from '#/components/icons/Wrench' 19 19 import * as Layout from '#/components/Layout' 20 + import {OTAInfo} from './components/OTAInfo' 20 21 21 22 type Props = NativeStackScreenProps<CommonNavigatorParams, 'AboutSettings'> 22 23 export function AboutSettingsScreen({}: Props) { ··· 92 93 </SettingsList.ItemText> 93 94 <SettingsList.BadgeText>{bundleInfo}</SettingsList.BadgeText> 94 95 </SettingsList.PressableItem> 96 + {devModeEnabled && <OTAInfo />} 95 97 </SettingsList.Container> 96 98 </Layout.Content> 97 99 </Layout.Screen>
+82
src/screens/Settings/components/OTAInfo.tsx
··· 1 + import * as Updates from 'expo-updates' 2 + import {msg, Trans} from '@lingui/macro' 3 + import {useLingui} from '@lingui/react' 4 + import {useMutation, useQuery} from '@tanstack/react-query' 5 + 6 + import * as Toast from '#/view/com/util/Toast' 7 + import {Button, ButtonIcon, ButtonText} from '#/components/Button' 8 + import {ArrowRotateCounterClockwise_Stroke2_Corner0_Rounded as RetryIcon} from '#/components/icons/ArrowRotateCounterClockwise' 9 + import {Shapes_Stroke2_Corner0_Rounded as ShapesIcon} from '#/components/icons/Shapes' 10 + import {Loader} from '#/components/Loader' 11 + import * as SettingsList from '../components/SettingsList' 12 + 13 + export function OTAInfo() { 14 + const {_} = useLingui() 15 + const { 16 + data: isAvailable, 17 + isPending: isPendingInfo, 18 + isFetching: isFetchingInfo, 19 + isError: isErrorInfo, 20 + refetch, 21 + } = useQuery({ 22 + queryKey: ['ota-info'], 23 + queryFn: async () => { 24 + const status = await Updates.checkForUpdateAsync() 25 + return status.isAvailable 26 + }, 27 + }) 28 + 29 + const {mutate: fetchAndLaunchUpdate, isPending: isPendingUpdate} = 30 + useMutation({ 31 + mutationFn: async () => { 32 + await Updates.fetchUpdateAsync() 33 + await Updates.reloadAsync() 34 + }, 35 + onError: error => 36 + Toast.show(`Failed to update: ${error.message}`, 'xmark'), 37 + }) 38 + 39 + if (!Updates.isEnabled || __DEV__) { 40 + return null 41 + } 42 + 43 + return ( 44 + <SettingsList.Item> 45 + <SettingsList.ItemIcon icon={ShapesIcon} /> 46 + <SettingsList.ItemText> 47 + {isAvailable ? ( 48 + <Trans>OTA status: Available!</Trans> 49 + ) : isErrorInfo ? ( 50 + <Trans>OTA status: Error fetching update</Trans> 51 + ) : isPendingInfo ? ( 52 + <Trans>OTA status: ...</Trans> 53 + ) : ( 54 + <Trans>OTA status: None available</Trans> 55 + )} 56 + </SettingsList.ItemText> 57 + <Button 58 + label={isAvailable ? _(msg`Update`) : _(msg`Fetch update`)} 59 + disabled={isFetchingInfo || isPendingUpdate} 60 + variant="solid" 61 + size="small" 62 + color={isAvailable ? 'primary' : 'secondary_inverted'} 63 + onPress={() => { 64 + if (isFetchingInfo || isPendingUpdate) return 65 + 66 + if (isAvailable) { 67 + fetchAndLaunchUpdate() 68 + } else { 69 + refetch() 70 + } 71 + }}> 72 + {isAvailable ? ( 73 + <ButtonText> 74 + <Trans>Update</Trans> 75 + </ButtonText> 76 + ) : ( 77 + <ButtonIcon icon={isFetchingInfo ? Loader : RetryIcon} /> 78 + )} 79 + </Button> 80 + </SettingsList.Item> 81 + ) 82 + }
+3
src/screens/Settings/components/OTAInfo.web.tsx
··· 1 + export function OTAInfo() { 2 + return null 3 + }