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>
|
|
|
|
export default {
|
|
|
|
name: 'update',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
updateAvailable: false,
|
|
|
|
registration: null,
|
|
|
|
refreshing: false,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
created() {
|
2021-07-26 22:26:53 +02:00
|
|
|
document.addEventListener('swUpdated', this.showRefreshUI, {once: true})
|
2020-11-01 18:36:00 +01:00
|
|
|
|
|
|
|
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>
|
2021-10-18 14:33:45 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.update-notification {
|
|
|
|
margin: 1rem;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
background: $warning;
|
|
|
|
padding: 0 0 0 .5rem;
|
|
|
|
border-radius: $radius;
|
|
|
|
font-size: .9rem;
|
2021-11-22 22:12:54 +01:00
|
|
|
color: var(--grey-900);
|
2021-10-18 14:33:45 +02:00
|
|
|
justify-content: space-between;
|
|
|
|
|
|
|
|
@media screen and (max-width: $desktop) {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 1rem;
|
|
|
|
margin: 0;
|
|
|
|
width: 450px;
|
|
|
|
left: calc(50vw - 225px);
|
|
|
|
}
|
|
|
|
|
|
|
|
@media screen and (max-width: $tablet) {
|
|
|
|
position: fixed;
|
|
|
|
left: 1rem;
|
|
|
|
right: 1rem;
|
|
|
|
bottom: 1rem;
|
|
|
|
width: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
p {
|
|
|
|
text-align: center;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
|
|
|
|
> * + * {
|
|
|
|
margin-left: .5rem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|