From 528c8ea57790738564cf42b6fb499bdfd7f2e78a Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 11 Dec 2019 13:02:10 +0100 Subject: Fixed shortcut and context menu doing nothing unless browserAction icon is visible on Firefox (issue #58). --- src/bg/main.js | 20 ++++++++++++-------- src/bg/popupHandler.js | 2 ++ src/ui/popup.js | 3 +-- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/bg/main.js b/src/bg/main.js index 6e2cdf9..fa58b3a 100644 --- a/src/bg/main.js +++ b/src/bg/main.js @@ -54,19 +54,23 @@ }; let Commands = { - openPageUI() { + async openPageUI() { + if (ns.popupOpening) return; + ns.popupOpening = true; + ns.popupOpened = false; + let openPanel = async () => { + ns.popupOpening = false; + if (ns.popupOpened) return; + messageHandler.openStandalonePopup(); + }; try { - browser.browserAction.openPopup(); + await browser.browserAction.openPopup(); + setTimeout(openPanel, 500); return; } catch (e) { + openPanel(); debug(e); } - browser.windows.create({ - url: popupURL, - width: 800, - height: 600, - type: "panel" - }); }, togglePermissions() {}, diff --git a/src/bg/popupHandler.js b/src/bg/popupHandler.js index b893174..f5c2049 100644 --- a/src/bg/popupHandler.js +++ b/src/bg/popupHandler.js @@ -1,5 +1,6 @@ browser.runtime.onConnect.addListener(port => { if (port.name === "noscript.popup") { + ns.popupOpened = true; let pendingReload = false; let tabId = -1; port.onMessage.addListener(m => { @@ -9,6 +10,7 @@ browser.runtime.onConnect.addListener(port => { } }); port.onDisconnect.addListener(() => { + ns.popupOpened = false; if (pendingReload) { browser.tabs.reload(tabId); } diff --git a/src/ui/popup.js b/src/ui/popup.js index c29b94d..4b5dc85 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -43,10 +43,9 @@ addEventListener("unload", e => { tabId = tab.id; } - + let port = browser.runtime.connect({name: "noscript.popup"}); await UI.init(tabId); - let port = browser.runtime.connect({name: "noscript.popup"}) function pendingReload(b) { try { port.postMessage({tabId, pendingReload: b}); -- cgit v1.2.3