Skip to content

Commit

Permalink
feat: reload automatically on App update
Browse files Browse the repository at this point in the history
  • Loading branch information
AlejandroAkbal committed Mar 11, 2021
1 parent 76ac61f commit 45554b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions nuxt.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default {
{ src: '~/plugins/vuex-router-sync.js', mode: 'client' },
{ src: '~/plugins/vuex-persist.js', mode: 'client' },
{ src: '~/plugins/vue-matomo.js', mode: 'client' },
{ src: '~/plugins/pwa-update.js', mode: 'client' },
],

buildModules: [
Expand Down
18 changes: 18 additions & 0 deletions plugins/pwa-update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export default async (context) => {
const workbox = await window.$workbox

if (!workbox) {
console.debug("Workbox couldn't be loaded.")
return
}

workbox.addEventListener('installed', (event) => {
if (!event.isUpdate) {
console.debug('The PWA is on the latest version.')
return
}

console.debug('There is an update for the PWA, reloading...')
location.reload()
})
}

0 comments on commit 45554b3

Please sign in to comment.