ntfy/web/src/index.jsx

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
939 B
React
Raw Normal View History

2022-02-19 03:49:51 +13:00
import * as React from "react";
2022-04-08 12:31:24 +12:00
import { createRoot } from "react-dom/client";
2023-06-30 01:07:18 +12:00
// eslint-disable-next-line import/no-unresolved
import { registerSW } from "virtual:pwa-register";
2022-02-21 10:55:55 +13:00
import App from "./components/App";
2022-02-19 03:49:51 +13:00
2023-06-30 01:07:18 +12:00
// fetch new sw every hour, i.e. update app every hour while running
const intervalMS = 60 * 60 * 1000;
// https://vite-pwa-org.netlify.app/guide/periodic-sw-updates.html
registerSW({
onRegisteredSW(swUrl, registration) {
if (!registration) {
return;
}
setInterval(async () => {
if (registration.installing || navigator?.onLine === false) return;
const resp = await fetch(swUrl, {
cache: "no-store",
headers: {
cache: "no-store",
"cache-control": "no-cache",
},
});
if (resp?.status === 200) await registration.update();
}, intervalMS);
},
});
2022-04-08 12:31:24 +12:00
const root = createRoot(document.querySelector("#root"));
root.render(<App />);