move service worker code to a separate file

This commit is contained in:
Hans Pagel committed 2023-02-06 17:54:10 +01:00
1 parent 0ded55bf21
commit d12c6063cd
2 files changed
+25 -29

No files matched your search

-28
View File
@@ -21,7 +21,6 @@ import { initI18n } from "~/utils/i18n";
import Desktop from "./components/DesktopEventHandler";
import LazyPolyfill from "./components/LazyPolyfills";
import Routes from "./routes";
import Logger from "./utils/Logger";
import history from "./utils/history";
import { initSentry } from "./utils/sentry";
@@ -38,33 +37,6 @@ if (env.SENTRY_DSN) {
initSentry(history);
}
if ("serviceWorker" in window.navigator) {
window.addEventListener("load", () => {
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
// In some rare (<0.1% of cases) this call can return `undefined`
const maybePromise = window.navigator.serviceWorker.register(
"/static/service-worker.js",
{
scope: "/",
}
);
if (maybePromise?.then) {
maybePromise
.then((registration) => {
Logger.debug("lifecycle", "SW registered: ", registration);
})
.catch((registrationError) => {
Logger.debug(
"lifecycle",
"SW registration failed: ",
registrationError
);
});
}
});
}
// Make sure to return the specific export containing the feature bundle.
const loadFeatures = () => import("./utils/motion").then((res) => res.default);
+25 -1
View File
@@ -1 +1,25 @@
export default console.log("Hello, I’m there to register the service worker.");
import Logger from "~/utils/Logger";
if ("serviceWorker" in navigator) {
window.addEventListener("load", () => {
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=1097616
// In some rare (<0.1% of cases) this call can return `undefined`
const maybePromise = navigator.serviceWorker.register("/sw.js", {
scope: "/",
});
if (maybePromise?.then) {
maybePromise
.then((registration) => {
Logger.debug("lifecycle", "SW registered: ", registration);
})
.catch((registrationError) => {
Logger.debug(
"lifecycle",
"SW registration failed: ",
registrationError
);
});
}
});
}