mirror of
https://github.com/sussy-code/smov.git
synced 2025-01-20 02:21:25 +01:00
27 lines
589 B
TypeScript
27 lines
589 B
TypeScript
import { registerSW } from "virtual:pwa-register";
|
|
|
|
const intervalMS = 60 * 60 * 1000;
|
|
|
|
registerSW({
|
|
immediate: true,
|
|
onRegisteredSW(swUrl, r) {
|
|
if (!r) return;
|
|
setInterval(async () => {
|
|
if (!(!r.installing && navigator)) return;
|
|
|
|
if ("connection" in navigator && !navigator.onLine) return;
|
|
|
|
const resp = await fetch(swUrl, {
|
|
cache: "no-store",
|
|
headers: {
|
|
cache: "no-store",
|
|
"cache-control": "no-cache",
|
|
},
|
|
});
|
|
|
|
if (resp?.status === 200) {
|
|
await r.update();
|
|
}
|
|
}, intervalMS);
|
|
},
|
|
});
|