feat(app-update): add in-app update flow with native e2e coverage

This commit is contained in:
Tommaso Casaburi
2026-03-19 20:19:48 +08:00
parent bc870ae438
commit a2286aa68e
61 changed files with 1900 additions and 249 deletions
@@ -1,45 +1,4 @@
import { useEffect } from 'react';
import packageJson from '../../../package.json';
import { fetchLatestStableVersion, isElectron, refreshServiceWorkerRegistration } from '../../lib/app-update';
import useAppUpdateStore from '../../stores/use-app-update-store';
const UPDATE_CHECK_INTERVAL_MS = 60 * 1000;
const AppUpdateRegistration = () => {
useEffect(() => {
if (isElectron) {
return undefined;
}
let isDisposed = false;
const syncUpdateAvailability = async () => {
await refreshServiceWorkerRegistration().catch((error) => {
console.error('Failed to refresh service worker registration', error);
});
try {
const latestStableVersion = await fetchLatestStableVersion();
if (!isDisposed) {
useAppUpdateStore.getState().setNeedRefresh(packageJson.version !== latestStableVersion);
}
} catch (error) {
console.error('Failed to check app update availability', error);
}
};
void syncUpdateAvailability();
const intervalId = window.setInterval(() => {
void syncUpdateAvailability();
}, UPDATE_CHECK_INTERVAL_MS);
return () => {
isDisposed = true;
window.clearInterval(intervalId);
useAppUpdateStore.getState().setNeedRefresh(false);
};
}, []);
return null;
};