From 9fde3957e76050a78c04509c84e5091f20975555 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Thu, 6 Mar 2025 00:01:17 +0000 Subject: [PATCH] ota helper in dev mode (#7911) --- src/screens/Settings/AboutSettings.tsx | 2 + src/screens/Settings/components/OTAInfo.tsx | 82 +++++++++++++++++++ .../Settings/components/OTAInfo.web.tsx | 3 + 3 files changed, 87 insertions(+) create mode 100644 src/screens/Settings/components/OTAInfo.tsx create mode 100644 src/screens/Settings/components/OTAInfo.web.tsx diff --git a/src/screens/Settings/AboutSettings.tsx b/src/screens/Settings/AboutSettings.tsx index 8b1b1f76d0..afae1096cb 100644 --- a/src/screens/Settings/AboutSettings.tsx +++ b/src/screens/Settings/AboutSettings.tsx @@ -17,6 +17,7 @@ import {Globe_Stroke2_Corner0_Rounded as GlobeIcon} from '#/components/icons/Glo import {Newspaper_Stroke2_Corner2_Rounded as NewspaperIcon} from '#/components/icons/Newspaper' import {Wrench_Stroke2_Corner2_Rounded as WrenchIcon} from '#/components/icons/Wrench' import * as Layout from '#/components/Layout' +import {OTAInfo} from './components/OTAInfo' type Props = NativeStackScreenProps export function AboutSettingsScreen({}: Props) { @@ -92,6 +93,7 @@ export function AboutSettingsScreen({}: Props) { {bundleInfo} + {devModeEnabled && } diff --git a/src/screens/Settings/components/OTAInfo.tsx b/src/screens/Settings/components/OTAInfo.tsx new file mode 100644 index 0000000000..ee63d150fe --- /dev/null +++ b/src/screens/Settings/components/OTAInfo.tsx @@ -0,0 +1,82 @@ +import * as Updates from 'expo-updates' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {useMutation, useQuery} from '@tanstack/react-query' + +import * as Toast from '#/view/com/util/Toast' +import {Button, ButtonIcon, ButtonText} from '#/components/Button' +import {ArrowRotateCounterClockwise_Stroke2_Corner0_Rounded as RetryIcon} from '#/components/icons/ArrowRotateCounterClockwise' +import {Shapes_Stroke2_Corner0_Rounded as ShapesIcon} from '#/components/icons/Shapes' +import {Loader} from '#/components/Loader' +import * as SettingsList from '../components/SettingsList' + +export function OTAInfo() { + const {_} = useLingui() + const { + data: isAvailable, + isPending: isPendingInfo, + isFetching: isFetchingInfo, + isError: isErrorInfo, + refetch, + } = useQuery({ + queryKey: ['ota-info'], + queryFn: async () => { + const status = await Updates.checkForUpdateAsync() + return status.isAvailable + }, + }) + + const {mutate: fetchAndLaunchUpdate, isPending: isPendingUpdate} = + useMutation({ + mutationFn: async () => { + await Updates.fetchUpdateAsync() + await Updates.reloadAsync() + }, + onError: error => + Toast.show(`Failed to update: ${error.message}`, 'xmark'), + }) + + if (!Updates.isEnabled || __DEV__) { + return null + } + + return ( + + + + {isAvailable ? ( + OTA status: Available! + ) : isErrorInfo ? ( + OTA status: Error fetching update + ) : isPendingInfo ? ( + OTA status: ... + ) : ( + OTA status: None available + )} + + + + ) +} diff --git a/src/screens/Settings/components/OTAInfo.web.tsx b/src/screens/Settings/components/OTAInfo.web.tsx new file mode 100644 index 0000000000..af6464ee62 --- /dev/null +++ b/src/screens/Settings/components/OTAInfo.web.tsx @@ -0,0 +1,3 @@ +export function OTAInfo() { + return null +}