From 7460ff705513188b3675e358349acc949b757f4d Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 13 Dec 2020 22:50:24 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B2=D1=8B=D1=85=D0=BE=D0=B4=D0=B0=20=D0=BD=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D0=B8=20=D1=87?= =?UTF-8?q?=D0=B8=D1=82=D0=B0=D0=BB=D0=BA=D0=B8=20=D0=B8=20=D1=83=D0=B2?= =?UTF-8?q?=D0=B5=D0=B4=D0=BE=D0=BC=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE?= =?UTF-8?q?=D0=B1=20=D1=8D=D1=82=D0=BE=D0=BC,=20=D0=B7=D0=B0=D0=BE=D0=B4?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=BF=D0=BE=D0=BF=D1=83=D1=82=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82=D0=BE=D1=80=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/App.vue | 34 +++++++++------ client/components/Reader/Reader.vue | 41 ++++++++++++++++++- .../Reader/SettingsPage/include/OthersTab.inc | 13 +++++- client/store/modules/config.js | 13 +----- client/store/modules/reader.js | 4 +- 5 files changed, 78 insertions(+), 27 deletions(-) diff --git a/client/components/App.vue b/client/components/App.vue index 44859c56..9232d1c1 100644 --- a/client/components/App.vue +++ b/client/components/App.vue @@ -2,7 +2,7 @@
- +
@@ -12,8 +12,11 @@ //----------------------------------------------------------------------------- import Vue from 'vue'; import Component from 'vue-class-component'; + import Notify from './share/Notify.vue'; import StdDialog from './share/StdDialog.vue'; + +import miscApi from '../api/misc'; import * as utils from '../share/utils'; export default @Component({ @@ -30,6 +33,8 @@ export default @Component({ }) class App extends Vue { + showPage = false; + itemRuText = { '/cardindex': 'Картотека', '/reader': 'Читалка', @@ -42,7 +47,6 @@ class App extends Vue { created() { this.commit = this.$store.commit; - this.dispatch = this.$store.dispatch; this.state = this.$store.state; this.uistate = this.$store.state.uistate; this.config = this.$store.state.config; @@ -116,18 +120,24 @@ class App extends Vue { this.$root.notify = this.$refs.notify; this.$root.stdDialog = this.$refs.stdDialog; - this.dispatch('config/loadConfig'); - this.$watch('apiError', function(newError) { - if (newError) { - let mes = newError.message; - if (newError.response && newError.response.config) - mes = newError.response.config.url + '
' + newError.response.statusText; - this.$root.notify.error(mes, 'Ошибка API'); - } - }); - this.setAppTitle(); (async() => { + //загрузим конфиг сревера + try { + const config = await miscApi.loadConfig(); + this.commit('config/setConfig', config); + this.showPage = true; + } catch(e) { + //проверим, не получен ли конфиг ранее + if (!this.mode) { + this.$root.notify.error(e.message, 'Ошибка API'); + } else { + //вероятно, работаем в оффлайне + this.showPage = true; + } + console.error(e); + } + //запросим persistent storage if (navigator.storage && navigator.storage.persist) { navigator.storage.persist(); diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index 09a46a36..fea20b06 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -133,6 +133,9 @@ import ReaderDialogs from './ReaderDialogs/ReaderDialogs.vue'; import bookManager from './share/bookManager'; import rstore from '../../store/modules/reader'; import readerApi from '../../api/reader'; +import miscApi from '../../api/misc'; + +import {versionHistory} from './versionHistory'; import * as utils from '../../share/utils'; export default @Component({ @@ -229,7 +232,6 @@ class Reader extends Vue { this.rstore = rstore; this.loading = true; this.commit = this.$store.commit; - this.dispatch = this.$store.dispatch; this.reader = this.$store.state.reader; this.config = this.$store.state.config; @@ -292,6 +294,32 @@ class Reader extends Vue { this.updateRoute(); await this.$refs.dialogs.init(); + + await utils.sleep(15*1000); //подождем 15 секунд, чтобы прогрузился ServiceWorker при выходе новой версии + this.isFirstNeedUpdateNotify = true; + //вечный цикл, запрашиваем периодически конфиг для проверки выхода новой версии читалки + while (true) {// eslint-disable-line no-constant-condition + if (this.showNeedUpdateNotify) { + try { + const config = await miscApi.loadConfig(); + this.commit('config/setConfig', config); + + let againMes = ''; + if (this.isFirstNeedUpdateNotify) { + againMes = ' ЕЩЕ один раз'; + } + + if (this.version != this.clientVersion) + this.$root.notify.info(`Вышла новая версия (v${this.version}) читалки.
Пожалуйста, обновите страницу${againMes}.`, 'Обновление'); + } catch(e) { + // + } + } + + await utils.sleep(3600*1000); //каждый час + this.isFirstNeedUpdateNotify = false; + } + //дальше кода нет })(); } @@ -304,6 +332,7 @@ class Reader extends Vue { this.blinkCachedLoad = settings.blinkCachedLoad; this.showToolButton = settings.showToolButton; this.enableSitesFilter = settings.enableSitesFilter; + this.showNeedUpdateNotify = settings.showNeedUpdateNotify; this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys); this.$root.readerActionByKeyEvent = (event) => { @@ -394,6 +423,16 @@ class Reader extends Vue { return this.$store.state.config.mode; } + get version() { + return this.$store.state.config.version; + } + + get clientVersion() { + let v = versionHistory[0].header; + v = v.split(' ')[0]; + return v; + } + get routeParamUrl() { let result = ''; const path = this.$route.fullPath; diff --git a/client/components/Reader/SettingsPage/include/OthersTab.inc b/client/components/Reader/SettingsPage/include/OthersTab.inc index 46f3427b..5bc4f21b 100644 --- a/client/components/Reader/SettingsPage/include/OthersTab.inc +++ b/client/components/Reader/SettingsPage/include/OthersTab.inc @@ -36,7 +36,18 @@ Показывать уведомление "Что нового" Показывать уведомления "Что нового"
- при каждом выходе новой версии читалки + при появлении новой версии читалки +
+ + + +
+
Уведомление
+ + Показывать уведомление о новой версии + + Напоминать о необходимости обновления страницы
+ при появлении новой версии читалки
diff --git a/client/store/modules/config.js b/client/store/modules/config.js index a9c7c1e7..32852f7f 100644 --- a/client/store/modules/config.js +++ b/client/store/modules/config.js @@ -10,18 +10,7 @@ const state = { const getters = {}; // actions -const actions = { - async loadConfig({ commit, state }) { - commit('setApiError', null, { root: true }); - commit('setConfig', {}); - try { - const config = await miscApi.loadConfig(); - commit('setConfig', config); - } catch (e) { - commit('setApiError', e, { root: true }); - } - }, -}; +const actions = {}; // mutations const mutations = { diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index f99d79c8..ed3d10d9 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -251,11 +251,13 @@ const settingDefaults = { compactTextPerc: 0, imageHeightLines: 100, imageFitWidth: true, + enableSitesFilter: true, + showServerStorageMessages: true, showWhatsNewDialog: true, showDonationDialog2020: true, showLiberamaTopDialog2020: true, - enableSitesFilter: true, + showNeedUpdateNotify: true, fontShifts: {}, showToolButton: {},