From a63602df7a85b120487d6ee31410643f4364f0ef Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 2 Nov 2020 14:33:15 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B1=D0=B0=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Reader/SettingsPage/SettingsPage.vue | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/client/components/Reader/SettingsPage/SettingsPage.vue b/client/components/Reader/SettingsPage/SettingsPage.vue index 65b805e9..c926be16 100644 --- a/client/components/Reader/SettingsPage/SettingsPage.vue +++ b/client/components/Reader/SettingsPage/SettingsPage.vue @@ -108,8 +108,10 @@ export default @Component({ }, vertShift: function(newValue) { const font = (this.webFontName ? this.webFontName : this.fontName); - this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue}); - this.fontVertShift = newValue; + if (this.fontShifts[font] != newValue) { + this.fontShifts = Object.assign({}, this.fontShifts, {[font]: newValue}); + this.fontVertShift = newValue; + } }, fontName: function(newValue) { const font = (this.webFontName ? this.webFontName : newValue); @@ -185,10 +187,18 @@ class SettingsPage extends Vue { settingsChanged() { if (_.isEqual(this.form, this.settings)) return; + this.form = Object.assign({}, this.settings); + if (!this.unwatch) + this.unwatch = {}; + for (let prop in rstore.settingDefaults) { + if (this.unwatch && this.unwatch[prop]) + this.unwatch[prop](); + this[prop] = this.form[prop]; - this.$watch(prop, (newValue) => { + + this.unwatch[prop] = this.$watch(prop, (newValue) => { this.form = Object.assign({}, this.form, {[prop]: newValue}); }); } From bbdba0ef16857b079be4953941df8f14cfd65d85 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 2 Nov 2020 23:45:59 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=BF=D0=BE=20=D1=80=D0=B5=D0=B7=D1=83=D0=BB=D1=8C?= =?UTF-8?q?=D1=82=D0=B0=D1=82=D1=83=20=D1=82=D0=B5=D1=81=D1=82=D0=B8=D1=80?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/share/utils.js | 66 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/client/share/utils.js b/client/share/utils.js index 5af01b6a..0dd69976 100644 --- a/client/share/utils.js +++ b/client/share/utils.js @@ -130,20 +130,53 @@ export function getObjDiff(oldObj, newObj) { } export function isObjDiff(diff) { - return (_.isObject(diff) && diff.__isDiff); + return (_.isObject(diff) && diff.__isDiff && diff.change && diff.add && diff.del); } export function isEmptyObjDiff(diff) { - return (!_.isObject(diff) || !diff.__isDiff || - (!Object.keys(diff.change).length && - !Object.keys(diff.add).length && - !diff.del.length + return (!isObjDiff(diff) || + !(Object.keys(diff.change).length || + Object.keys(diff.add).length || + diff.del.length ) ); } -export function applyObjDiff(obj, diff, isAddChanged) { - const result = _.cloneDeep(obj); +export function isEmptyObjDiffDeep(diff, opts = {}) { + if (!isObjDiff(diff)) + return true; + + const { + isApplyChange = true, + isApplyAdd = true, + isApplyDel = true, + } = opts; + + let notEmptyDeep = false; + const change = diff.change; + for (const key of Object.keys(change)) { + if (_.isObject(change[key])) + notEmptyDeep |= !isEmptyObjDiffDeep(change[key], opts); + else if (isApplyChange) + notEmptyDeep = true; + } + + return !( + notEmptyDeep || + (isApplyAdd && Object.keys(diff.add).length) || + (isApplyDel && diff.del.length) + ); +} + +export function applyObjDiff(obj, diff, opts = {}) { + const { + isAddChanged = false, + isApplyChange = true, + isApplyAdd = true, + isApplyDel = true, + } = opts; + + let result = _.cloneDeep(obj); if (!diff.__isDiff) return result; @@ -151,21 +184,28 @@ export function applyObjDiff(obj, diff, isAddChanged) { for (const key of Object.keys(change)) { if (result.hasOwnProperty(key)) { if (_.isObject(change[key])) { - result[key] = applyObjDiff(result[key], change[key], isAddChanged); + result[key] = applyObjDiff(result[key], change[key], opts); } else { - result[key] = _.cloneDeep(change[key]); + if (isApplyChange) + result[key] = _.cloneDeep(change[key]); } } else if (isAddChanged) { result[key] = _.cloneDeep(change[key]); } } - for (const key of Object.keys(diff.add)) { - result[key] = _.cloneDeep(diff.add[key]); + if (isApplyAdd) { + for (const key of Object.keys(diff.add)) { + result[key] = _.cloneDeep(diff.add[key]); + } } - for (const key of diff.del) { - delete result[key]; + if (isApplyDel && diff.del.length) { + for (const key of diff.del) { + delete result[key]; + } + if (_.isArray(result)) + result = result.filter(v => v); } return result; From fdf50099997e29bbc73266c85cf52f449565ba7d Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Mon, 2 Nov 2020 23:51:41 +0700 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9C=D0=B5=D0=BB=D0=BA=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/share/Dialog.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/share/Dialog.vue b/client/components/share/Dialog.vue index bf2b87df..d7ace375 100644 --- a/client/components/share/Dialog.vue +++ b/client/components/share/Dialog.vue @@ -32,7 +32,7 @@ const DialogProps = Vue.extend({ props: { value: Boolean, } -}) +}); export default @Component({ }) From 8b66fd522da4ddc4ea6d588dea08750b91d13261 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 3 Nov 2020 00:00:31 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=20=D0=B2=D0=BE=D1=81=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B4=D0=B5=D1=84=D0=BE?= =?UTF-8?q?=D0=BB=D1=82=D0=BD=D1=8B=D1=85=20=D0=BD=D0=B0=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=BE=D0=B5=D0=BA=20=D0=B2=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA?= =?UTF-8?q?=D1=82=D0=B5=20settings=20=D0=BF=D1=80=D0=B8=20=D0=B8=D1=85=20?= =?UTF-8?q?=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/Reader/Reader.vue | 6 +++ .../Reader/ServerStorage/ServerStorage.vue | 4 +- client/store/modules/reader.js | 39 ++++++++++++++----- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index b557e880..c3a6fdf2 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -331,6 +331,12 @@ class Reader extends Vue { this.checkActivateDonateHelpPage(); this.loading = false; + //проверим состояние Settings, и обновим, если надо + const newSettings = rstore.addDefaultsToSettings(this.settings); + if (newSettings) { + this.commit('reader/setSettings', newSettings); + } + this.updateRoute(); await this.showWhatsNew(); diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index b6092ddb..7a17af30 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -505,7 +505,7 @@ class ServerStorage extends Vue { const md = newRecentMod.data; if (md.key && result[md.key]) - result[md.key] = utils.applyObjDiff(result[md.key], md.mod, true); + result[md.key] = utils.applyObjDiff(result[md.key], md.mod, {isAddChanged: true}); if (!bookManager.loaded) { this.warning('Ожидание загрузки списка книг перед синхронизацией'); @@ -569,7 +569,7 @@ class ServerStorage extends Vue { let applyMod = this.cachedRecentMod.data; if (applyMod && applyMod.key && newRecentPatch.data[applyMod.key]) - newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod, true); + newRecentPatch.data[applyMod.key] = utils.applyObjDiff(newRecentPatch.data[applyMod.key], applyMod.mod, {isAddChanged: true}); newRecentMod = {rev: this.cachedRecentMod.rev + 1, data: {}}; needSaveRecentPatch = true; diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index d75aa62b..a120851f 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -1,3 +1,5 @@ +import * as utils from '../../share/utils'; + const readerActions = { 'help': 'Вызвать cправку', 'loader': 'На страницу загрузки', @@ -256,6 +258,25 @@ const settingDefaults = { userHotKeys: {}, }; +for (const font of fonts) + settingDefaults.fontShifts[font.name] = font.fontVertShift; +for (const font of webFonts) + settingDefaults.fontShifts[font.name] = font.fontVertShift; +for (const button of toolButtons) + settingDefaults.showToolButton[button.name] = button.show; +for (const hotKey of hotKeys) + settingDefaults.userHotKeys[hotKey.name] = hotKey.codes; + +function addDefaultsToSettings(settings) { + const diff = utils.getObjDiff(settings, settingDefaults); + + if (!utils.isEmptyObjDiffDeep(diff, {isApplyChange: false})) { + return utils.applyObjDiff(settings, diff, {isApplyChange: false}); + } + + return false; +} + const libsDefaults = { startLink: 'http://flibusta.is', comment: 'Флибуста | Книжное братство', @@ -279,15 +300,6 @@ const libsDefaults = { ] }; -for (const font of fonts) - settingDefaults.fontShifts[font.name] = font.fontVertShift; -for (const font of webFonts) - settingDefaults.fontShifts[font.name] = font.fontVertShift; -for (const button of toolButtons) - settingDefaults.showToolButton[button.name] = button.show; -for (const hotKey of hotKeys) - settingDefaults.userHotKeys[hotKey.name] = hotKey.codes; - // initial state const state = { toolBarActive: true, @@ -341,7 +353,13 @@ const mutations = { state.currentProfile = value; }, setSettings(state, value) { - state.settings = Object.assign({}, state.settings, value); + const newSettings = Object.assign({}, state.settings, value); + const added = addDefaultsToSettings(newSettings); + if (added) { + state.settings = added; + } else { + state.settings = newSettings; + } }, setSettingsRev(state, value) { state.settingsRev = Object.assign({}, state.settingsRev, value); @@ -361,6 +379,7 @@ export default { fonts, webFonts, settingDefaults, + addDefaultsToSettings, libsDefaults, namespaced: true, From 213f7e48c9476e8a69c32544be6f6bd92e3a51e7 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 3 Nov 2020 00:26:25 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=B4=20BookmarkSettings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookmarkSettings/BookmarkSettings.vue | 59 +++++++++++++++++++ .../components/ExternalLibs/ExternalLibs.vue | 37 ++++++++---- client/components/share/Window.vue | 1 + 3 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue diff --git a/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue b/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue new file mode 100644 index 00000000..97653dd7 --- /dev/null +++ b/client/components/ExternalLibs/BookmarkSettings/BookmarkSettings.vue @@ -0,0 +1,59 @@ + + + + + diff --git a/client/components/ExternalLibs/ExternalLibs.vue b/client/components/ExternalLibs/ExternalLibs.vue index 2b587acc..1baa4c28 100644 --- a/client/components/ExternalLibs/ExternalLibs.vue +++ b/client/components/ExternalLibs/ExternalLibs.vue @@ -23,8 +23,8 @@ Добавить закладку - - Настроить закладки (пока недоступно) + + Настроить закладки + @@ -108,6 +109,8 @@ import _ from 'lodash'; import Window from '../share/Window.vue'; import Dialog from '../share/Dialog.vue'; +import BookmarkSettings from './BookmarkSettings/BookmarkSettings.vue'; + import rstore from '../../store/modules/reader'; import * as utils from '../../share/utils'; @@ -118,7 +121,8 @@ const proxySubst = { export default @Component({ components: { Window, - Dialog + Dialog, + BookmarkSettings }, watch: { libs: function() { @@ -153,6 +157,8 @@ class ExternalLibs extends Vue { bookmarkDesc = ''; defaultRootLink = ''; + bookmarkSettingsActive = false; + created() { this.$root.addKeyHook(this.keyHook); @@ -549,9 +555,6 @@ class ExternalLibs extends Vue { this.addBookmarkVisible = false; } - bookmarkSettings() { - } - fullScreenToggle() { this.fullScreenActive = !this.fullScreenActive; if (this.fullScreenActive) { @@ -584,14 +587,28 @@ class ExternalLibs extends Vue { } } - keyHook() { + bookmarkSettings() { + this.bookmarkSettingsActive = true; + this.$nextTick(() => { + this.$refs.bookmarkSettings.init(); + }); + } + + closeBookmarkSettings() { + this.bookmarkSettingsActive = false; + } + + keyHook(event) { if (this.$root.rootRoute() == '/external-libs') { + if (this.bookmarkSettingsActive && this.$refs.bookmarkSettings.keyHook(event)) + return true; + if (this.$refs.dialogAddBookmark.active) return false; if (event.type == 'keydown' && event.key == 'F4') { - this.addBookmark() - return; + this.addBookmark(); + return true; } if (event.type == 'keydown' && event.key == 'Escape' && @@ -599,8 +616,8 @@ class ExternalLibs extends Vue { (document.activeElement != this.$refs.selectedLink.$refs.target || !this.$refs.selectedLink.menu) ) { this.close(); + return true; } - return true; } return false; } diff --git a/client/components/share/Window.vue b/client/components/share/Window.vue index 8805d119..98c816cc 100644 --- a/client/components/share/Window.vue +++ b/client/components/share/Window.vue @@ -124,6 +124,7 @@ class Window extends Vue { .main { background-color: transparent !important; z-index: 50; + overflow: hidden; } .xyfit { From 3ca0a9244293e99d8a1cbf2feb6789a2b466ea71 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Tue, 3 Nov 2020 00:28:15 +0700 Subject: [PATCH 6/6] =?UTF-8?q?=D0=92=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=BE=D1=82=D0=BA=D0=BB=D1=8E=D1=87=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D1=83=20"=D0=9D=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B8=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D0=B4=D0=BA=D0=B8"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/components/ExternalLibs/ExternalLibs.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/components/ExternalLibs/ExternalLibs.vue b/client/components/ExternalLibs/ExternalLibs.vue index 1baa4c28..19611658 100644 --- a/client/components/ExternalLibs/ExternalLibs.vue +++ b/client/components/ExternalLibs/ExternalLibs.vue @@ -23,7 +23,7 @@ Добавить закладку - + Настроить закладки