mirror of
https://github.com/p-stream/p-stream.git
synced 2026-04-14 12:30:23 +00: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);
|
|
},
|
|
});
|