2022-09-11 11:42:40 -07:00
|
|
|
import registerEvents from 'retrospring/utilities/registerEvents';
|
|
|
|
import { enableHandler } from './enable';
|
|
|
|
import { dismissHandler } from "./dismiss";
|
2022-10-21 13:37:52 -07:00
|
|
|
import { unsubscribeHandler } from "retrospring/features/webpush/unsubscribe";
|
2022-09-11 11:42:40 -07:00
|
|
|
|
|
|
|
export default (): void => {
|
2022-10-20 09:49:02 -07:00
|
|
|
const swCapable = document.body.classList.contains('cap-service-worker');
|
|
|
|
const notificationCapable = document.body.classList.contains('cap-notification');
|
2022-09-11 11:42:40 -07:00
|
|
|
|
|
|
|
if (swCapable && notificationCapable) {
|
|
|
|
|
2022-10-23 07:00:21 -07:00
|
|
|
navigator.serviceWorker.getRegistration().then(registration => {
|
|
|
|
return registration.pushManager.getSubscription().then(subscription => {
|
|
|
|
if (!subscription) {
|
|
|
|
document.querySelector('button[data-action="push-enable"]').classList.remove('d-none');
|
|
|
|
} else {
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2022-09-11 11:42:40 -07:00
|
|
|
}
|
2022-10-23 07:00:21 -07:00
|
|
|
|
|
|
|
registerEvents([
|
|
|
|
{type: 'click', target: '[data-action="push-enable"]', handler: enableHandler, global: true},
|
|
|
|
{type: 'click', target: '[data-action="push-dismiss"]', handler: dismissHandler, global: true},
|
|
|
|
{type: 'click', target: '[data-action="push-disable"]', handler: unsubscribeHandler, global: true},
|
|
|
|
{
|
|
|
|
type: 'click',
|
|
|
|
target: '[data-action="push-remove-all"]',
|
|
|
|
handler: unsubscribeHandler,
|
|
|
|
global: true
|
|
|
|
},
|
|
|
|
]);
|
2022-09-11 11:42:40 -07:00
|
|
|
}
|