From 9b98e8773d4051ac70529d3b8294ee853788ac8f Mon Sep 17 00:00:00 2001 From: Eliot Berriot <contact@eliotberriot.com> Date: Thu, 9 Jan 2020 12:33:24 +0100 Subject: [PATCH] Fixed API caching not triggered when loading app for first time --- front/src/App.vue | 9 +-------- front/src/store/instance.js | 8 +++++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/front/src/App.vue b/front/src/App.vue index 5417a07e14..b2de3597e8 100644 --- a/front/src/App.vue +++ b/front/src/App.vue @@ -114,7 +114,7 @@ export default { let defaultInstanceUrl = this.$store.state.instance.frontSettings.defaultServerUrl || process.env.VUE_APP_INSTANCE_URL || this.$store.getters['instance/defaultUrl']() this.$store.commit('instance/instanceUrl', defaultInstanceUrl) } else { - // needed to trigger initialization of axios + // needed to trigger initialization of axios / service worker this.$store.commit('instance/instanceUrl', this.$store.state.instance.instanceUrl) } await this.fetchNodeInfo() @@ -320,13 +320,6 @@ export default { '$store.state.instance.instanceUrl' (v) { this.$store.dispatch('instance/fetchSettings') this.fetchNodeInfo() - if (this.serviceWorker.registration) { - let sw = this.serviceWorker.registration.active - if (sw) { - sw.postMessage({command: 'serverChosen', serverUrl: v}) - - } - } }, '$store.state.ui.theme': { immediate: true, diff --git a/front/src/store/instance.js b/front/src/store/instance.js index ec4e47b43d..8fa74afb4c 100644 --- a/front/src/store/instance.js +++ b/front/src/store/instance.js @@ -9,6 +9,12 @@ function getDefaultUrl () { ) } +function notifyServiceWorker (registration, message) { + if (registration && registration.active) { + registration.active.postMessage(message) + } +} + export default { namespaced: true, state: { @@ -75,7 +81,7 @@ export default { value = value + '/' } state.instanceUrl = value - + notifyServiceWorker(state.registration, {command: 'serverChosen', serverUrl: state.instanceUrl}) // append the URL to the list (and remove existing one if needed) if (value) { let index = state.knownInstances.indexOf(value); -- GitLab