35 lines
No EOL
951 B
TypeScript
35 lines
No EOL
951 B
TypeScript
import React, { useEffect } from 'react';
|
|
import * as Updates from 'expo-updates';
|
|
import { Alert } from 'react-native';
|
|
import type { ReactParentComponent } from '@packages/shared';
|
|
|
|
const UpdateChecker: React.FC<ReactParentComponent> = ({ children }) => {
|
|
useEffect(() => {
|
|
const checkForUpdates = async () => {
|
|
try {
|
|
const update = await Updates.checkForUpdateAsync();
|
|
if (update.isAvailable) {
|
|
Alert.alert(
|
|
"Update available",
|
|
"Restart app to apply the update?",
|
|
[
|
|
{ text: "Later", style: "cancel" },
|
|
{ text: "Update & Restart", onPress: () => Updates.reloadAsync() }
|
|
]
|
|
);
|
|
}
|
|
} catch (error) {
|
|
// Update check failed silently
|
|
}
|
|
};
|
|
|
|
// Only check on production builds
|
|
if (!__DEV__) {
|
|
checkForUpdates();
|
|
}
|
|
}, []);
|
|
|
|
return <>{children}</>;
|
|
};
|
|
|
|
export default UpdateChecker; |