|
- // (A) INSTANT WORKER ACTIVATION
- self.addEventListener("install", evt => self.skipWaiting());
-
- // (B) CLAIM CONTROL INSTANTLY
- self.addEventListener("activate", evt => self.clients.claim());
-
- // (C) LISTEN TO PUSH
- self.addEventListener("push", evt => {
- const data = evt.data.json();
- console.log("got: " + evt.data);
- self.registration.showNotification(data.title, {
- body: data.body,
- icon: data.icon,
- image: data.image
- });
- });
-
- // (D) HANDLE USER INTERACTION
- // https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/notificationclick_event
- self.addEventListener( "notificationclick", (event) => {
- event.notification.close();
- if (event.action === "archive") {
- // User selected the Archive action.
- //archiveEmail();
- } else {
- // User selected (e.g., clicked in) the main body of notification.
- //clients.openWindow("/inbox");
- }
- },
- false,
- );
|