diff options
Diffstat (limited to 'ext/fg/js')
| -rw-r--r-- | ext/fg/js/frontend-api-sender.js | 14 | ||||
| -rw-r--r-- | ext/fg/js/popup-proxy-host.js | 6 | ||||
| -rw-r--r-- | ext/fg/js/popup.js | 7 | 
3 files changed, 22 insertions, 5 deletions
| diff --git a/ext/fg/js/frontend-api-sender.js b/ext/fg/js/frontend-api-sender.js index a1cb02c4..2e037e62 100644 --- a/ext/fg/js/frontend-api-sender.js +++ b/ext/fg/js/frontend-api-sender.js @@ -26,9 +26,7 @@ class FrontendApiSender {          this.disconnected = false;          this.nextId = 0; -        this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); -        this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); -        this.port.onMessage.addListener(this.onMessage.bind(this)); +        this.port = null;      }      invoke(action, params, target) { @@ -36,6 +34,10 @@ class FrontendApiSender {              return Promise.reject('Disconnected');          } +        if (this.port === null) { +            this.createPort(); +        } +          const id = `${this.nextId}`;          ++this.nextId; @@ -48,6 +50,12 @@ class FrontendApiSender {          });      } +    createPort() { +        this.port = chrome.runtime.connect(null, {name: 'backend-api-forwarder'}); +        this.port.onDisconnect.addListener(this.onDisconnect.bind(this)); +        this.port.onMessage.addListener(this.onMessage.bind(this)); +    } +      onMessage({type, id, data, senderId}) {          if (senderId !== this.senderId) { return; }          switch (type) { diff --git a/ext/fg/js/popup-proxy-host.js b/ext/fg/js/popup-proxy-host.js index 041900ed..1f14a06f 100644 --- a/ext/fg/js/popup-proxy-host.js +++ b/ext/fg/js/popup-proxy-host.js @@ -116,12 +116,14 @@ class PopupProxyHost {      async termsShow(id, elementRect, writingMode, definitions, options, context) {          const popup = this.getPopup(id);          elementRect = this.jsonRectToDOMRect(popup, elementRect); +        if (!PopupProxyHost.popupCanShow(popup)) { return false; }          return await popup.termsShow(elementRect, writingMode, definitions, options, context);      }      async kanjiShow(id, elementRect, writingMode, definitions, options, context) {          const popup = this.getPopup(id);          elementRect = this.jsonRectToDOMRect(popup, elementRect); +        if (!PopupProxyHost.popupCanShow(popup)) { return false; }          return await popup.kanjiShow(elementRect, writingMode, definitions, options, context);      } @@ -129,6 +131,10 @@ class PopupProxyHost {          const popup = this.getPopup(id);          return popup.clearAutoPlayTimer();      } + +    static popupCanShow(popup) { +        return popup.parent === null || popup.parent.isVisible(); +    }  }  PopupProxyHost.instance = PopupProxyHost.create(); diff --git a/ext/fg/js/popup.js b/ext/fg/js/popup.js index 1b15977b..08c4bfcb 100644 --- a/ext/fg/js/popup.js +++ b/ext/fg/js/popup.js @@ -239,9 +239,12 @@ class Popup {      }      focusParent() { -        if (this.parent && this.parent.container) { +        if (this.parent !== null) {              // Chrome doesn't like focusing iframe without contentWindow. -            this.parent.container.contentWindow.focus(); +            const contentWindow = this.parent.container.contentWindow; +            if (contentWindow !== null) { +                contentWindow.focus(); +            }          } else {              // Firefox doesn't like focusing window without first blurring the iframe.              // this.container.contentWindow.blur() doesn't work on Firefox for some reason. |