Implemented auto update not yet tested
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ayanova",
|
"name": "ayanova",
|
||||||
"version": "8.0.0-alpha.23",
|
"version": "8.0.0-alpha.24",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"serve": "vue-cli-service serve",
|
"serve": "vue-cli-service serve",
|
||||||
|
|||||||
@@ -10,6 +10,11 @@
|
|||||||
https://github.com/vuetifyjs/vuetify/issues/9607
|
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-navigation-drawer
|
||||||
v-if="isAuthenticated"
|
v-if="isAuthenticated"
|
||||||
v-model="drawer"
|
v-model="drawer"
|
||||||
@@ -269,24 +274,37 @@ export default {
|
|||||||
title: "",
|
title: "",
|
||||||
helpUrl: "user-intro",
|
helpUrl: "user-intro",
|
||||||
menuItems: []
|
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() {
|
created() {
|
||||||
//Detect version change, wipe persisted form settings if has changed.
|
//pwa update
|
||||||
let currentVersion = window.$gz.clientInfo.version;
|
document.addEventListener("swUpdated", this.showRefreshUI, { once: true });
|
||||||
if (currentVersion != window.$gz.store.state.lastClientVersion) {
|
navigator.serviceWorker.addEventListener("controllerchange", () => {
|
||||||
window.$gz.store.commit(
|
if (this.refreshing) return;
|
||||||
"logItem",
|
this.refreshing = true;
|
||||||
"##### New version detected ##### cleared form settings cache (" +
|
window.location.reload();
|
||||||
window.$gz.store.state.lastClientVersion +
|
});
|
||||||
" -> " +
|
|
||||||
currentVersion +
|
// //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("setLastClientVersion", currentVersion);
|
// window.$gz.store.commit(
|
||||||
window.$gz.store.commit("clearAllFormSettings");
|
// "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
|
// WIRE UP
|
||||||
@@ -378,6 +396,20 @@ export default {
|
|||||||
},
|
},
|
||||||
newNotificationCount() {
|
newNotificationCount() {
|
||||||
return this.$store.state.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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
export default {
|
export default {
|
||||||
version: "8.0.0-alpha.23",
|
version: "8.0.0-alpha.24",
|
||||||
copyright: "© 1999-2020, Ground Zero Tech-Works Inc."
|
copyright: "© 1999-2020, Ground Zero Tech-Works Inc."
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,16 +5,27 @@ import { register } from "register-service-worker";
|
|||||||
if (process.env.NODE_ENV === "production") {
|
if (process.env.NODE_ENV === "production") {
|
||||||
register(`${process.env.BASE_URL}service-worker.js`, {
|
register(`${process.env.BASE_URL}service-worker.js`, {
|
||||||
ready() {
|
ready() {
|
||||||
console.log(
|
console.log("Service worker is active.");
|
||||||
"App is being served from cache by a service worker.\n" +
|
|
||||||
"For more details, visit https://goo.gl/AFskqB"
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
cached() {
|
cached() {
|
||||||
console.log("Content has been cached for offline use.");
|
console.log("Content has been cached for offline use.");
|
||||||
},
|
},
|
||||||
updated() {
|
updatefound() {
|
||||||
|
console.log("New content is downloading.");
|
||||||
|
},
|
||||||
|
updated(registration) {
|
||||||
console.log("New content is available; please refresh.");
|
console.log("New content is available; please refresh.");
|
||||||
|
//https://medium.com/@dougallrich/give-users-control-over-app-updates-in-vue-cli-3-pwas-20453aedc1f2
|
||||||
|
document.dispatchEvent(
|
||||||
|
new CustomEvent("swUpdated", { detail: registration })
|
||||||
|
);
|
||||||
|
},
|
||||||
|
registered(registration) {
|
||||||
|
//https://medium.com/@dougallrich/give-users-control-over-app-updates-in-vue-cli-3-pwas-20453aedc1f2
|
||||||
|
console.log("Service worker has been registered.");
|
||||||
|
setInterval(() => {
|
||||||
|
registration.update();
|
||||||
|
}, 1000 * 60 * 60); // e.g. hourly checks
|
||||||
},
|
},
|
||||||
offline() {
|
offline() {
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
25
ayanova/src/sw.js
Normal file
25
ayanova/src/sw.js
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// This is the code piece that GenerateSW mode can't provide for us.
|
||||||
|
// This code listens for the user's confirmation to update the app.
|
||||||
|
//https://medium.com/@dougallrich/give-users-control-over-app-updates-in-vue-cli-3-pwas-20453aedc1f2
|
||||||
|
self.addEventListener("message", e => {
|
||||||
|
if (!e.data) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (e.data) {
|
||||||
|
case "skipWaiting":
|
||||||
|
self.skipWaiting();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// NOOP
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
workbox.core.clientsClaim(); // Vue CLI 4 and Workbox v4, else
|
||||||
|
// workbox.clientsClaim(); // Vue CLI 3 and Workbox v3.
|
||||||
|
|
||||||
|
// The precaching code provided by Workbox.
|
||||||
|
self.__precacheManifest = [].concat(self.__precacheManifest || []);
|
||||||
|
// workbox.precaching.suppressWarnings(); // Only used with Vue CLI 3 and Workbox v3.
|
||||||
|
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
|
||||||
@@ -16,6 +16,12 @@ module.exports = {
|
|||||||
})
|
})
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
transpileDependencies: ["vuetify"],
|
||||||
transpileDependencies: ["vuetify"]
|
pwa: {
|
||||||
|
workboxPluginMode: "InjectManifest",
|
||||||
|
workboxOptions: {
|
||||||
|
swSrc: "./src/sw.js",
|
||||||
|
swDest: "service-worker.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user