2020-02-18 08:57:00 +01:00
|
|
|
import { register } from "register-service-worker";
|
2018-05-18 11:28:29 +02:00
|
|
|
|
2022-08-22 12:12:09 +02:00
|
|
|
if ("serviceWorker" in navigator && import.meta.env.PROD) {
|
2022-07-12 10:55:28 +02:00
|
|
|
register(`${import.meta.env.BASE_URL}service-worker.js`, {
|
2021-05-12 18:24:38 +02:00
|
|
|
ready() {
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug(
|
2021-05-12 18:24:38 +02:00
|
|
|
"App is being served from cache by a service worker.\n" +
|
|
|
|
"For more details, visit https://goo.gl/AFskqB"
|
|
|
|
);
|
|
|
|
},
|
|
|
|
registered() {
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug("Service worker has been registered.");
|
2021-05-12 18:24:38 +02:00
|
|
|
},
|
|
|
|
cached() {
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug("Content has been cached for offline use.");
|
2021-05-12 18:24:38 +02:00
|
|
|
},
|
|
|
|
updatefound() {
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug("New content is downloading.");
|
2021-05-12 18:24:38 +02:00
|
|
|
},
|
2021-06-18 18:19:04 +02:00
|
|
|
updated(registration: ServiceWorkerRegistration) {
|
|
|
|
const event = new CustomEvent("refreshApp", { detail: registration });
|
|
|
|
document.dispatchEvent(event);
|
|
|
|
console.debug("New content is available; please refresh.");
|
2021-05-12 18:24:38 +02:00
|
|
|
},
|
|
|
|
offline() {
|
2021-06-18 18:19:04 +02:00
|
|
|
console.debug(
|
2021-05-12 18:24:38 +02:00
|
|
|
"No internet connection found. App is running in offline mode."
|
|
|
|
);
|
|
|
|
},
|
|
|
|
error(error) {
|
|
|
|
console.error("Error during service worker registration:", error);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|