initial work on showing notifications through serviceworkers

This commit is contained in:
Henry Jameson 2023-10-25 18:58:33 +03:00
commit 73fbe89a4b
5 changed files with 58 additions and 21 deletions

View file

@ -1,9 +1,8 @@
import { showDesktopNotification as swDesktopNotification } from '../sw/sw.js'
export const showDesktopNotification = (rootState, desktopNotificationOpts) => {
if (!('Notification' in window && window.Notification.permission === 'granted')) return
if (rootState.statuses.notifications.desktopNotificationSilence) { return }
const desktopNotification = new window.Notification(desktopNotificationOpts.title, desktopNotificationOpts)
// Chrome is known for not closing notifications automatically
// according to MDN, anyway.
setTimeout(desktopNotification.close.bind(desktopNotification), 5000)
swDesktopNotification(desktopNotificationOpts)
}