Fixed API caching not triggered when loading app for first time

This commit is contained in:
Eliot Berriot 2020-01-09 12:33:24 +01:00
parent bf4c1290d7
commit 9b98e8773d
No known key found for this signature in database
GPG Key ID: 6B501DFD73514E14
2 changed files with 8 additions and 9 deletions

View File

@ -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,

View File

@ -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);