feat: update
This commit is contained in:
@@ -9,7 +9,10 @@ import { Alert, Platform } from 'react-native';
|
||||
import 'react-native-reanimated';
|
||||
import { PaperProvider, MD3DarkTheme, MD3LightTheme } from 'react-native-paper';
|
||||
|
||||
import { useColorScheme } from '@/components/useColorScheme';
|
||||
// ✅ 从 hooks 目录导入
|
||||
import { useColorScheme } from '@/hooks';
|
||||
// ✅ 从 stores 目录导入
|
||||
import { restoreUserState, restoreSettingsState, useTenantActions } from '@/stores';
|
||||
|
||||
export {
|
||||
// Catch any errors thrown by the Layout component.
|
||||
@@ -29,6 +32,7 @@ export default function RootLayout() {
|
||||
SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
|
||||
...FontAwesome.font,
|
||||
});
|
||||
const { requestTenantInfo } = useTenantActions();
|
||||
|
||||
// Expo Router uses Error Boundaries to catch errors in the navigation tree.
|
||||
useEffect(() => {
|
||||
@@ -41,6 +45,31 @@ export default function RootLayout() {
|
||||
}
|
||||
}, [loaded]);
|
||||
|
||||
// 恢复持久化状态并初始化应用数据
|
||||
useEffect(() => {
|
||||
async function initializeApp() {
|
||||
try {
|
||||
// 1. 恢复本地存储的状态
|
||||
await Promise.all([restoreUserState(), restoreSettingsState()]);
|
||||
|
||||
// 2. 调用初始化接口(获取平台数据等)
|
||||
if (__DEV__) {
|
||||
console.log('🚀 Initializing app data...');
|
||||
}
|
||||
|
||||
await requestTenantInfo();
|
||||
|
||||
if (__DEV__) {
|
||||
console.log('✅ Platform data loaded:');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize app:', error);
|
||||
// 初始化失败不应该阻止应用启动,只记录错误
|
||||
}
|
||||
}
|
||||
initializeApp();
|
||||
}, []);
|
||||
|
||||
// 检查热更新
|
||||
useEffect(() => {
|
||||
async function checkForUpdates() {
|
||||
|
||||
Reference in New Issue
Block a user