This commit is contained in:
+10
-4
@@ -2,6 +2,7 @@ import React, { useMemo, useEffect } from "react";
|
||||
import { StatusBar } from "expo-status-bar";
|
||||
import { ActivityIndicator, View, StyleSheet } from "react-native";
|
||||
import * as Updates from "expo-updates";
|
||||
import AsyncStorage from "@react-native-async-storage/async-storage";
|
||||
import { NavigationContainer } from "@react-navigation/native";
|
||||
import { createNativeStackNavigator } from "@react-navigation/native-stack";
|
||||
|
||||
@@ -23,6 +24,8 @@ import type { AuthStackParamList } from "./src/navigation/types";
|
||||
|
||||
const Stack = createNativeStackNavigator<AuthStackParamList>();
|
||||
|
||||
const OTA_LAST_RELOAD_KEY = "ota_last_reload_update_id";
|
||||
|
||||
function AuthStack() {
|
||||
const { colors } = useTheme();
|
||||
|
||||
@@ -97,10 +100,13 @@ export default function App() {
|
||||
const checkForUpdate = async () => {
|
||||
try {
|
||||
const update = await Updates.checkForUpdateAsync();
|
||||
if (update.isAvailable) {
|
||||
await Updates.fetchUpdateAsync();
|
||||
await Updates.reloadAsync();
|
||||
}
|
||||
const id = update.isAvailable ? update.manifest?.id : undefined;
|
||||
if (!id || id === Updates.updateId) return;
|
||||
// Déjà tentée : si elle ne tourne pas, on ne relance pas (évite la boucle)
|
||||
if ((await AsyncStorage.getItem(OTA_LAST_RELOAD_KEY)) === id) return;
|
||||
await Updates.fetchUpdateAsync();
|
||||
await AsyncStorage.setItem(OTA_LAST_RELOAD_KEY, id);
|
||||
await Updates.reloadAsync();
|
||||
} catch (e) {
|
||||
console.error("[OTA] Échec de la vérification/application de la mise à jour:", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user