fix(pwa): make web updates deterministic (#1093)

* fix(pwa): make web updates deterministic

* fix(pwa): address review feedback
This commit is contained in:
Tommaso Casaburi
2026-03-17 16:20:13 +08:00
committed by GitHub
parent b2946e8b2e
commit f812fe1d18
11 changed files with 235 additions and 27 deletions
+26
View File
@@ -0,0 +1,26 @@
const isElectron = window.electronApi?.isElectron === true;
const fetchLatestStableVersion = async (): Promise<string> => {
const versionUrl = isElectron
? 'https://raw.githubusercontent.com/bitsocialnet/5chan/master/package.json'
: new URL(`/version.json?t=${Date.now()}`, window.location.origin).toString();
const packageRes = await fetch(versionUrl, { cache: 'no-store' });
const packageData = await packageRes.json();
if (typeof packageData?.version !== 'string') {
throw new Error('invalid version payload');
}
return packageData.version;
};
const refreshServiceWorkerRegistration = async (): Promise<void> => {
if (!('serviceWorker' in navigator)) {
return;
}
const registration = await navigator.serviceWorker.getRegistration();
await registration?.update();
};
export { fetchLatestStableVersion, isElectron, refreshServiceWorkerRegistration };