aboutsummaryrefslogtreecommitdiff
path: root/ext/fg/js/popup.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.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.js')
-rw-r--r--ext/fg/js/popup.js33
1 files changed, 19 insertions, 14 deletions
diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js
index 281913c6..22672706 100644
--- a/ext/fg/js/popup.js
+++ b/ext/fg/js/popup.js
@@ -97,7 +97,7 @@ class Popup {
this._options = await api.optionsGet(optionsContext);
this.updateTheme();
- this._invokeApi('setOptionsContext', {optionsContext});
+ this._invokeSafe('setOptionsContext', {optionsContext});
}
hide(changeFocus) {
@@ -146,25 +146,21 @@ class Popup {
}
if (displayDetails !== null) {
- this._invokeApi('setContent', {details: displayDetails});
+ this._invokeSafe('setContent', {details: displayDetails});
}
}
setCustomCss(css) {
- this._invokeApi('setCustomCss', {css});
+ this._invokeSafe('setCustomCss', {css});
}
- async clearAutoPlayTimer() {
- try {
- await this._invokeApi('clearAutoPlayTimer');
- } catch (e) {
- // NOP
- }
+ clearAutoPlayTimer() {
+ this._invokeSafe('clearAutoPlayTimer');
}
setContentScale(scale) {
this._contentScale = scale;
- this._invokeApi('setContentScale', {scale});
+ this._invokeSafe('setContentScale', {scale});
}
// Popup-only public functions
@@ -266,7 +262,7 @@ class Popup {
await frameClient.connect(this._frame, this._targetOrigin, this._frameId, setupFrame);
// Configure
- await this._invokeApi('configure', {
+ await this._invokeSafe('configure', {
frameId: this._frameId,
ownerFrameId: this._ownerFrameId,
popupId: this._id,
@@ -448,7 +444,7 @@ class Popup {
return dark ? 'dark' : 'light';
}
- async _invokeApi(action, params={}) {
+ async _invoke(action, params={}) {
const contentWindow = this._frame.contentWindow;
if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; }
@@ -456,7 +452,16 @@ class Popup {
return await api.crossFrame.invoke(this._frameClient.frameId, 'popupMessage', message);
}
- _invokeWindowApi(action, params={}) {
+ async _invokeSafe(action, params={}, defaultReturnValue) {
+ try {
+ return await this._invoke(action, params);
+ } catch (e) {
+ if (!yomichan.isExtensionUnloaded) { throw e; }
+ return defaultReturnValue;
+ }
+ }
+
+ _invokeWindow(action, params={}) {
const contentWindow = this._frame.contentWindow;
if (this._frameClient === null || !this._frameClient.isConnected() || contentWindow === null) { return; }
@@ -465,7 +470,7 @@ class Popup {
}
_onExtensionUnloaded() {
- this._invokeWindowApi('extensionUnloaded');
+ this._invokeWindow('extensionUnloaded');
}
_getFrameParentElement() {