|
@@ -1,5 +1,12 @@
|
|
|
|
|
+import { AnimatedSplashOverlay } from '@/components/animated-icon';
|
|
|
|
|
+import { antdTheme } from '@/constants/antd-theme';
|
|
|
|
|
+import { Colors } from '@/constants/theme';
|
|
|
import '@/global.css';
|
|
import '@/global.css';
|
|
|
|
|
+import api from '@/utils/api';
|
|
|
|
|
+import { AuthProvider } from '@/utils/auth';
|
|
|
|
|
+import { getGlobalStorage } from '@/utils/storage';
|
|
|
import { Modal, Provider, Toast } from '@ant-design/react-native';
|
|
import { Modal, Provider, Toast } from '@ant-design/react-native';
|
|
|
|
|
+import type { Theme } from '@react-navigation/native';
|
|
|
import {
|
|
import {
|
|
|
DefaultTheme as ReactNavigationDefaultTheme,
|
|
DefaultTheme as ReactNavigationDefaultTheme,
|
|
|
ThemeProvider,
|
|
ThemeProvider,
|
|
@@ -12,13 +19,6 @@ import * as SplashScreen from 'expo-splash-screen';
|
|
|
import * as updates from 'expo-updates';
|
|
import * as updates from 'expo-updates';
|
|
|
import { useEffect, useState } from 'react';
|
|
import { useEffect, useState } from 'react';
|
|
|
import { Linking, Platform, View } from 'react-native';
|
|
import { Linking, Platform, View } from 'react-native';
|
|
|
-import { AnimatedSplashOverlay } from '@/components/animated-icon';
|
|
|
|
|
-import { antdTheme } from '@/constants/antd-theme';
|
|
|
|
|
-import { Colors } from '@/constants/theme';
|
|
|
|
|
-import api from '@/utils/api';
|
|
|
|
|
-import { AuthProvider } from '@/utils/auth';
|
|
|
|
|
-import { getGlobalStorage } from '@/utils/storage';
|
|
|
|
|
-import type { Theme } from '@react-navigation/native';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SplashScreen.preventAutoHideAsync();
|
|
SplashScreen.preventAutoHideAsync();
|
|
@@ -39,7 +39,7 @@ export const DefaultTheme: Theme = {
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function RootLayout() {
|
|
export default function RootLayout() {
|
|
|
- const [initializing, setIniting] = useState(true);
|
|
|
|
|
|
|
+ const [initializing, setInitlizing] = useState(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
// const colorScheme = useColorScheme();
|
|
// const colorScheme = useColorScheme();
|
|
@@ -54,8 +54,7 @@ export default function RootLayout() {
|
|
|
try {
|
|
try {
|
|
|
const lastTime = parseInt(getGlobalStorage().getString('last_update_app') || '0');
|
|
const lastTime = parseInt(getGlobalStorage().getString('last_update_app') || '0');
|
|
|
if (now - lastTime < 15 * 60000) {
|
|
if (now - lastTime < 15 * 60000) {
|
|
|
- SplashScreen.hide();
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
const {
|
|
const {
|
|
|
version,
|
|
version,
|
|
@@ -67,10 +66,8 @@ export default function RootLayout() {
|
|
|
version: application.nativeApplicationVersion,
|
|
version: application.nativeApplicationVersion,
|
|
|
}, { timeout: 5000 });
|
|
}, { timeout: 5000 });
|
|
|
getGlobalStorage().set('last_update_app', now);
|
|
getGlobalStorage().set('last_update_app', now);
|
|
|
-
|
|
|
|
|
- SplashScreen.hide();
|
|
|
|
|
if (!version || version === application.nativeApplicationVersion) {
|
|
if (!version || version === application.nativeApplicationVersion) {
|
|
|
- return true;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
const va = version.split('.');
|
|
const va = version.split('.');
|
|
|
let vb = (application.nativeApplicationVersion || '').split('.');
|
|
let vb = (application.nativeApplicationVersion || '').split('.');
|
|
@@ -82,8 +79,9 @@ export default function RootLayout() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
if (!update) {
|
|
if (!update) {
|
|
|
- return true;
|
|
|
|
|
|
|
+ return;
|
|
|
}
|
|
}
|
|
|
|
|
+ SplashScreen.hide();
|
|
|
let ok = true;
|
|
let ok = true;
|
|
|
do {
|
|
do {
|
|
|
ok = await new Promise<boolean>((resolve, reject) => {
|
|
ok = await new Promise<boolean>((resolve, reject) => {
|
|
@@ -95,15 +93,16 @@ export default function RootLayout() {
|
|
|
if (pkg) {
|
|
if (pkg) {
|
|
|
if (await Linking.canOpenURL(pkg)) {
|
|
if (await Linking.canOpenURL(pkg)) {
|
|
|
Linking.openURL(pkg);
|
|
Linking.openURL(pkg);
|
|
|
- resolve(false);
|
|
|
|
|
|
|
+ resolve(true);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
Modal.alert('无法自动更新', "请前往应用商店更新");
|
|
Modal.alert('无法自动更新', "请前往应用商店更新");
|
|
|
- resolve(true);
|
|
|
|
|
|
|
+ resolve(false);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- resolve(true);
|
|
|
|
|
|
|
+ // todo other
|
|
|
|
|
+ resolve(false);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
];
|
|
];
|
|
@@ -119,55 +118,56 @@ export default function RootLayout() {
|
|
|
Modal.alert(`${version}可更新`, force ? '请更新后继续使用' : '是否立即更新?', actions);
|
|
Modal.alert(`${version}可更新`, force ? '请更新后继续使用' : '是否立即更新?', actions);
|
|
|
});
|
|
});
|
|
|
} while (!ok);
|
|
} while (!ok);
|
|
|
- return true;
|
|
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
-
|
|
|
|
|
- SplashScreen.hide();
|
|
|
|
|
console.warn(e);
|
|
console.warn(e);
|
|
|
- return true;
|
|
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
(async () => {
|
|
(async () => {
|
|
|
if (__DEV__) {
|
|
if (__DEV__) {
|
|
|
- setIniting(false);
|
|
|
|
|
|
|
+ setInitlizing(false);
|
|
|
SplashScreen.hide();
|
|
SplashScreen.hide();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- if (!await checkApp()) {
|
|
|
|
|
- setIniting(false);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
-
|
|
|
|
|
- const res = await updates.checkForUpdateAsync();
|
|
|
|
|
- // alert(JSON.stringify(res))
|
|
|
|
|
- if (res.isAvailable) {
|
|
|
|
|
-
|
|
|
|
|
- Modal.alert("发现热更新", "需要立即下载", [
|
|
|
|
|
- {
|
|
|
|
|
- text: '确认',
|
|
|
|
|
- onPress: async () => {
|
|
|
|
|
- const l = Toast.loading("正在下载更新 ...");
|
|
|
|
|
- try {
|
|
|
|
|
- await updates.fetchUpdateAsync();
|
|
|
|
|
- await updates.reloadAsync();
|
|
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- Modal.alert("提示", "更新遇到问题");
|
|
|
|
|
|
|
+ await checkApp();
|
|
|
|
|
+ SplashScreen.hide();
|
|
|
|
|
+
|
|
|
|
|
+ while (true) {
|
|
|
|
|
+ let res = await new Promise<string|void>(async (resolve, reject) => {
|
|
|
|
|
+ const res = await updates.checkForUpdateAsync();
|
|
|
|
|
+ if (res.isAvailable) {
|
|
|
|
|
+
|
|
|
|
|
+ Modal.alert("发现热更新", "需要立即下载", [
|
|
|
|
|
+ {
|
|
|
|
|
+ text: '确认',
|
|
|
|
|
+ onPress: async () => {
|
|
|
|
|
+ const l = Toast.loading("正在下载更新 ...");
|
|
|
|
|
+ try {
|
|
|
|
|
+ await updates.fetchUpdateAsync();
|
|
|
|
|
+ Toast.remove(l);
|
|
|
|
|
+ await updates.reloadAsync();
|
|
|
|
|
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
|
+ } catch (e) {
|
|
|
|
|
+ Toast.remove(l);
|
|
|
|
|
+ Modal.alert("提示", "更新遇到问题", [{
|
|
|
|
|
+ text: '确认',
|
|
|
|
|
+ onPress: resolve,
|
|
|
|
|
+ }], ()=>{resolve();return true});
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- Toast.remove(l);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ ], () => false);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ resolve('updateok');
|
|
|
}
|
|
}
|
|
|
- ], () => false);
|
|
|
|
|
|
|
+ });
|
|
|
|
|
+ if (res === 'updateok') {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
- } catch (e) {
|
|
|
|
|
- // alert(e?.message || e+"");
|
|
|
|
|
- }
|
|
|
|
|
- setIniting(false);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ setInitlizing(false);
|
|
|
|
|
|
|
|
})();
|
|
})();
|
|
|
|
|
|
|
@@ -196,7 +196,7 @@ export default function RootLayout() {
|
|
|
</Stack>
|
|
</Stack>
|
|
|
</AuthProvider>}
|
|
</AuthProvider>}
|
|
|
</Provider>
|
|
</Provider>
|
|
|
- {initializing && <View className='absolute left-0 top-0 right-0 bottom-0 bg-[#f6f6f6] z-50'>
|
|
|
|
|
|
|
+ {(initializing || !fontsLoaded)&& <View className='absolute left-0 top-0 right-0 bottom-0 bg-[#f6f6f6] z-50'>
|
|
|
<Image contentFit='contain' style={{ flex: 1 }} source={require('@/assets/images/uploading.jpg')} />
|
|
<Image contentFit='contain' style={{ flex: 1 }} source={require('@/assets/images/uploading.jpg')} />
|
|
|
</View>}
|
|
</View>}
|
|
|
</ThemeProvider>
|
|
</ThemeProvider>
|