fix:小组件- PUSH
This commit is contained in:
@@ -6,9 +6,12 @@ import * as SplashScreen from 'expo-splash-screen';
|
||||
import * as Notifications from 'expo-notifications';
|
||||
import { useEffect, useState } from 'react';
|
||||
import 'react-native-reanimated';
|
||||
import { AppState } from 'react-native';
|
||||
|
||||
import { useColorScheme } from '@/components/useColorScheme';
|
||||
import { initI18n } from '@/src/i18n';
|
||||
import { ensureDailyWidgetRecoUpToDate, syncWidgetConfig, syncWidgetUserProfileFromStorage } from '@/src/modules/dailyWidgetReco';
|
||||
import { getOrCreateClientUserId } from '@/src/storage/appStorage';
|
||||
|
||||
// 配置通知处理方式(即使不发送也建议配置,以确保权限接口正常)
|
||||
Notifications.setNotificationHandler({
|
||||
@@ -53,6 +56,17 @@ export default function RootLayout() {
|
||||
.finally(() => setI18nReady(true));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// 尽早生成 client_user_id,便于后续任意时刻与后端建立关联(Push Token/偏好等)
|
||||
getOrCreateClientUserId()
|
||||
.then((id) => {
|
||||
if (__DEV__) console.log('[client_user_id]', id);
|
||||
})
|
||||
.catch((e) => {
|
||||
console.warn('[client_user_id] 生成失败(不阻塞启动)', e);
|
||||
});
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
// 等字体与 i18n 都准备好后再隐藏启动页,避免文案闪烁
|
||||
if (loaded && i18nReady) {
|
||||
@@ -70,6 +84,21 @@ export default function RootLayout() {
|
||||
function RootLayoutNav() {
|
||||
const colorScheme = useColorScheme();
|
||||
|
||||
useEffect(() => {
|
||||
// iOS 小组件:启动时把必要信息写入共享区,并尽力刷新一次“每日推荐”
|
||||
syncWidgetConfig().catch(() => {});
|
||||
syncWidgetUserProfileFromStorage().catch(() => {});
|
||||
ensureDailyWidgetRecoUpToDate({ reason: 'app_start' }).catch(() => {});
|
||||
|
||||
const sub = AppState.addEventListener('change', (state) => {
|
||||
if (state === 'active') {
|
||||
// App 回到前台时尝试刷新(失败不阻塞)
|
||||
ensureDailyWidgetRecoUpToDate({ reason: 'app_active' }).catch(() => {});
|
||||
}
|
||||
});
|
||||
return () => sub.remove();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme}>
|
||||
<Stack screenOptions={{ headerShown: false }}>
|
||||
|
||||
Reference in New Issue
Block a user