diff --git a/client/components/Reader/Reader.vue b/client/components/Reader/Reader.vue index a20f8483..ca4c3a7b 100644 --- a/client/components/Reader/Reader.vue +++ b/client/components/Reader/Reader.vue @@ -197,6 +197,12 @@ class Reader extends Vue { } }, 500); + this.debouncedSaveRecent = _.debounce(async() => { + const serverStorage = this.$refs.serverStorage; + while (!serverStorage.inited) await utils.sleep(1000); + await serverStorage.saveRecent(); + }, 1000); + document.addEventListener('fullscreenchange', () => { this.fullScreenActive = (document.fullscreenElement !== null); }); @@ -303,7 +309,7 @@ class Reader extends Vue { await this.loadBook(newBook); } - await serverStorage.saveRecent(); + this.debouncedSaveRecent(); })(); } } diff --git a/client/components/Reader/ServerStorage/ServerStorage.vue b/client/components/Reader/ServerStorage/ServerStorage.vue index f4ea2a3f..7f5ebdc0 100644 --- a/client/components/Reader/ServerStorage/ServerStorage.vue +++ b/client/components/Reader/ServerStorage/ServerStorage.vue @@ -36,6 +36,7 @@ export default @Component({ }) class ServerStorage extends Vue { created() { + this.inited = false; this.commit = this.$store.commit; this.prevServerStorageKey = null; this.$root.$on('generateNewServerStorageKey', () => {this.generateNewServerStorageKey()}); @@ -50,14 +51,18 @@ class ServerStorage extends Vue { } async init() { - if (!this.serverStorageKey) { - //генерируем новый ключ - await this.generateNewServerStorageKey(); - } else { - await this.serverStorageKeyChanged(); + try { + if (!this.serverStorageKey) { + //генерируем новый ключ + await this.generateNewServerStorageKey(); + } else { + await this.serverStorageKeyChanged(); + } + await this.currentProfileChanged(); + await this.loadRecent(); + } finally { + this.inited = true; } - await this.currentProfileChanged(); - await this.loadRecent(); } async generateNewServerStorageKey() {