fix(pwa): added reload on new version
This commit is contained in:
		
							parent
							
								
									c8db56c23f
								
							
						
					
					
						commit
						d49da7dc3b
					
				| @ -29,6 +29,7 @@ export default { | |||||||
| 
 | 
 | ||||||
|   // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
 |   // Plugins to run before rendering page (https://go.nuxtjs.dev/config-plugins)
 | ||||||
|   plugins: [ |   plugins: [ | ||||||
|  |     {src: '~/plugins/pwa-update.plugin.ts', mode: 'client'}, | ||||||
|     '~/plugins/vuetify-toast' |     '~/plugins/vuetify-toast' | ||||||
|   ], |   ], | ||||||
| 
 | 
 | ||||||
|  | |||||||
							
								
								
									
										26
									
								
								plugins/pwa-update.plugin.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								plugins/pwa-update.plugin.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,26 @@ | |||||||
|  | import { Plugin } from '@nuxt/types' | ||||||
|  | 
 | ||||||
|  | const pwaUpdatePlugin: Plugin = async () => { | ||||||
|  |   // @ts-ignore
 | ||||||
|  |   const workbox = await window.$workbox | ||||||
|  | 
 | ||||||
|  |   if (!workbox) { | ||||||
|  |     // eslint-disable-next-line no-console
 | ||||||
|  |     console.debug("Workbox couldn't be loaded.") | ||||||
|  |     return | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   workbox.addEventListener('installed', (event: { isUpdate: boolean }) => { | ||||||
|  |     if (!event.isUpdate) { | ||||||
|  |       // eslint-disable-next-line no-console
 | ||||||
|  |       console.debug('The PWA is on the latest version.') | ||||||
|  |       return | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     // eslint-disable-next-line no-console
 | ||||||
|  |     console.debug('There is an update for the PWA, reloading...') | ||||||
|  |     window.location.reload() | ||||||
|  |   }) | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default pwaUpdatePlugin | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user