Implemented auto update not yet tested
This commit is contained in:
@@ -10,6 +10,11 @@
|
||||
https://github.com/vuetifyjs/vuetify/issues/9607
|
||||
|
||||
-->
|
||||
<template>
|
||||
<button v-if="updateExists" @click="refreshApp">
|
||||
New version available! Click to update
|
||||
</button>
|
||||
</template>
|
||||
<v-navigation-drawer
|
||||
v-if="isAuthenticated"
|
||||
v-model="drawer"
|
||||
@@ -269,24 +274,37 @@ export default {
|
||||
title: "",
|
||||
helpUrl: "user-intro",
|
||||
menuItems: []
|
||||
}
|
||||
},
|
||||
//pwa update
|
||||
//https://medium.com/@dougallrich/give-users-control-over-app-updates-in-vue-cli-3-pwas-20453aedc1f2
|
||||
refreshing: false,
|
||||
registration: null,
|
||||
updateExists: false
|
||||
};
|
||||
},
|
||||
created() {
|
||||
//Detect version change, wipe persisted form settings if has changed.
|
||||
let currentVersion = window.$gz.clientInfo.version;
|
||||
if (currentVersion != window.$gz.store.state.lastClientVersion) {
|
||||
window.$gz.store.commit(
|
||||
"logItem",
|
||||
"##### New version detected ##### cleared form settings cache (" +
|
||||
window.$gz.store.state.lastClientVersion +
|
||||
" -> " +
|
||||
currentVersion +
|
||||
")"
|
||||
);
|
||||
window.$gz.store.commit("setLastClientVersion", currentVersion);
|
||||
window.$gz.store.commit("clearAllFormSettings");
|
||||
}
|
||||
//pwa update
|
||||
document.addEventListener("swUpdated", this.showRefreshUI, { once: true });
|
||||
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
||||
if (this.refreshing) return;
|
||||
this.refreshing = true;
|
||||
window.location.reload();
|
||||
});
|
||||
|
||||
// //Detect version change, wipe persisted form settings if has changed.
|
||||
// let currentVersion = window.$gz.clientInfo.version;
|
||||
// if (currentVersion != window.$gz.store.state.lastClientVersion) {
|
||||
// window.$gz.store.commit(
|
||||
// "logItem",
|
||||
// "##### New version detected ##### cleared form settings cache (" +
|
||||
// window.$gz.store.state.lastClientVersion +
|
||||
// " -> " +
|
||||
// currentVersion +
|
||||
// ")"
|
||||
// );
|
||||
// window.$gz.store.commit("setLastClientVersion", currentVersion);
|
||||
// window.$gz.store.commit("clearAllFormSettings");
|
||||
// }
|
||||
|
||||
//////////////////////////////////
|
||||
// WIRE UP
|
||||
@@ -378,6 +396,20 @@ export default {
|
||||
},
|
||||
newNotificationCount() {
|
||||
return this.$store.state.newNotificationCount;
|
||||
},
|
||||
//PWA update
|
||||
showRefreshUI(e) {
|
||||
this.registration = e.detail;
|
||||
this.updateExists = true;
|
||||
},
|
||||
refreshApp() {
|
||||
this.updateExists = false;
|
||||
if (!this.registration || !this.registration.waiting) {
|
||||
return;
|
||||
}
|
||||
this.registration.waiting.postMessage("skipWaiting");
|
||||
//todo clear stale data here?
|
||||
//maybe needs better control, i.e. conditionally clear only if needs to and then force re-login after
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user