Добавлено автообновление страницы приложения в браузере при обнаружении новой версии

This commit is contained in:
Book Pauk
2022-10-02 15:31:42 +07:00
parent e1fb8afa27
commit 0946941e59
2 changed files with 19 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ import wsc from './webSocketConnection';
import * as utils from '../../share/utils';
import * as cryptoUtils from '../../share/cryptoUtils';
import LockQueue from '../../share/LockQueue';
import packageJson from '../../../package.json';
const rotor = '|/-\\';
const stepBound = [
@@ -92,6 +93,15 @@ class Api {
try {
const config = await this.getConfig();
this.commit('setConfig', config);
//проверим на новую версию, обновимся при необходимости
if (this.config.version) {
if (this.config.version != packageJson.version && Date.now() - this.lastReloadTime > 15*1000) {
this.commit('setLastReloadTime', Date.now());//на всякий случай, чтобы исключить зацикливание в reload
document.location.reload();
}
}
} catch (e) {
this.$root.stdDialog.alert(e.message, 'Ошибка');
}
@@ -101,6 +111,10 @@ class Api {
return this.$store.state.config;
}
get lastReloadTime() {
return this.$store.state.lastReloadTime;
}
get settings() {
return this.$store.state.settings;
}

View File

@@ -1,6 +1,7 @@
// initial state
const state = {
config: {},
lastReloadTime: 0,
settings: {
accessToken: '',
limit: 20,
@@ -12,7 +13,7 @@ const state = {
showDeleted: false,
abCacheEnabled: true,
langDefault: '',
},
},
};
// getters
@@ -26,6 +27,9 @@ const mutations = {
setConfig(state, value) {
state.config = value;
},
setLastReloadTime(state, value) {
state.lastReloadTime = value;
},
setSettings(state, value) {
state.settings = Object.assign({}, state.settings, value);
},