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) {
|
if (swCapable && notificationCapable) {
|
||||||
const enableBtn = document.querySelector('button[data-action="push-enable"]');
|
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) {
|
navigator.serviceWorker.getRegistration().then(async registration => {
|
||||||
checkSubscription(subscription);
|
const subscription = await registration?.pushManager.getSubscription();
|
||||||
subscriptionChecked = true;
|
if (subscription) {
|
||||||
}
|
document.querySelector('button[data-action="push-enable"]')?.classList.add('d-none');
|
||||||
} else {
|
document.querySelector('[data-action="push-disable"]')?.classList.remove('d-none');
|
||||||
enableBtn?.classList.remove('d-none');
|
|
||||||
|
|
||||||
if (localStorage.getItem('dismiss-push-settings-prompt') == null) {
|
if (!subscriptionChecked) {
|
||||||
document.querySelector('.push-settings')?.classList.remove('d-none');
|
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([
|
registerEvents([
|
||||||
|
|
Loading…
Reference in New Issue