Allow setting up push when service worker hasn't been registered yet.
We don't register the service worker until the user opts in for push notifications.
This commit is contained in:
parent
7ffd07a959
commit
1a29a19e9d
|
@ -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([
|
||||
|
|
Loading…
Reference in New Issue