summaryrefslogtreecommitdiff
path: root/ext/fg/js/float.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-07-18 14:15:36 -0400
committerGitHub <noreply@github.com>2020-07-18 14:15:36 -0400
commitdac33e696145ad3c2cfe076a7fadc82c05732102 (patch)
tree06dff8bd7dd2d8ebad5a025cf71e2910b2af80d4 /ext/fg/js/float.js
parentf9c76efea00ff62021119c4d0fcf414e8988be1d (diff)
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
Diffstat (limited to 'ext/fg/js/float.js')
-rw-r--r--ext/fg/js/float.js25
1 files changed, 23 insertions, 2 deletions
diff --git a/ext/fg/js/float.js b/ext/fg/js/float.js
index 61d42fb3..690d1b9e 100644
--- a/ext/fg/js/float.js
+++ b/ext/fg/js/float.js
@@ -31,7 +31,7 @@ class DisplayFloat extends Display {
this._nestedPopupsPrepared = false;
this._ownerFrameId = null;
this._frameEndpoint = new FrameEndpoint();
- this._windowMessageHandlers = new Map([
+ this._messageHandlers = new Map([
['configure', {async: true, handler: this._onMessageConfigure.bind(this)}],
['setOptionsContext', {async: false, handler: this._onMessageSetOptionsContext.bind(this)}],
['setContent', {async: false, handler: this._onMessageSetContent.bind(this)}],
@@ -39,6 +39,9 @@ class DisplayFloat extends Display {
['setCustomCss', {async: false, handler: this._onMessageSetCustomCss.bind(this)}],
['setContentScale', {async: false, handler: this._onMessageSetContentScale.bind(this)}]
]);
+ this._windowMessageHandlers = new Map([
+ ['extensionUnloaded', {async: false, handler: this._onMessageExtensionUnloaded.bind(this)}]
+ ]);
this.registerActions([
['copy-host-selection', () => this._copySelection()]
@@ -54,6 +57,7 @@ class DisplayFloat extends Display {
api.crossFrame.registerHandlers([
['popupMessage', {async: 'dynamic', handler: this._onMessage.bind(this)}]
]);
+ window.addEventListener('message', this._onWindowMessage.bind(this), false);
this._frameEndpoint.signal();
}
@@ -107,7 +111,7 @@ class DisplayFloat extends Display {
}
const {action, params} = data.data;
- const handlerInfo = this._windowMessageHandlers.get(action);
+ const handlerInfo = this._messageHandlers.get(action);
if (typeof handlerInfo === 'undefined') {
throw new Error(`Invalid action: ${action}`);
}
@@ -117,6 +121,18 @@ class DisplayFloat extends Display {
return {async, result};
}
+ _onWindowMessage(e) {
+ const data = e.data;
+ if (!this._frameEndpoint.authenticate(data)) { return; }
+
+ const {action, params} = data.data;
+ const messageHandler = this._windowMessageHandlers.get(action);
+ if (typeof messageHandler === 'undefined') { return; }
+
+ const callback = () => {}; // NOP
+ yomichan.invokeMessageHandler(messageHandler, params, callback);
+ }
+
async _onMessageConfigure({frameId, ownerFrameId, popupId, optionsContext, childrenSupported, scale}) {
this._ownerFrameId = ownerFrameId;
this.setOptionsContext(optionsContext);
@@ -152,6 +168,11 @@ class DisplayFloat extends Display {
this._setContentScale(scale);
}
+ _onMessageExtensionUnloaded() {
+ if (yomichan.isExtensionUnloaded) { return; }
+ yomichan.triggerExtensionUnloaded();
+ }
+
// Private
_copySelection() {