diff --git a/app/javascript/retrospring/features/webpush/index.ts b/app/javascript/retrospring/features/webpush/index.ts index bb5a154d..0d884fde 100644 --- a/app/javascript/retrospring/features/webpush/index.ts +++ b/app/javascript/retrospring/features/webpush/index.ts @@ -12,24 +12,27 @@ export default (): void => { if (swCapable && notificationCapable) { const enableBtn = document.querySelector('button[data-action="push-enable"]'); - navigator.serviceWorker.getRegistration().then(registration => - registration?.pushManager.getSubscription().then(subscription => { - if (subscription) { - document.querySelector('button[data-action="push-enable"]')?.classList.add('d-none'); - document.querySelector('[data-action="push-disable"]')?.classList.remove('d-none'); - if (!subscriptionChecked) { - checkSubscription(subscription); - subscriptionChecked = true; - } - } else { - enableBtn?.classList.remove('d-none'); + navigator.serviceWorker.getRegistration().then(async registration => { + const subscription = await registration?.pushManager.getSubscription(); + if (subscription) { + document.querySelector('button[data-action="push-enable"]')?.classList.add('d-none'); + document.querySelector('[data-action="push-disable"]')?.classList.remove('d-none'); - if (localStorage.getItem('dismiss-push-settings-prompt') == null) { - document.querySelector('.push-settings')?.classList.remove('d-none'); - } + if (!subscriptionChecked) { + checkSubscription(subscription); + subscriptionChecked = true; } - })); + } + + if (!registration) { + enableBtn?.classList.remove('d-none'); + + if (localStorage.getItem('dismiss-push-settings-prompt') == null) { + document.querySelector('.push-settings')?.classList.remove('d-none'); + } + } + }); } registerEvents([