From d2a870ac960aec630e1559563faac0225ad4cb16 Mon Sep 17 00:00:00 2001 From: Henry Jameson Date: Fri, 13 Feb 2026 14:35:17 +0200 Subject: [PATCH] better handling of SW subscription --- src/services/sw/sw.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/services/sw/sw.js b/src/services/sw/sw.js index 72d78384c..e744e37aa 100644 --- a/src/services/sw/sw.js +++ b/src/services/sw/sw.js @@ -41,7 +41,7 @@ function subscribePush(registration, isEnabled, vapidPublicKey) { function unsubscribePush(registration) { return registration.pushManager.getSubscription().then((subscription) => { if (subscription === null) { - return + return Promise.resolve('No subscription') } return subscription.unsubscribe() }) @@ -158,23 +158,23 @@ export function registerPushNotifications( export function unregisterPushNotifications(token) { if (isPushSupported()) { - Promise.all([ - deleteSubscriptionFromBackEnd(token), - getOrCreateServiceWorker() - .then((registration) => { - return unsubscribePush(registration).then((result) => [ - registration, - result, - ]) - }) - .then(([, unsubResult]) => { - if (!unsubResult) { - console.warn("Push subscription cancellation wasn't successful") - } - }), - ]).catch((e) => - console.warn(`Failed to disable Web Push Notifications: ${e.message}`), - ) + getOrCreateServiceWorker() + .then((registration) => { + return unsubscribePush(registration).then((result) => [ + registration, + result, + ]) + }) + .then(([, unsubResult]) => { + if (unsubResult === 'No subscription') return + if (!unsubResult) { + console.warn("Push subscription cancellation wasn't successful") + } + return deleteSubscriptionFromBackEnd(token) + }) + .catch((e) => { + console.warn(`Failed to disable Web Push Notifications: ${e.message}`) + }) } }