✨ (notificaiton) dismiss notification when the app is updated
This commit is contained in:
@@ -6,6 +6,12 @@ import { setNotificationInstance, notify } from './utils/notification'
|
|||||||
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(sw) {
|
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')
|
console.log('App is being served from cache by a service worker')
|
||||||
setNotificationInstance((title, options?) =>
|
setNotificationInstance((title, options?) =>
|
||||||
sw.showNotification(title, options)
|
sw.showNotification(title, options)
|
||||||
@@ -26,7 +32,8 @@ if (process.env.NODE_ENV === 'production') {
|
|||||||
sw.showNotification(title, options)
|
sw.showNotification(title, options)
|
||||||
)
|
)
|
||||||
notify('An update is available!', {
|
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() {
|
offline() {
|
||||||
|
|||||||
Reference in New Issue
Block a user