From 3ecde302c32f5692891c2df21cf0d4d5669f43f7 Mon Sep 17 00:00:00 2001 From: Julien Calixte Date: Sun, 5 Jul 2020 18:41:07 +0200 Subject: [PATCH] :sparkles: (notification) notify when a new service worker is available. --- src/registerServiceWorker.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/registerServiceWorker.ts b/src/registerServiceWorker.ts index 004f773..455667c 100644 --- a/src/registerServiceWorker.ts +++ b/src/registerServiceWorker.ts @@ -1,7 +1,7 @@ /* eslint-disable no-console */ import { register } from 'register-service-worker' -import { setNotificationInstance } from './utils/notification' +import { setNotificationInstance, notify } from './utils/notification' if (process.env.NODE_ENV === 'production') { register(`${process.env.BASE_URL}service-worker.js`, { @@ -20,8 +20,14 @@ if (process.env.NODE_ENV === 'production') { updatefound() { console.log('New content is downloading.') }, - updated() { + updated(sw) { console.log('New content is available; please refresh.') + setNotificationInstance((title, options?) => + sw.showNotification(title, options) + ) + notify('Une nouvelle version est disponible.', { + body: 'Rafraichissez la page pour mettre à jour.' + }) }, offline() { console.log(