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) {
|
|
|
|
navigator.serviceWorker.getRegistration().then(registration => {
|
|
|
|
if (!registration && localStorage.getItem('dismiss-push-settings-prompt') == null) {
|
|
|
|
document.querySelector('.push-settings').classList.remove('d-none');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
registerEvents([
|
|
|
|
{type: 'click', target: '[data-action="push-enable"]', handler: enableHandler, global: true},
|
|
|
|
{type: 'click', target: '[data-action="push-dismiss"]', handler: dismissHandler, global: true},
|
2022-10-21 13:37:52 -07:00
|
|
|
{type: 'click', target: '[data-action="push-disable"]', handler: () => unsubscribeHandler(false), global: true},
|
|
|
|
{type: 'click', target: '[data-action="push-remove-all"]', handler: () => unsubscribeHandler(true), global: true},
|
2022-09-11 11:42:40 -07:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|