diff --git a/public/badge-128x128.png b/public/badge-128x128.png new file mode 100644 index 000000000..0ef0e6a02 Binary files /dev/null and b/public/badge-128x128.png differ diff --git a/public/sw.js b/public/sw.js index d6672e609..a3c816e8f 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,3 +1,4 @@ +/* eslint-disable no-undef */ // Incrementing OFFLINE_VERSION will kick off the install event and force // previously cached resources to be updated from the network. // This variable is intentionally declared and unused. @@ -33,7 +34,7 @@ self.addEventListener("activate", (event) => { ); // Tell the active service worker to take control of the page immediately. - self.clients.claim(); + clients.claim(); }); self.addEventListener("fetch", (event) => { @@ -57,6 +58,7 @@ self.addEventListener("fetch", (event) => { // due to a network error. // If fetch() returns a valid HTTP response with a response code in // the 4xx or 5xx range, the catch() will NOT be called. + // eslint-disable-next-line no-console console.log("Fetch failed; returning offline page instead.", error); const cache = await caches.open(CACHE_NAME); @@ -73,6 +75,7 @@ self.addEventListener('push', (event) => { const options = { body: payload.message, + badge: 'badge-128x128.png', icon: payload.image ? payload.image : 'android-chrome-192x192.png', vibrate: [100, 50, 100], data: { @@ -109,7 +112,7 @@ self.addEventListener('push', (event) => { event.waitUntil( self.registration.showNotification(payload.subject, options) ); -}) +}); self.addEventListener('notificationclick', (event) => { const notificationData = event.notification.data; @@ -117,20 +120,20 @@ self.addEventListener('notificationclick', (event) => { event.notification.close(); if (event.action === 'viewmedia') { - self.clients.openWindow(notificationData.actionUrl); + clients.openWindow(notificationData.actionUrl); } else if (event.action === 'approve') { fetch(`/api/v1/request/${notificationData.requestId}/approve`, { method: 'POST', }); - self.clients.openWindow(notificationData.actionUrl); + clients.openWindow(notificationData.actionUrl); } else if (event.action === 'decline') { fetch(`/api/v1/request/${notificationData.requestId}/decline`, { method: 'POST', }); - self.clients.openWindow(notificationData.actionUrl); + clients.openWindow(notificationData.actionUrl); } else if (notificationData.actionUrl) { - self.clients.openWindow(notificationData.actionUrl); + clients.openWindow(notificationData.actionUrl); } }, false);