fix service worker

This commit is contained in:
Alberto Xamin 2023-01-27 19:27:41 +00:00
parent 983e1cb9cd
commit a4876a3b17
2 changed files with 16 additions and 2 deletions

View File

@ -57,6 +57,7 @@ export default {
data: () => ({ data: () => ({
isConnected: false, isConnected: false,
c: false, c: false,
registration: null,
showUpdateUI: false, showUpdateUI: false,
showHelp:false, showHelp:false,
theme: 'light', theme: 'light',
@ -90,9 +91,12 @@ export default {
localStorage.setItem('lang', this.$i18n.locale); localStorage.setItem('lang', this.$i18n.locale);
document.documentElement.lang = this.$i18n.locale; document.documentElement.lang = this.$i18n.locale;
}, },
async update() { update() {
this.showUpdateUI = false; this.showUpdateUI = false;
await this.$workbox.messageSW({ type: "SKIP_WAITING" }); // Make sure we only send a 'skip waiting' message if the SW is waiting
if (!this.registration || !this.registration.waiting) return
// Send message to SW to skip the waiting and activate the new SW
this.registration.waiting.postMessage({ type: 'SKIP_WAITING' })
}, },
detectColorScheme() { detectColorScheme() {
if(localStorage.getItem("theme")){ if(localStorage.getItem("theme")){
@ -119,6 +123,10 @@ export default {
this.$socket.emit('report', text) this.$socket.emit('report', text)
} }
}, },
updateAvailable(event) {
this.registration = event.detail
this.showUpdateUI = true
}
}, },
watch: { watch: {
theme() { theme() {
@ -158,6 +166,7 @@ export default {
datadogRum.startSessionReplayRecording(); datadogRum.startSessionReplayRecording();
}, },
created() { created() {
document.addEventListener('swUpdated', this.updateAvailable, { once: true })
if (this.$workbox) { if (this.$workbox) {
this.$workbox.addEventListener("waiting", () => { this.$workbox.addEventListener("waiting", () => {
this.showUpdateUI = true; this.showUpdateUI = true;

View File

@ -6,6 +6,11 @@ module.exports = {
manifestOptions: { manifestOptions: {
display: 'standalone', display: 'standalone',
}, },
workboxPluginMode: 'GenerateSW',
workboxOptions: {
navigateFallback: '/index.html',
cleanupOutdatedCaches: true,
}
}, },
configureWebpack: { configureWebpack: {
output: { output: {