🐛 (notification) try catch notification

This commit is contained in:
2020-07-02 08:46:19 +02:00
parent 53f8609885
commit f0a9fdd38a
2 changed files with 19 additions and 14 deletions

View File

@@ -4,11 +4,12 @@ import { register } from 'register-service-worker'
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, { register(`${process.env.BASE_URL}service-worker.js`, {
ready() { ready(sw) {
console.log( console.log(
'App is being served from cache by a service worker.\n' + 'App is being served from cache by a service worker.\n' +
'For more details, visit https://goo.gl/AFskqB' 'For more details, visit https://goo.gl/AFskqB'
) )
sw.showNotification('Coucou')
}, },
registered() { registered() {
console.log('Service worker has been registered.') console.log('Service worker has been registered.')

View File

@@ -1,19 +1,23 @@
declare const Notification: any declare const Notification: any
export const notify = (message: string) => { export const notify = (message: string) => {
if (!('Notification' in window)) { try {
return if (!('Notification' in window)) {
} else if (Notification.permission === 'granted') { return
new Notification(message) } else if (Notification.permission === 'granted') {
} else if (Notification.permission !== 'denied') { new Notification(message)
Notification.requestPermission((permission: any) => { } else if (Notification.permission !== 'denied') {
if (!('permission' in Notification)) { Notification.requestPermission((permission: any) => {
Notification.permission = permission if (!('permission' in Notification)) {
} Notification.permission = permission
}
if (permission === 'granted') { if (permission === 'granted') {
new Notification(message) new Notification(message)
} }
}) })
}
} catch (error) {
return
} }
} }