From 075a5ad0e0f9b4f9af614194d9c8d21d0ed45184 Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 22 Aug 2018 16:34:16 +0200 Subject: More coherent wrapper around the webex messaging API. --- src/ui/popup.js | 4 +--- src/ui/ui.js | 18 ++++++++---------- 2 files changed, 9 insertions(+), 13 deletions(-) (limited to 'src/ui') 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() { -- cgit v1.2.3