aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup-proxy.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-08-02 21:51:51 -0400
committerGitHub <noreply@github.com>2020-08-02 21:51:51 -0400
commitb253cdc92e38e960a6256f8aad730624c37d2a1b (patch)
tree9709cc6ad507e4f2000c9c3bef2e8c15fe7ad2c2 /ext/fg/js/popup-proxy.js
parenta81d69d6c12a383664a92acb40c1c365b2425ca5 (diff)
Fix extension unload cases (#712)
* Add _invokeSafe function to silently ignore extension unload errors * Remove "Api" from function names * Add invokeSafe to Popup * Don't redundantly set content type to 'unloaded'
Diffstat (limited to 'ext/fg/js/popup-proxy.js')
-rw-r--r--ext/fg/js/popup-proxy.js41
1 files changed, 21 insertions, 20 deletions
diff --git a/ext/fg/js/popup-proxy.js b/ext/fg/js/popup-proxy.js
index d910d30c..b4438f80 100644
--- a/ext/fg/js/popup-proxy.js
+++ b/ext/fg/js/popup-proxy.js
@@ -60,24 +60,20 @@ class PopupProxy extends EventDispatcher {
return true;
}
- async setOptionsContext(optionsContext, source) {
- return await this._invoke('setOptionsContext', {id: this._id, optionsContext, source});
+ setOptionsContext(optionsContext, source) {
+ return this._invokeSafe('setOptionsContext', {id: this._id, optionsContext, source});
}
hide(changeFocus) {
- this._invoke('hide', {id: this._id, changeFocus});
+ return this._invokeSafe('hide', {id: this._id, changeFocus});
}
- async isVisible() {
- try {
- return await this._invoke('isVisible', {id: this._id});
- } catch (e) {
- return false;
- }
+ isVisible() {
+ return this._invokeSafe('isVisible', {id: this._id}, false);
}
setVisibleOverride(visible) {
- this._invoke('setVisibleOverride', {id: this._id, visible});
+ return this._invokeSafe('setVisibleOverride', {id: this._id, visible});
}
async containsPoint(x, y) {
@@ -85,7 +81,7 @@ class PopupProxy extends EventDispatcher {
await this._updateFrameOffset();
[x, y] = this._applyFrameOffset(x, y);
}
- return await this._invoke('containsPoint', {id: this._id, x, y});
+ return await this._invokeSafe('containsPoint', {id: this._id, x, y}, false);
}
async showContent(details, displayDetails) {
@@ -98,23 +94,19 @@ class PopupProxy extends EventDispatcher {
}
details.elementRect = {x, y, width, height};
}
- return await this._invoke('showContent', {id: this._id, details, displayDetails});
+ return await this._invokeSafe('showContent', {id: this._id, details, displayDetails});
}
setCustomCss(css) {
- this._invoke('setCustomCss', {id: this._id, css});
+ return this._invokeSafe('setCustomCss', {id: this._id, css});
}
- async clearAutoPlayTimer() {
- try {
- await this._invoke('clearAutoPlayTimer', {id: this._id});
- } catch (e) {
- // NOP
- }
+ clearAutoPlayTimer() {
+ return this._invokeSafe('clearAutoPlayTimer', {id: this._id});
}
setContentScale(scale) {
- this._invoke('setContentScale', {id: this._id, scale});
+ return this._invokeSafe('setContentScale', {id: this._id, scale});
}
// Private
@@ -123,6 +115,15 @@ class PopupProxy extends EventDispatcher {
return api.crossFrame.invoke(this._parentFrameId, action, params);
}
+ async _invokeSafe(action, params={}, defaultReturnValue) {
+ try {
+ return await this._invoke(action, params);
+ } catch (e) {
+ if (!yomichan.isExtensionUnloaded) { throw e; }
+ return defaultReturnValue;
+ }
+ }
+
async _updateFrameOffset() {
const now = Date.now();
const firstRun = this._frameOffsetUpdatedAt === null;