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>
|
2022-09-14 19:06:34 +02:00
|
|
|
<x-button @click="refreshApp()" :shadow="false" class="has-no-text-wrap">
|
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>
|
|
|
|
|
2022-05-08 22:06:48 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import {ref} from 'vue'
|
2022-02-15 13:07:59 +01:00
|
|
|
|
2022-05-08 22:06:48 +02:00
|
|
|
const updateAvailable = ref(false)
|
|
|
|
const registration = ref(null)
|
|
|
|
const refreshing = ref(false)
|
2020-11-01 18:36:00 +01:00
|
|
|
|
2022-05-08 22:06:48 +02:00
|
|
|
document.addEventListener('swUpdated', showRefreshUI, {once: true})
|
|
|
|
|
|
|
|
if (navigator && navigator.serviceWorker) {
|
|
|
|
navigator.serviceWorker.addEventListener(
|
|
|
|
'controllerchange', () => {
|
|
|
|
if (refreshing.value) return
|
|
|
|
refreshing.value = true
|
|
|
|
window.location.reload()
|
2020-11-01 18:36:00 +01:00
|
|
|
},
|
2022-05-08 22:06:48 +02:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function showRefreshUI(e) {
|
|
|
|
console.log('recieved refresh event', e)
|
|
|
|
registration.value = e.detail
|
|
|
|
updateAvailable.value = true
|
|
|
|
}
|
|
|
|
|
|
|
|
function refreshApp() {
|
|
|
|
if (!registration.value || !registration.value.waiting) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// Notify the service worker to actually do the update
|
|
|
|
registration.value.waiting.postMessage('skipWaiting')
|
|
|
|
}
|
2020-11-01 18:36:00 +01:00
|
|
|
</script>
|
2021-10-18 14:33:45 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.update-notification {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
background: $warning;
|
2022-09-14 19:06:34 +02:00
|
|
|
padding: .5rem;
|
2021-10-18 14:33:45 +02:00
|
|
|
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;
|
|
|
|
|
2022-09-14 19:06:34 +02:00
|
|
|
position: fixed;
|
|
|
|
bottom: 1rem;
|
|
|
|
width: 450px;
|
|
|
|
left: calc(50vw - 225px);
|
2021-10-18 14:33:45 +02:00
|
|
|
|
|
|
|
@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;
|
|
|
|
}
|
|
|
|
}
|
2022-01-18 21:31:40 +01:00
|
|
|
|
|
|
|
.dark .update-notification {
|
|
|
|
color: var(--grey-200);
|
|
|
|
}
|
2021-10-18 14:33:45 +02:00
|
|
|
</style>
|