2022-12-18 22:23:30 +01:00
|
|
|
import { register as registerServiceWorker } from "../serviceWorkerRegistration";
|
2020-10-25 19:39:57 +05:30
|
|
|
import { EVENT } from "../constants";
|
|
|
|
|
|
|
|
// On Apple mobile devices add the proprietary app icon and splashscreen markup.
|
|
|
|
// No one should have to do this manually, and eventually this annoyance will
|
|
|
|
// go away once https://bugs.webkit.org/show_bug.cgi?id=183937 is fixed.
|
|
|
|
if (
|
2020-12-09 16:49:12 +01:00
|
|
|
/\b(iPad|iPhone|iPod|Safari)\b/.test(navigator.userAgent) &&
|
2020-10-25 19:39:57 +05:30
|
|
|
!matchMedia("(display-mode: standalone)").matches
|
|
|
|
) {
|
|
|
|
import(/* webpackChunkName: "pwacompat" */ "pwacompat");
|
|
|
|
}
|
|
|
|
|
|
|
|
registerServiceWorker({
|
|
|
|
onUpdate: (registration) => {
|
|
|
|
const waitingServiceWorker = registration.waiting;
|
|
|
|
if (waitingServiceWorker) {
|
|
|
|
waitingServiceWorker.addEventListener(
|
|
|
|
EVENT.STATE_CHANGE,
|
|
|
|
(event: Event) => {
|
|
|
|
const target = event.target as ServiceWorker;
|
|
|
|
const state = target.state as ServiceWorkerState;
|
|
|
|
if (state === "activated") {
|
|
|
|
window.location.reload();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
);
|
|
|
|
waitingServiceWorker.postMessage({ type: "SKIP_WAITING" });
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|