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..19611658 100644
--- a/client/components/ExternalLibs/ExternalLibs.vue
+++ b/client/components/ExternalLibs/ExternalLibs.vue
@@ -23,8 +23,8 @@
Добавить закладку
-
- Настроить закладки (пока недоступно)
+
+ Настроить закладки
@@ -97,6 +97,7 @@
+
@@ -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/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/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});
});
}
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({
})
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 {
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;
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,