Fixed shortcut and context menu doing nothing unless browserAction icon is visible on Firefox (issue #58).

This commit is contained in:
hackademix 2019-12-11 13:02:10 +01:00
parent 974d22848d
commit 528c8ea577
3 changed files with 15 additions and 10 deletions

View File

@ -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() {},

View File

@ -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);
}

View File

@ -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});