Skip to content

Commit e5691e2

Browse files
committed
Add version checking.
1 parent 2906360 commit e5691e2

File tree

16 files changed

+224
-164
lines changed

16 files changed

+224
-164
lines changed

App.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Test from '@screens/Test'
3131
import RandomColor from '@screens/Try/RandomColor'
3232
import RandomPassword from '@screens/Try/RandomPassword'
3333
import YourAge from '@screens/Try/YourAge'
34-
import ForceUpdate, { type ForceUpdateParamList } from '@screens/Update/ForceUpdate'
3534
import Update, { type UpdateParamList } from '@screens/Update/Update'
3635
import type { ConfirmCityParamList } from '@screens/Weather/ConfirmCity'
3736
import { type WeatherLocationParamList } from '@screens/Weather/WeatherLocation'
@@ -135,7 +134,6 @@ export type RootStackParamList = {
135134
RandomPassword: undefined
136135
GlobalSearch: undefined
137136
Update: UpdateParamList
138-
ForceUpdate: ForceUpdateParamList
139137
Splash: undefined
140138
Login: undefined
141139
Signup: undefined
@@ -224,7 +222,7 @@ function Navigation() {
224222
<Stack.Screen name='RandomPassword' component={RandomPassword} options={GestureEnabled} />
225223
<Stack.Screen name='GlobalSearch' component={GlobalSearch} options={IOS_BOTTOM_STYLE} />
226224
<Stack.Screen name='Update' component={Update} options={IOS_BOTTOM_STYLE} />
227-
<Stack.Screen name='ForceUpdate' component={ForceUpdate} options={GestureEnabled} />
225+
{/* <Stack.Screen name='ForceUpdate' component={Update} options={GestureEnabled} /> */}
228226
<Stack.Screen name='Devices' component={Devices} options={GestureEnabled} />
229227
<Stack.Screen name='Device' component={Device} options={GestureEnabled} />
230228
</Stack.Navigator>

src/assets/icons/icons.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,4 @@ export { default as Tick01SolidIcon } from '@icons/tick-01-solid-rounded.svg'
128128
export { default as WindowsOldSolidIcon } from '@icons/windows-old-solid-rounded.svg'
129129
export { default as AppleSolidIcon } from '@icons/apple-solid-rounded.svg'
130130
export { default as ChromeSolidIcon } from '@icons/chrome-solid-rounded.svg'
131+
export { default as SquareArrowUp02SolidIcon } from '@icons/square-arrow-up-02-solid-rounded.svg'
Lines changed: 3 additions & 0 deletions
Loading

src/rpc/hcWithType.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ declare const client: {
1111
date: any;
1212
forceUpdate: any;
1313
features: any;
14+
versionCode: any;
15+
size: any;
1416
};
1517
};
1618
outputFormat: "json";

src/screens/Home/CheckVersion.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import versionStore from '@/zustand/versionStore'
2+
import { useQuery } from '@tanstack/react-query'
3+
import { client } from '@utils/client'
4+
import { APP_VERSION_CODE } from '@utils/constants'
5+
import type { NavProp } from '@utils/types'
6+
import { useEffect } from 'react'
7+
8+
export default function CheckVersion({ navigation }: NavProp) {
9+
const { data } = useQuery({
10+
queryKey: ['checkVersion'],
11+
queryFn: async () => await (await client.api.version.$get()).json(),
12+
})
13+
14+
const setVersion = versionStore((state) => state.setVersion)
15+
16+
useEffect(() => {
17+
if (data && data.status) {
18+
const isNew = APP_VERSION_CODE < data.data?.versionCode
19+
setVersion({
20+
features: data.data?.features,
21+
forceUpdate: data.data?.forceUpdate,
22+
size: data.data?.size,
23+
version: data.data?.version,
24+
versionCode: data.data?.versionCode,
25+
})
26+
if (isNew) {
27+
console.log('New Version Available')
28+
if (data.data?.forceUpdate) {
29+
console.log('Force Update')
30+
navigation.reset({
31+
index: 0,
32+
routes: [{ name: 'Update', params: data.data }],
33+
})
34+
} else {
35+
console.log('Update Available')
36+
}
37+
}
38+
}
39+
}, [data, navigation, setVersion])
40+
41+
return null
42+
}

src/screens/Home/Greeting.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import Btn from '@components/Button'
33
import Feature from '@components/Feature'
44
import { PaddingBottom } from '@components/SafePadding'
55
import { Colors } from '@utils/colors'
6-
import { APP_VERSION } from '@utils/data'
7-
import { Bold, Medium, PoppinsMedium, SemiBold } from '@utils/fonts'
6+
import { APP_VERSION } from '@utils/constants'
7+
import { Bold, Medium, SemiBold } from '@utils/fonts'
88
import type { NavProp } from '@utils/types'
99
import { getLocalDate, greetingByTime } from '@utils/utils'
1010
import React from 'react'
11-
import { StatusBar, Text, View } from 'react-native'
11+
import { StatusBar, View } from 'react-native'
1212
import { ScrollView } from 'react-native-gesture-handler'
1313

1414
export default function Greeting({ navigation }: NavProp) {

src/screens/Home/HomeScreen.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,12 @@ import type { StackNav } from '@utils/types'
1010
import React, { useEffect, useMemo } from 'react'
1111
import { Dimensions, Text, TouchableOpacity, View } from 'react-native'
1212
import { ScrollView } from 'react-native-gesture-handler'
13+
import CheckVersion from './CheckVersion'
1314
import styles, { hw as height_weight } from './style'
1415

1516
const { width } = Dimensions.get('window')
1617

1718
export default function HomeScreen({ navigation }: { navigation: StackNav }) {
18-
// useEffect(() => {
19-
// setTimeout(() => {
20-
// navigation.navigate('Update', {
21-
// version: '1.0.0',
22-
// size: '10MB',
23-
// whatsNew: ['New Features', 'Bug Fixes'],
24-
// })
25-
// }, 1000)
26-
// }, [navigation])
27-
2819
const setUser = profileStore((state) => state.setUser)
2920

3021
const { mutate } = useMutation({
@@ -45,6 +36,7 @@ export default function HomeScreen({ navigation }: { navigation: StackNav }) {
4536
<>
4637
<View className='bg-zinc-50 px-5 pt-1 dark:bg-black'>
4738
<PaddingTop />
39+
<CheckVersion navigation={navigation} />
4840
</View>
4941
<ScrollView className='flex-1 bg-zinc-50 dark:bg-black' showsVerticalScrollIndicator={false}>
5042
<View style={{ gap: 10 }} className='pb-10'>

src/screens/Settings/Extra/About.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import AppIconRound from '@assets/icons/icon_round.svg'
22
import { useQuery } from '@tanstack/react-query'
33
import { client } from '@utils/client'
4-
// import { client } from '@utils/client'
5-
import { APP_VERSION } from '@utils/data'
4+
import { APP_VERSION } from '@utils/constants'
65
import { SemiBold } from '@utils/fonts'
76
import React from 'react'
87
import { View } from 'react-native'

src/screens/Settings/Settings.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { devOptStore } from '@/zustand/devOptStore'
22
import profileStore from '@/zustand/profileStore'
3+
import versionStore from '@/zustand/versionStore'
34
import {
45
BrushSolidIcon,
56
BubbleChatSolidIcon,
@@ -15,27 +16,30 @@ import {
1516
Logout02SolidIcon,
1617
PolicySolidIcon,
1718
ShieldUserSolidIcon,
19+
SquareArrowUp02SolidIcon,
1820
SquareLock02SolidIcon,
1921
TelegramSolidIcon,
2022
UserSolidIcon,
2123
Wallet02SolidIcon,
2224
} from '@assets/icons/icons'
2325
import { Gap12, Gap20 } from '@components/Gap'
2426
import RoundedIcon from '@components/RoundedIcon'
27+
import RoundNotification from '@components/RoundNotification'
2528
import { PaddingBottom, PaddingTop } from '@components/SafePadding'
2629
import Search from '@components/Search'
2730
import { SettGroup, SettOption, SettText } from '@components/Settings'
28-
import { TxtAcc } from '@components/Text'
31+
import { Txt, TxtAcc } from '@components/Text'
2932
import { useIsFocused } from '@react-navigation/native'
3033
import { Colors } from '@utils/colors'
31-
import { APP_VERSION, APP_VERSION_CODE, ask_a_question, join_telegram_channel } from '@utils/data'
34+
import { APP_VERSION, APP_VERSION_CODE, ask_a_question, join_telegram_channel } from '@utils/constants'
3235
import { Bold } from '@utils/fonts'
3336
import { Caches, clearStorage, getStartWithSize, getStorageSize } from '@utils/storage'
3437
import type { NavProp } from '@utils/types'
3538
import { screenDelay, toReadableSize } from '@utils/utils'
3639
import React, { useEffect } from 'react'
3740
import { useColorScheme, View } from 'react-native'
3841
import { ScrollView } from 'react-native-gesture-handler'
42+
import Animated, { FadeIn } from 'react-native-reanimated'
3943
// function getTransparentCardStyle(scheme: ColorSchemeName) {
4044
// return scheme === 'dark' ? 'aa' : '77'
4145
// }
@@ -92,6 +96,7 @@ export default function Settings({ navigation }: NavProp) {
9296
Hello {user?.name.split(' ')[0]}, Go to each section to customize your experience. All settings are saved
9397
automatically.
9498
</SettText>
99+
<UpdateSettings navigation={navigation} />
95100
<SettGroup title='General'>
96101
{/* <SettOption
97102
title='App Update'
@@ -284,3 +289,26 @@ function AdminSettings({ navigation }: NavProp) {
284289
</Gap12>
285290
)
286291
}
292+
293+
function UpdateSettings({ navigation }: NavProp) {
294+
const version = versionStore((state) => state.version)
295+
const isNew = version ? APP_VERSION_CODE < version.versionCode : false
296+
297+
if (!isNew) return null
298+
299+
return (
300+
<Gap12>
301+
<Animated.View entering={FadeIn}>
302+
<SettGroup>
303+
<SettOption
304+
title={isNew ? 'Update available' : 'Check for updates'}
305+
Icon={<RoundedIcon Icon={SquareArrowUp02SolidIcon} />}
306+
arrow
307+
onPress={() => version && navigation.navigate('Update', { shouldGoBack: true })}
308+
Right={isNew ? <RoundNotification n={1} /> : <Txt>{`v${APP_VERSION}`}</Txt>}
309+
/>
310+
</SettGroup>
311+
</Animated.View>
312+
</Gap12>
313+
)
314+
}

src/screens/Update/Components/UpdateAvailableUI.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import Animated, { Easing, useAnimatedStyle, useSharedValue, withRepeat, withTim
77
export default function UpdateAvailableUI({
88
version,
99
size,
10-
whatsNew,
10+
features,
1111
}: {
1212
version: string
1313
size: string
14-
whatsNew: Array<string>
14+
features: Array<string>
1515
}) {
1616
const rotate = useSharedValue(0)
1717

@@ -45,7 +45,7 @@ export default function UpdateAvailableUI({
4545
latest.
4646
</Regular>
4747
<View className='mt-5' style={{ gap: 5 }}>
48-
{whatsNew.map((item, index) => (
48+
{features.map((item, index) => (
4949
<Regular key={index} className='text-white opacity-80' style={{ fontSize: 11 }}>
5050
{' '}
5151
{item}

0 commit comments

Comments
 (0)