🐛 (notification) try catch notification
This commit is contained in:
@@ -4,11 +4,12 @@ import { register } from 'register-service-worker'
|
||||
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||
ready() {
|
||||
ready(sw) {
|
||||
console.log(
|
||||
'App is being served from cache by a service worker.\n' +
|
||||
'For more details, visit https://goo.gl/AFskqB'
|
||||
)
|
||||
sw.showNotification('Coucou')
|
||||
},
|
||||
registered() {
|
||||
console.log('Service worker has been registered.')
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
declare const Notification: any
|
||||
|
||||
export const notify = (message: string) => {
|
||||
if (!('Notification' in window)) {
|
||||
return
|
||||
} else if (Notification.permission === 'granted') {
|
||||
new Notification(message)
|
||||
} else if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission((permission: any) => {
|
||||
if (!('permission' in Notification)) {
|
||||
Notification.permission = permission
|
||||
}
|
||||
try {
|
||||
if (!('Notification' in window)) {
|
||||
return
|
||||
} else if (Notification.permission === 'granted') {
|
||||
new Notification(message)
|
||||
} else if (Notification.permission !== 'denied') {
|
||||
Notification.requestPermission((permission: any) => {
|
||||
if (!('permission' in Notification)) {
|
||||
Notification.permission = permission
|
||||
}
|
||||
|
||||
if (permission === 'granted') {
|
||||
new Notification(message)
|
||||
}
|
||||
})
|
||||
if (permission === 'granted') {
|
||||
new Notification(message)
|
||||
}
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user