diff --git a/src/registerServiceWorker.ts b/src/registerServiceWorker.ts index e940164..555741b 100644 --- a/src/registerServiceWorker.ts +++ b/src/registerServiceWorker.ts @@ -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.') diff --git a/src/utils/notification.ts b/src/utils/notification.ts index 02c42ce..213479c 100644 --- a/src/utils/notification.ts +++ b/src/utils/notification.ts @@ -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 } }