2020-11-01 18:36:00 +01:00
|
|
|
<template>
|
|
|
|
<div class="update-notification" v-if="updateAvailable">
|
2021-06-24 01:24:57 +02:00
|
|
|
<p>{{ $t('update.available') }}</p>
|
2021-01-17 18:57:57 +01:00
|
|
|
<x-button @click="refreshApp()" :shadow="false">
|
2021-06-24 01:24:57 +02:00
|
|
|
{{ $t('update.do') }}
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
2020-11-01 18:36:00 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import swEvents from '@/ServiceWorker/events.json'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'update',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
updateAvailable: false,
|
|
|
|
registration: null,
|
|
|
|
refreshing: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
|
|
|
document.addEventListener(swEvents.SW_UPDATED, this.showRefreshUI, {once: true})
|
|
|
|
|
|
|
|
if (navigator && navigator.serviceWorker) {
|
|
|
|
navigator.serviceWorker.addEventListener(
|
|
|
|
'controllerchange', () => {
|
|
|
|
if (this.refreshing) return
|
|
|
|
this.refreshing = true
|
|
|
|
window.location.reload()
|
|
|
|
},
|
|
|
|
)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
showRefreshUI(e) {
|
|
|
|
console.log('recieved refresh event', e)
|
|
|
|
this.registration = e.detail
|
|
|
|
this.updateAvailable = true
|
|
|
|
},
|
|
|
|
refreshApp() {
|
|
|
|
this.updateExists = false
|
|
|
|
if (!this.registration || !this.registration.waiting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Notify the service worker to actually do the update
|
|
|
|
this.registration.waiting.postMessage('skipWaiting')
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|