Retrospring/app/javascript/retrospring/features/webpush/index.ts

25 lines
1.2 KiB
TypeScript
Raw Normal View History

import registerEvents from 'retrospring/utilities/registerEvents';
import { enableHandler } from './enable';
import { dismissHandler } from "./dismiss";
import { unsubscribeHandler } from "retrospring/features/webpush/unsubscribe";
export default (): void => {
const swCapable = document.body.classList.contains('cap-service-worker');
const notificationCapable = document.body.classList.contains('cap-notification');
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},
{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},
]);
}
}