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: 'Флибуста | Книжное братство'},