Bladeren bron

Добавлена проверка выхода новой версии читалки и уведомление об этом,
заодно попутный рефакторинг

Book Pauk 4 jaren geleden
bovenliggende
commit
7460ff7055

+ 22 - 12
client/components/App.vue

@@ -2,7 +2,7 @@
     <div class="fit row">
     <div class="fit row">
         <Notify ref="notify"/>
         <Notify ref="notify"/>
         <StdDialog ref="stdDialog"/>
         <StdDialog ref="stdDialog"/>
-        <keep-alive>
+        <keep-alive v-if="showPage">
             <router-view class="col"></router-view>
             <router-view class="col"></router-view>
         </keep-alive>
         </keep-alive>
     </div>
     </div>
@@ -12,8 +12,11 @@
 //-----------------------------------------------------------------------------
 //-----------------------------------------------------------------------------
 import Vue from 'vue';
 import Vue from 'vue';
 import Component from 'vue-class-component';
 import Component from 'vue-class-component';
+
 import Notify from './share/Notify.vue';
 import Notify from './share/Notify.vue';
 import StdDialog from './share/StdDialog.vue';
 import StdDialog from './share/StdDialog.vue';
+
+import miscApi from '../api/misc';
 import * as utils from '../share/utils';
 import * as utils from '../share/utils';
 
 
 export default @Component({
 export default @Component({
@@ -30,6 +33,8 @@ export default @Component({
 
 
 })
 })
 class App extends Vue {
 class App extends Vue {
+    showPage = false;
+
     itemRuText = {
     itemRuText = {
         '/cardindex': 'Картотека',
         '/cardindex': 'Картотека',
         '/reader': 'Читалка',
         '/reader': 'Читалка',
@@ -42,7 +47,6 @@ class App extends Vue {
 
 
     created() {
     created() {
         this.commit = this.$store.commit;
         this.commit = this.$store.commit;
-        this.dispatch = this.$store.dispatch;
         this.state = this.$store.state;
         this.state = this.$store.state;
         this.uistate = this.$store.state.uistate;
         this.uistate = this.$store.state.uistate;
         this.config = this.$store.state.config;
         this.config = this.$store.state.config;
@@ -116,18 +120,24 @@ class App extends Vue {
         this.$root.notify = this.$refs.notify;
         this.$root.notify = this.$refs.notify;
         this.$root.stdDialog = this.$refs.stdDialog;
         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 + '<br>' + newError.response.statusText;
-                this.$root.notify.error(mes, 'Ошибка API');
-            }
-        });
-
         this.setAppTitle();
         this.setAppTitle();
         (async() => {
         (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
             //запросим persistent storage
             if (navigator.storage && navigator.storage.persist) {
             if (navigator.storage && navigator.storage.persist) {
                 navigator.storage.persist();
                 navigator.storage.persist();

+ 40 - 1
client/components/Reader/Reader.vue

@@ -133,6 +133,9 @@ import ReaderDialogs from './ReaderDialogs/ReaderDialogs.vue';
 import bookManager from './share/bookManager';
 import bookManager from './share/bookManager';
 import rstore from '../../store/modules/reader';
 import rstore from '../../store/modules/reader';
 import readerApi from '../../api/reader';
 import readerApi from '../../api/reader';
+import miscApi from '../../api/misc';
+
+import {versionHistory} from './versionHistory';
 import * as utils from '../../share/utils';
 import * as utils from '../../share/utils';
 
 
 export default @Component({
 export default @Component({
@@ -229,7 +232,6 @@ class Reader extends Vue {
         this.rstore = rstore;
         this.rstore = rstore;
         this.loading = true;
         this.loading = true;
         this.commit = this.$store.commit;
         this.commit = this.$store.commit;
-        this.dispatch = this.$store.dispatch;
         this.reader = this.$store.state.reader;
         this.reader = this.$store.state.reader;
         this.config = this.$store.state.config;
         this.config = this.$store.state.config;
 
 
@@ -292,6 +294,32 @@ class Reader extends Vue {
             this.updateRoute();
             this.updateRoute();
 
 
             await this.$refs.dialogs.init();
             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}) читалки.<br>Пожалуйста, обновите страницу${againMes}.`, 'Обновление');
+                    } catch(e) {
+                        //
+                    }
+                }
+
+                await utils.sleep(3600*1000); //каждый час
+                this.isFirstNeedUpdateNotify = false;
+            }
+            //дальше кода нет
         })();
         })();
     }
     }
 
 
@@ -304,6 +332,7 @@ class Reader extends Vue {
         this.blinkCachedLoad = settings.blinkCachedLoad;
         this.blinkCachedLoad = settings.blinkCachedLoad;
         this.showToolButton = settings.showToolButton;
         this.showToolButton = settings.showToolButton;
         this.enableSitesFilter = settings.enableSitesFilter;
         this.enableSitesFilter = settings.enableSitesFilter;
+        this.showNeedUpdateNotify = settings.showNeedUpdateNotify;
 
 
         this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
         this.readerActionByKeyCode = utils.userHotKeysObjectSwap(settings.userHotKeys);
         this.$root.readerActionByKeyEvent = (event) => {
         this.$root.readerActionByKeyEvent = (event) => {
@@ -394,6 +423,16 @@ class Reader extends Vue {
         return this.$store.state.config.mode;
         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() {
     get routeParamUrl() {
         let result = '';
         let result = '';
         const path = this.$route.fullPath;
         const path = this.$route.fullPath;

+ 12 - 1
client/components/Reader/SettingsPage/include/OthersTab.inc

@@ -36,7 +36,18 @@
         Показывать уведомление "Что нового"
         Показывать уведомление "Что нового"
         <q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
         <q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
             Показывать уведомления "Что нового"<br>
             Показывать уведомления "Что нового"<br>
-            при каждом выходе новой версии читалки
+            при появлении новой версии читалки
+        </q-tooltip>
+    </q-checkbox>
+</div>
+
+<div class="item row">
+    <div class="label-6">Уведомление</div>
+    <q-checkbox size="xs" v-model="showNeedUpdateNotify">
+        Показывать уведомление о новой версии
+        <q-tooltip :delay="1000" anchor="top middle" self="bottom middle" content-style="font-size: 80%">
+            Напоминать о необходимости обновления страницы<br>
+            при появлении новой версии читалки
         </q-tooltip>
         </q-tooltip>
     </q-checkbox>
     </q-checkbox>
 </div>
 </div>

+ 1 - 12
client/store/modules/config.js

@@ -10,18 +10,7 @@ const state = {
 const getters = {};
 const getters = {};
 
 
 // actions
 // 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
 // mutations
 const mutations = {
 const mutations = {

+ 3 - 1
client/store/modules/reader.js

@@ -251,11 +251,13 @@ const settingDefaults = {
     compactTextPerc: 0,
     compactTextPerc: 0,
     imageHeightLines: 100,
     imageHeightLines: 100,
     imageFitWidth: true,
     imageFitWidth: true,
+    enableSitesFilter: true,
+
     showServerStorageMessages: true,
     showServerStorageMessages: true,
     showWhatsNewDialog: true,
     showWhatsNewDialog: true,
     showDonationDialog2020: true,
     showDonationDialog2020: true,
     showLiberamaTopDialog2020: true,
     showLiberamaTopDialog2020: true,
-    enableSitesFilter: true,
+    showNeedUpdateNotify: true,
 
 
     fontShifts: {},
     fontShifts: {},
     showToolButton: {},
     showToolButton: {},