added basic PWA functionality
This commit is contained in:
parent
b3b8a10d92
commit
893bc88ce6
8 changed files with 369 additions and 219 deletions
13
src/App.vue
13
src/App.vue
|
@ -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) {
|
||||
|
|
|
@ -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({
|
||||
|
|
17
src/registerServiceWorker.js
Normal file
17
src/registerServiceWorker.js
Normal 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;
|
Loading…
Add table
Add a link
Reference in a new issue