1 import Push from 'push.js';
3 import noop from '@proton/utils/noop';
5 import type { ElectronNotification } from '../desktop/desktopTypes';
6 import { invokeInboxDesktopIPC } from '../desktop/ipcHelpers';
7 import { isElectronMail } from './desktop';
10 serviceWorker: './assets/serviceWorker.min.js', // Sets a custom service worker script
19 export const getStatus = (): Status => {
20 const permission = Push.Permission.get();
25 return Status.GRANTED;
27 return Status.DEFAULT;
31 export const isEnabled = (): boolean => Push.Permission.has();
33 export const clear = () => Push.clear();
35 export const request = (onGranted: () => void = noop, onDenied: () => void = noop) => {
37 Push.Permission.request(onGranted, onDenied);
41 * Hotfix to fix requesting the permission on non-promisified requests.
42 * TypeError: undefined is not an object (evaluating 'this._win.Notification.requestPermission().then')
43 * https://github.com/Nickersoft/push.js/issues/117
49 * Create a desktop notification
51 * @param params https://pushjs.org/docs/options
52 * @param electronNotification used to show notification on Electron apps, optional parameter
54 export const create = async (title = '', params = {}, electronNotification?: ElectronNotification) => {
58 if (isElectronMail && electronNotification) {
59 invokeInboxDesktopIPC({ type: 'showNotification', payload: electronNotification });
61 return Push.create(title, params);