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>
|
|
|
|
|
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 {
|
2022-05-15 22:33:19 +02:00
|
|
|
margin: .5rem;
|
2021-10-18 14:33:45 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
background: $warning;
|
2022-05-15 22:33:19 +02:00
|
|
|
padding: 0 .25rem;
|
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;
|
|
|
|
|
|
|
|
@media screen and (max-width: $desktop) {
|
|
|
|
position: fixed;
|
|
|
|
bottom: 1rem;
|
|
|
|
margin: 0;
|
|
|
|
width: 450px;
|
|
|
|
left: calc(50vw - 225px);
|
2022-05-15 22:33:19 +02:00
|
|
|
padding: .5rem;
|
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>
|