Add prompt to reload page if new version came out

This commit is contained in:
Kacper Donat 2020-01-13 15:40:31 +01:00
parent a0a290e06c
commit 40432a9717
3 changed files with 21 additions and 3 deletions

View File

@ -34,6 +34,7 @@
"xpath": "^0.0.27" "xpath": "^0.0.27"
}, },
"dependencies": { "dependencies": {
"@types/workbox-window": "^4.3.3",
"babel-minify-webpack-plugin": "^0.3.1", "babel-minify-webpack-plugin": "^0.3.1",
"clean-webpack-plugin": "^3.0.0", "clean-webpack-plugin": "^3.0.0",
"copy-webpack-plugin": "^4.5.2", "copy-webpack-plugin": "^4.5.2",
@ -42,6 +43,7 @@
"vue2-leaflet": "^1.0.2", "vue2-leaflet": "^1.0.2",
"vuex": "^3.0.1", "vuex": "^3.0.1",
"vuex-class": "^0.3.1", "vuex-class": "^0.3.1",
"workbox-webpack-plugin": "^4.3.1" "workbox-webpack-plugin": "^4.3.1",
"workbox-window": "^4.3.1"
} }
} }

View File

@ -13,6 +13,7 @@ window['Popper'] = Popper;
// dependencies // dependencies
import Vue from "vue"; import Vue from "vue";
import Vuex, { mapActions, mapMutations, mapState, Store } from 'vuex'; import Vuex, { mapActions, mapMutations, mapState, Store } from 'vuex';
import { Workbox } from "workbox-window";
Vue.use(Vuex); Vue.use(Vuex);
@ -38,8 +39,18 @@ Vue.use(Vuex);
store.dispatch('load', window['czydojade'].state); store.dispatch('load', window['czydojade'].state);
if ('serviceWorker' in navigator) { if ('serviceWorker' in navigator) {
window.addEventListener('load', function() { const wb = new Workbox("/service-worker.js");
navigator.serviceWorker.register('/service-worker.js');
wb.addEventListener('waiting', event => {
if (window.confirm("Dostępna jest nowa wersja, przeładować?")) {
wb.addEventListener('controlling', event => {
window.location.reload();
});
wb.messageSW({type: 'SKIP_WAITING'});
}
}); });
wb.register();
} }
})(); })();

View File

@ -268,6 +268,11 @@
"@types/webpack-sources" "*" "@types/webpack-sources" "*"
source-map "^0.6.0" source-map "^0.6.0"
"@types/workbox-window@^4.3.3":
version "4.3.3"
resolved "https://registry.yarnpkg.com/@types/workbox-window/-/workbox-window-4.3.3.tgz#47f91df7ce7eea5c151a6beb3e8398c7db8ee538"
integrity sha512-iIq2obSq3gvzhwFxg+/02v4VqfHjRg9hpEjoM68TKYcmCAe9QGlFsJ5qPZkJKUuZDVW7cUoR3iiA2jIALFU6Ag==
"@webassemblyjs/ast@1.8.5": "@webassemblyjs/ast@1.8.5":
version "1.8.5" version "1.8.5"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359"