diff options
author | hackademix | 2018-08-22 16:34:16 +0200 |
---|---|---|
committer | hackademix | 2018-08-22 16:34:16 +0200 |
commit | 075a5ad0e0f9b4f9af614194d9c8d21d0ed45184 (patch) | |
tree | cc341040d0515e54ec8466dec8d3e32c381f1457 /src/ui | |
parent | 48c04726b8d2da0023abd0ccef3e2d09511bea47 (diff) | |
download | noscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.tar.gz noscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.tar.xz noscript-075a5ad0e0f9b4f9af614194d9c8d21d0ed45184.zip |
More coherent wrapper around the webex messaging API.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/popup.js | 4 | ||||
-rw-r--r-- | src/ui/ui.js | 18 |
2 files changed, 9 insertions, 13 deletions
diff --git a/src/ui/popup.js b/src/ui/popup.js index 55eff03..bc054d1 100644 --- a/src/ui/popup.js +++ b/src/ui/popup.js @@ -4,9 +4,7 @@ var sitesUI; addEventListener("unload", e => { if (!UI.initialized) { - browser.runtime.sendMessage({ - type: "openStandalonePopup" - }); + Messages.send("openStandalonePopup"); } }); diff --git a/src/ui/ui.js b/src/ui/ui.js index be9063b..8cf20ce 100644 --- a/src/ui/ui.js +++ b/src/ui/ui.js @@ -16,6 +16,7 @@ var UI = (() => { UI.tabId = tabId; let scripts = [ "/ui/ui.css", + "/lib/Messages.js", "/lib/punycode.js", "/lib/tld.js", "/common/Policy.js", @@ -27,11 +28,9 @@ var UI = (() => { } await include(scripts); - - let inited = new Promise(resolve => { - let listener = async m => { - if (m.type === "settings") { + Messages.addHandler({ + async settings(m) { UI.policy = new Policy(m.policy); UI.snapshot = UI.policy.snapshot; UI.seen = m.seen; @@ -46,8 +45,7 @@ var UI = (() => { if (UI.onSettings) UI.onSettings(); await HighContrast.init(); } - }; - browser.runtime.onMessage.addListener(listener); + }); if (this.mobile) FastClick.attach(document.body); UI.pullSettings(); @@ -59,11 +57,11 @@ var UI = (() => { debug("Imported", Policy); }, async pullSettings() { - browser.runtime.sendMessage({action: "broadcastSettings", tabId: UI.tabId}); + Messages.send("broadcastSettings", {tabId: UI.tabId}); }, async updateSettings({policy, xssUserChoices, unrestrictedTab, local, sync, reloadAffected}) { if (policy) policy = policy.dry(true); - return await browser.runtime.sendMessage({action: "updateSettings", + return await Messages.send("updateSettings", { policy, xssUserChoices, unrestrictedTab, @@ -75,10 +73,10 @@ var UI = (() => { }, async exportSettings() { - return await browser.runtime.sendMessage({action: "exportSettings"}); + return await Messages.send("exportSettings"); }, async importSettings(data) { - return await browser.runtime.sendMessage({action: "importSettings", data}); + return await Messages.send("importSettings", {data}); }, async revokeTemp() { |