(notificaiton) dismiss notification when the app is updated

This commit is contained in:
2020-07-12 22:41:55 +02:00
parent 62ac70a747
commit 6e0d7d2bbc

View File

@@ -6,6 +6,12 @@ import { setNotificationInstance, notify } from './utils/notification'
if (process.env.NODE_ENV === 'production') {
register(`${process.env.BASE_URL}service-worker.js`, {
ready(sw) {
sw.getNotifications().then((notifs) => {
const newVersions = notifs.filter(
(notif) => notif.tag === 'new-version'
)
newVersions.forEach((notif) => notif.close())
})
console.log('App is being served from cache by a service worker')
setNotificationInstance((title, options?) =>
sw.showNotification(title, options)
@@ -26,7 +32,8 @@ if (process.env.NODE_ENV === 'production') {
sw.showNotification(title, options)
)
notify('An update is available!', {
body: `Reload the app to install the update.`
body: `Reload the app to install the update.`,
tag: 'new-version'
})
},
offline() {