added basic PWA functionality

This commit is contained in:
thilo 2020-03-22 20:18:18 +01:00
parent b3b8a10d92
commit 893bc88ce6
8 changed files with 369 additions and 219 deletions

View file

@ -9,6 +9,19 @@
<script>
export default {
created() {
if (this.$workbox) {
this.$workbox.addEventListener("waiting", () => {
this.showUpgradeUI = true;
});
}
},
methods: {
async accept() {
this.showUpgradeUI = false
await this.$workbox.messageSW({ type: "SKIP_WAITING" });
}
},
mounted() {
this.$store.commit("init")
if (!this.$store.state.surveyCompletedOnce) {

View file

@ -2,7 +2,9 @@ import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import wb from "./registerServiceWorker";
Vue.prototype.$workbox = wb;
Vue.config.productionTip = false
new Vue({

View file

@ -0,0 +1,17 @@
import { Workbox } from "workbox-window";
let wb;
if ("serviceWorker" in navigator) {
wb = new Workbox(`${process.env.BASE_URL}service-worker.js`);
wb.addEventListener("controlling", () => {
window.location.reload();
});
wb.register();
} else {
wb = null;
}
export default wb;