service worker stuff
This commit is contained in:
		
							parent
							
								
									b2ba24906e
								
							
						
					
					
						commit
						f29be68425
					
				| @ -16,6 +16,15 @@ | |||||||
| 			</option> | 			</option> | ||||||
| 		</select> | 		</select> | ||||||
| 		<label for="lang" style="opacity:0" >Language</label> | 		<label for="lang" style="opacity:0" >Language</label> | ||||||
|  | 		<div v-if="showUpdateUI" style="position: fixed;bottom: 0;z-index: 1;background: rgba(0,0,0,0.5);padding: 20pt;" class="center-stuff"> | ||||||
|  | 			<p class="update-dialog__content"> | ||||||
|  | 				A new version is available. Refresh to load it? | ||||||
|  | 			</p> | ||||||
|  | 			<div class="update-dialog__actions"> | ||||||
|  | 				<button @click="update">Update</button> | ||||||
|  | 				<button @click="showUpdateUI = false">Cancel</button> | ||||||
|  | 			</div> | ||||||
|  | 		</div> | ||||||
| 	</div> | 	</div> | ||||||
| </template> | </template> | ||||||
| 
 | 
 | ||||||
| @ -26,6 +35,7 @@ export default { | |||||||
| 	name: 'App', | 	name: 'App', | ||||||
| 	data: () => ({ | 	data: () => ({ | ||||||
| 		isConnected: false, | 		isConnected: false, | ||||||
|  | 		c: false, | ||||||
| 	}), | 	}), | ||||||
| 	computed: { | 	computed: { | ||||||
| 	}, | 	}, | ||||||
| @ -48,12 +58,23 @@ export default { | |||||||
| 	methods: { | 	methods: { | ||||||
| 		storeLangPref() { | 		storeLangPref() { | ||||||
| 			localStorage.setItem('lang', this.$i18n.locale) | 			localStorage.setItem('lang', this.$i18n.locale) | ||||||
|  | 		}, | ||||||
|  | 		async update() { | ||||||
|  | 			this.showUpdateUI = false; | ||||||
|  | 			await this.$workbox.messageSW({ type: "SKIP_WAITING" }); | ||||||
| 		} | 		} | ||||||
| 	}, | 	}, | ||||||
| 	mounted() { | 	mounted() { | ||||||
| 		if (localStorage.getItem('lang')) | 		if (localStorage.getItem('lang')) | ||||||
| 			this.$i18n.locale = localStorage.getItem('lang') | 			this.$i18n.locale = localStorage.getItem('lang') | ||||||
| 	}, | 	}, | ||||||
|  | 	created() { | ||||||
|  | 		if (this.$workbox) { | ||||||
|  | 			this.$workbox.addEventListener("waiting", () => { | ||||||
|  | 				this.showUpdateUI = true; | ||||||
|  | 			}); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
| </script> | </script> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,15 +3,15 @@ import { Workbox } from "workbox-window"; | |||||||
| let wb; | let wb; | ||||||
| 
 | 
 | ||||||
| if ("serviceWorker" in navigator) { | if ("serviceWorker" in navigator) { | ||||||
|   wb = new Workbox(`${process.env.BASE_URL}service-worker.js`); | 	wb = new Workbox(`${process.env.BASE_URL}service-worker.js`); | ||||||
| 
 | 
 | ||||||
|   wb.addEventListener("controlling", () => { | 	wb.addEventListener("controlling", () => { | ||||||
|     window.location.reload(); | 		window.location.reload(); | ||||||
|   }); | 	}); | ||||||
| 
 | 
 | ||||||
|   wb.register(); | 	wb.register(); | ||||||
| } else { | } else { | ||||||
|   wb = null; | 	wb = null; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| export default wb; | export default wb; | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Alberto Xamin
						Alberto Xamin