From bc21ace416945f331d1a9ac0a460770811b6e4a2 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Thu, 29 Oct 2020 15:14:27 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B4=20LibsPage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/ExternalLibs/ExternalLibs.vue | 25 +++++++++++++------ .../components/Reader/LibsPage/LibsPage.vue | 10 +++----- client/store/modules/reader.js | 1 + 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/client/components/ExternalLibs/ExternalLibs.vue b/client/components/ExternalLibs/ExternalLibs.vue index 9866e51d..310dbe77 100644 --- a/client/components/ExternalLibs/ExternalLibs.vue +++ b/client/components/ExternalLibs/ExternalLibs.vue @@ -125,10 +125,7 @@ class ExternalLibs extends Vue { } while(this.opener) { - if (this.opener.closed) { - await this.$root.stdDialog.alert('Потеряна связь с читалкой. Окно будет закрыто', 'Ошибка'); - window.close(); - } + await this.checkOpener(); await utils.sleep(1000); } })(); @@ -143,12 +140,24 @@ class ExternalLibs extends Vue { this.ready = true; this.libs = _.cloneDeep(d.data); this.goToStartLink(); + } else if (d.type == 'notify') { + this.$root.notify.success(d.data); } } sendMessage(d) { - if (this.opener && this.openerOrigin) - this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin); + (async() => { + await this.checkOpener(); + if (this.opener && this.openerOrigin) + this.opener.postMessage(Object.assign({}, {from: 'ExternalLibs'}, d), this.openerOrigin); + })(); + } + + async checkOpener() { + if (this.opener.closed) { + await this.$root.stdDialog.alert('Потеряна связь с читалкой. Окно будет закрыто', 'Ошибка'); + window.close(); + } } commitLibs(libs) { @@ -283,8 +292,10 @@ class ExternalLibs extends Vue { submitUrl() { if (this.bookUrl) { - this.$emit('load-book', {url: this.addProtocol(this.bookUrl), force: true}); + this.sendMessage({type: 'submitUrl', data: {url: this.addProtocol(this.bookUrl), force: true}}); this.bookUrl = ''; + if (this.libs.closeAfterSubmit) + this.close(); } } diff --git a/client/components/Reader/LibsPage/LibsPage.vue b/client/components/Reader/LibsPage/LibsPage.vue index 88b2b36d..2e86195c 100644 --- a/client/components/Reader/LibsPage/LibsPage.vue +++ b/client/components/Reader/LibsPage/LibsPage.vue @@ -81,6 +81,9 @@ class LibsPage extends Vue { this.commit('reader/setLibs', d.data); } else if (d.type == 'close') { this.close(); + } else if (d.type == 'submitUrl') { + this.$emit('load-book', d.data); + this.sendMessage({type: 'notify', data: 'Ссылка передана в читалку'}); } } @@ -105,13 +108,6 @@ class LibsPage extends Vue { this.sendMessage({type: 'libs', data: this.libs}); } -/* submitUrl() { - if (this.bookUrl) { - this.$emit('load-book', {url: this.addProtocol(this.bookUrl), force: true}); - this.bookUrl = ''; - } - }*/ - close() { this.$emit('libs-close'); } diff --git a/client/store/modules/reader.js b/client/store/modules/reader.js index 35a20344..2501959a 100644 --- a/client/store/modules/reader.js +++ b/client/store/modules/reader.js @@ -256,6 +256,7 @@ const settingDefaults = { const libsDefaults = { startLink: 'http://flibusta.is', comment: 'Флибуста | Книжное братство', + closeAfterSubmit: false, groups: [ {r: 'http://flibusta.is', s: 'http://flibusta.is', list: [ {l: 'http://flibusta.is', c: 'Флибуста | Книжное братство'},