feat: Implement automatic update checking and user notifications for new versions

This commit is contained in:
zimplexing
2025-08-01 13:53:29 +08:00
parent 10bfbbbf8e
commit 18aba87ddb
18 changed files with 1524 additions and 4 deletions

View File

@@ -10,6 +10,9 @@ import { useSettingsStore } from "@/stores/settingsStore";
import { useRemoteControlStore } from "@/stores/remoteControlStore";
import LoginModal from "@/components/LoginModal";
import useAuthStore from "@/stores/authStore";
import { useUpdateStore, initUpdateStore } from "@/stores/updateStore";
import { UpdateModal } from "@/components/UpdateModal";
import { UPDATE_CONFIG } from "@/constants/UpdateConfig";
// Prevent the splash screen from auto-hiding before asset loading is complete.
SplashScreen.preventAutoHideAsync();
@@ -22,9 +25,11 @@ export default function RootLayout() {
const { loadSettings, remoteInputEnabled, apiBaseUrl } = useSettingsStore();
const { startServer, stopServer } = useRemoteControlStore();
const { checkLoginStatus } = useAuthStore();
const { checkForUpdate, lastCheckTime } = useUpdateStore();
useEffect(() => {
loadSettings();
initUpdateStore(); // 初始化更新存储
}, [loadSettings]);
useEffect(() => {
@@ -42,6 +47,17 @@ export default function RootLayout() {
}
}, [loaded, error]);
// 检查更新
useEffect(() => {
if (loaded && UPDATE_CONFIG.AUTO_CHECK && Platform.OS === 'android') {
// 检查是否需要自动检查更新
const shouldCheck = Date.now() - lastCheckTime > UPDATE_CONFIG.CHECK_INTERVAL;
if (shouldCheck) {
checkForUpdate(true); // 静默检查
}
}
}, [loaded, lastCheckTime, checkForUpdate]);
useEffect(() => {
if (remoteInputEnabled) {
startServer();
@@ -68,6 +84,7 @@ export default function RootLayout() {
</Stack>
<Toast />
<LoginModal />
<UpdateModal />
</ThemeProvider>
);
}