From 55d607d8ea1fd49ad760c092672242b9c5abc984 Mon Sep 17 00:00:00 2001 From: Gannicus Date: Sat, 6 Apr 2024 20:19:15 -0400 Subject: [PATCH] Push the updates --- src/pages/settings/panes/Notifications.tsx | 23 +++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/pages/settings/panes/Notifications.tsx b/src/pages/settings/panes/Notifications.tsx index cae7a611..755570b7 100644 --- a/src/pages/settings/panes/Notifications.tsx +++ b/src/pages/settings/panes/Notifications.tsx @@ -74,6 +74,12 @@ export const Notifications = observer(() => { } onChange={async (pushEnabled) => { try { + console.log( + urlBase64ToUint8Array( + client.configuration!.vapid, + ), + ); + if (!("serviceWorker" in navigator)) { return modalController.push({ type: "error", @@ -81,16 +87,19 @@ export const Notifications = observer(() => { }); } - let reg = + const regReady = await navigator.serviceWorker + .ready; + if (!regReady) { + return modalController.push({ + type: "error", + error: "ServiceWorkerNotReady", + }); + } + + const reg = await navigator.serviceWorker.getRegistration( `${window.location.origin}/sw.js`, ); - if (!reg) { - reg = - await navigator.serviceWorker.register( - `${window.location.origin}/sw.js`, - ); - } if (reg) { if (pushEnabled) {