2022-05-30 00:21:42 +00:00
|
|
|
/// <reference lib="WebWorker" />
|
|
|
|
|
2022-06-01 21:56:37 +00:00
|
|
|
import handleInstall from "./service-worker/install";
|
|
|
|
import handleActivate from "./service-worker/activate";
|
|
|
|
import handlePush from "./service-worker/push";
|
|
|
|
import handleNotificationClick from "./service-worker/notification-click";
|
|
|
|
import handleFetch from "./service-worker/fetch";
|
2022-06-05 22:01:33 +00:00
|
|
|
import handleMessage from "./service-worker/message";
|
2022-05-30 00:21:42 +00:00
|
|
|
|
2022-06-11 13:13:28 +00:00
|
|
|
declare const self: ServiceWorkerGlobalScope;
|
2022-05-30 00:21:42 +00:00
|
|
|
|
2022-06-01 21:56:37 +00:00
|
|
|
self.addEventListener("install", (event) => {
|
|
|
|
event.waitUntil(handleInstall(event).then(() => self.skipWaiting()));
|
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
|
|
event.waitUntil(handleActivate(event).then(() => self.clients.claim()));
|
|
|
|
});
|
2022-05-30 00:21:42 +00:00
|
|
|
|
|
|
|
self.addEventListener("push", (event) => {
|
2022-06-01 21:56:37 +00:00
|
|
|
event.waitUntil(handlePush(event));
|
2022-05-30 00:21:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
self.addEventListener("notificationclick", (event) => {
|
2022-06-01 21:56:37 +00:00
|
|
|
event.waitUntil(handleNotificationClick(event));
|
|
|
|
});
|
2022-05-30 00:21:42 +00:00
|
|
|
|
2022-06-05 22:01:33 +00:00
|
|
|
self.addEventListener("message", (event) => {
|
|
|
|
event.waitUntil(handleMessage(event));
|
|
|
|
});
|
|
|
|
|
2022-06-01 21:56:37 +00:00
|
|
|
self.addEventListener("fetch", (event) => {
|
2022-06-27 11:49:56 +00:00
|
|
|
const isSSERequest = event.request.headers.get("Accept") === "text/event-stream";
|
|
|
|
const isOutsideRequest = !["localhost", "dev.shellphone.app", "www.shellphone.app"].includes(
|
|
|
|
new URL(event.request.url).hostname,
|
|
|
|
);
|
|
|
|
if (isSSERequest || isOutsideRequest) {
|
2022-06-19 15:57:51 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-01 21:56:37 +00:00
|
|
|
event.respondWith(handleFetch(event));
|
2022-05-30 00:21:42 +00:00
|
|
|
});
|