fallback to old notification method, don't spam if old way of creating
notification fails, try to use favicon
This commit is contained in:
parent
1b7e930b2e
commit
0628aac664
4 changed files with 27 additions and 10 deletions
|
|
@ -1,8 +1,18 @@
|
|||
import { showDesktopNotification as swDesktopNotification } from '../sw/sw.js'
|
||||
import { showDesktopNotification as swDesktopNotification, isSWSupported } from '../sw/sw.js'
|
||||
const state = { failCreateNotif: false }
|
||||
|
||||
export const showDesktopNotification = (rootState, desktopNotificationOpts) => {
|
||||
if (!('Notification' in window && window.Notification.permission === 'granted')) return
|
||||
if (rootState.statuses.notifications.desktopNotificationSilence) { return }
|
||||
|
||||
swDesktopNotification(desktopNotificationOpts)
|
||||
if (isSWSupported()) {
|
||||
swDesktopNotification(desktopNotificationOpts)
|
||||
} else if (!state.failCreateNotif) {
|
||||
try {
|
||||
const desktopNotification = new window.Notification(desktopNotificationOpts.title, desktopNotificationOpts)
|
||||
setTimeout(desktopNotification.close.bind(desktopNotification), 5000)
|
||||
} catch {
|
||||
state.failCreateNotif = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue