summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bg/main.js2
-rw-r--r--src/bg/popupHandler.js17
-rw-r--r--src/ui/popup.js30
3 files changed, 34 insertions, 15 deletions
diff --git a/src/bg/main.js b/src/bg/main.js
index 8ff2d55..667be28 100644
--- a/src/bg/main.js
+++ b/src/bg/main.js
@@ -49,7 +49,7 @@
// no embedder to answer us
}
log("STARTED");
-
+ await include("/bg/popupHandler.js");
};
let Commands = {
diff --git a/src/bg/popupHandler.js b/src/bg/popupHandler.js
new file mode 100644
index 0000000..b893174
--- /dev/null
+++ b/src/bg/popupHandler.js
@@ -0,0 +1,17 @@
+browser.runtime.onConnect.addListener(port => {
+ if (port.name === "noscript.popup") {
+ let pendingReload = false;
+ let tabId = -1;
+ port.onMessage.addListener(m => {
+ if ("pendingReload" in m) {
+ tabId = m.tabId;
+ pendingReload = m.pendingReload;
+ }
+ });
+ port.onDisconnect.addListener(() => {
+ if (pendingReload) {
+ browser.tabs.reload(tabId);
+ }
+ });
+ }
+});
diff --git a/src/ui/popup.js b/src/ui/popup.js
index 1f79b55..87ac73e 100644
--- a/src/ui/popup.js
+++ b/src/ui/popup.js
@@ -18,7 +18,6 @@ addEventListener("unload", e => {
try {
let tabId;
- let pendingReload = false;
let isBrowserAction = true;
let optionsClosed = false;
let tab = (await browser.tabs.query({
@@ -44,8 +43,19 @@ addEventListener("unload", e => {
tabId = tab.id;
}
+
await UI.init(tabId);
+ let port = browser.runtime.connect({name: "noscript.popup"})
+ function pendingReload(b) {
+ try {
+ port.postMessage({tabId, pendingReload: b});
+ } catch (e) {
+ debug(e);
+ }
+ }
+
+
if (isBrowserAction) {
browser.tabs.onActivated.addListener(e => {
if (e.tabId !== tabId) close();
@@ -154,7 +164,7 @@ addEventListener("unload", e => {
sitesUI = new UI.Sites(document.getElementById("sites"));
sitesUI.onChange = (row) => {
- pendingReload = !row.temp2perm;
+ pendingReload(!row.temp2perm);
if (optionsClosed) return;
browser.tabs.query({url: browser.runtime.getManifest().options_ui.page })
.then(tabs => {
@@ -168,7 +178,7 @@ addEventListener("unload", e => {
function initSitesUI() {
- pendingReload = false;
+ pendingReload(false);
let {
typesMap
} = sitesUI;
@@ -233,14 +243,13 @@ addEventListener("unload", e => {
function reload() {
if (sitesUI) sitesUI.clear();
browser.tabs.reload(tabId);
- pendingReload = false;
+ pendingReload(false);
}
function close() {
if (isBrowserAction) {
window.close();
} else {
- //browser.windows.remove(tab.windowId);
browser.tabs.remove(tab.id);
}
}
@@ -260,16 +269,9 @@ addEventListener("unload", e => {
hostContains: sitesUI.mainDomain
}]
});
- addEventListener("unload", e => {
+ addEventListener("blur", e => {
onCompleted.removeListener(onCompletedListener);
- debug("pendingReload", pendingReload);
- if (pendingReload) {
- UI.updateSettings({
- policy: UI.policy,
- reloadAffected: true,
- });
- }
- }, true);
+ });
} catch (e) {
error(e, "Can't open popup");
close();