From 9b3b6a9170b25209e54c74aa9e96659bc2d19edd Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Tue, 25 May 2021 20:30:17 -0400 Subject: [PATCH] feat(pwa): add notification badge icon (#1695) --- public/badge-128x128.png | Bin 0 -> 3258 bytes public/sw.js | 15 +++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 public/badge-128x128.png diff --git a/public/badge-128x128.png b/public/badge-128x128.png new file mode 100644 index 0000000000000000000000000000000000000000..0ef0e6a024a17a827b1f9ffb52ad343b4980286f GIT binary patch literal 3258 zcmdUx_dgYm|HbchNs&!l$(BS$RwUzITQ*ryxZ!4x`?fA_30Y-iySet>^CIh7p=1jg z#Wk*RN!PwUzJJE|JRavfe?70CUMJefK#PuslLi0)(CKKan_Lm~f4&a7%ERTvlPlC3 zJvGy~;^qGwtAzV&rcQ=B}rpN6OTGAu7 z6?qYEdaEsPx#Da~!-iPTc9e2APGO+NCxUwD>U7#r9d$LcfVu7T&7d;Xn~}JV_q=uC zlZE^(s9Ebq>?Q5v*Nty`-dC=lEABCzDecT=2);=A+7%WW1N-vMBVjd=xg~dYZF#Bt z3*~Uikf~+C+AAmCI%4xmuabwUa zU|6|tT5j%J@N{mS>bu+a&|}1Cp670S_)Nv#PN@P>j9rNLKvUND{66;BB-9Yk2VlwI zUYUn15WJ3VtLBqu?CcsQ5x+^j+2iPo-3N9q!Sm*FBbse>nz}vf!*|JI zRH!NWJRv=1Y1>D*(BLe#c~t2zd%Q-QEFGeK@#u@y#I&W5k0uYBZ!Fq|7+nh4q@^|Y}AUg5Ch{@Cx0vJPavNyDPzS@z`7QM)e?C54tEt(Xq8CR;ybOhVa{ zUBxeFb9(YdOgF?age*)ac3cYXzp7s-mK=|Dgne~+0Y+3NXjDGQd@i#%KG&-&#ZtY< zHcc{t`CRV)f|(a9r+rA$Ta%}92(#N<+o2|}>KorDyrUM9GmAfa;87JSYGjuzs?n8N zz{OkTs*~36z}KL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@_&;^s>tr?#=c2ex;0) zMAvw@0rC0r%)jYDT_Lun+Ry*?+gJsu{WT@xPqe$+LU@SHXH6xf8a1KL!qKRYQJb(M zYw{q8`=!TXh>R3rJfPHwsUfc%yu)<{t$ z1-4h1lR0JeqYo6I%LLcC8`Fax6ljfwGV@Rd+0uzWO$?`1)tQ)y{@dY9%18gK*E;j> zBJh_^Ju1x*(C#*$96%tD3DHn={K=pkMgsd`!r&CNZTo}3Rr=`^s|#T(wUt6{5A^t0 zabIN@wW{y~3zQp0xRpxnrNLi7bAFp^5v>!6BVfYohih;p(DH#<`8ZA; zw+FxW(++9q33~vT7S5*x&?1bre)M_%;X4T|b@uIm@hpn|%mgT6$Ew?7j)XhXf|yze zsf_dkB4+jlcWFMI@o*jKbS8k{@8JK(F<@4iVx= literal 0 HcmV?d00001 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);