From dac33e696145ad3c2cfe076a7fadc82c05732102 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 18 Jul 2020 14:15:36 -0400 Subject: Extension unload indication fix (#662) * Remove unused function * Rename field * Change extensionUnloaded trigger function * Update how extension unloaded content is shown * Ignore certain errors caused by extension unload * Add _showExtensionUnloaded function * Wrap internals of updateOptions * Suppress errors caued by extension unload * Make the frontend trigger the popup's extensionUnloaded event --- ext/mixed/js/display.js | 15 +++++++-------- ext/mixed/js/yomichan.js | 12 ++++++------ 2 files changed, 13 insertions(+), 14 deletions(-) (limited to 'ext/mixed/js') diff --git a/ext/mixed/js/display.js b/ext/mixed/js/display.js index 7dc63e65..bf3e3eae 100644 --- a/ext/mixed/js/display.js +++ b/ext/mixed/js/display.js @@ -97,14 +97,12 @@ class Display { this._setInteractive(true); await yomichan.ready(); await this._displayGenerator.prepare(); + yomichan.on('extensionUnloaded', this._onExtensionUnloaded.bind(this)); } onError(error) { - if (yomichan.isExtensionUnloaded) { - this.setContent('extensionUnloaded'); - } else { - yomichan.logError(error); - } + if (yomichan.isExtensionUnloaded) { return; } + yomichan.logError(error); } onEscape() { @@ -176,9 +174,6 @@ class Display { case 'kanji': await this._setContentKanji(details.definitions, details.context, token); break; - case 'extensionUnloaded': - this._setContentExtensionUnloaded(); - break; } } catch (e) { this.onError(e); @@ -236,6 +231,10 @@ class Display { // Private + _onExtensionUnloaded() { + this._setContentExtensionUnloaded(); + } + _onSourceTermView(e) { e.preventDefault(); this._sourceTermView(); diff --git a/ext/mixed/js/yomichan.js b/ext/mixed/js/yomichan.js index 7fffbaa6..33870658 100644 --- a/ext/mixed/js/yomichan.js +++ b/ext/mixed/js/yomichan.js @@ -196,7 +196,7 @@ const yomichan = (() => { try { return chrome.runtime.sendMessage(...args); } catch (e) { - this._onExtensionUnloaded(e); + this.triggerExtensionUnloaded(); throw e; } } @@ -205,7 +205,7 @@ const yomichan = (() => { try { return chrome.runtime.connect(...args); } catch (e) { - this._onExtensionUnloaded(e); + this.triggerExtensionUnloaded(); throw e; } } @@ -247,13 +247,13 @@ const yomichan = (() => { } } - // Private - - _onExtensionUnloaded(error) { + triggerExtensionUnloaded() { this._isExtensionUnloaded = true; - this.trigger('extensionUnloaded', {error}); + this.trigger('extensionUnloaded'); } + // Private + _getUrl() { return (typeof window === 'object' && window !== null ? window.location.href : ''); } -- cgit v1.2.3