summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bg/defaults.js60
-rw-r--r--src/bg/main.js30
-rw-r--r--src/lib/Messages.js14
-rw-r--r--src/manifest.json5
4 files changed, 59 insertions, 50 deletions
diff --git a/src/bg/defaults.js b/src/bg/defaults.js
index 4d071b4..7170743 100644
--- a/src/bg/defaults.js
+++ b/src/bg/defaults.js
@@ -1,36 +1,38 @@
'use strict';
-ns.defaults = (async () => {
- let defaults = {
- local: {
- debug: false,
- showCtxMenuItem: true,
- showCountBadge: true,
- showFullAddresses: false,
- },
- sync: {
- "global": false,
- "xss": true,
- "clearclick": true
- }
- };
- let defaultsClone = JSON.parse(JSON.stringify(defaults));
+var Defaults = {
+ async init() {
+ let defaults = {
+ local: {
+ debug: false,
+ showCtxMenuItem: true,
+ showCountBadge: true,
+ showFullAddresses: false,
+ },
+ sync: {
+ "global": false,
+ "xss": true,
+ "clearclick": true
+ }
+ };
+ let defaultsClone = JSON.parse(JSON.stringify(defaults));
- for (let [k, v] of Object.entries(defaults)) {
- let store = await Storage.get(k, k);
- if (k in store) {
- Object.assign(v, store[k]);
+ for (let [k, v] of Object.entries(defaults)) {
+ let store = await Storage.get(k, k);
+ if (k in store) {
+ Object.assign(v, store[k]);
+ }
+ v.storage = k;
}
- v.storage = k;
- }
- Object.assign(ns, defaults);
+ Object.assign(ns, defaults);
- // dynamic settings
- if (!ns.local.uuid) {
- ns.local.uuid = uuid();
- await ns.save(ns.local);
- }
+ // dynamic settings
+ if (!ns.local.uuid) {
+ ns.local.uuid = uuid();
+ await ns.save(ns.local);
+ }
- return ns.defaults = defaultsClone;
-})();
+ return ns.defaults = defaultsClone;
+ }
+};
diff --git a/src/bg/main.js b/src/bg/main.js
index 72ef5de..58e7aef 100644
--- a/src/bg/main.js
+++ b/src/bg/main.js
@@ -23,8 +23,7 @@
}
async function init() {
- await include("/bg/defaults.js");
- await ns.defaults;
+ await Defaults.init();
let policyData = (await Storage.get("sync", "policy")).policy;
if (policyData && policyData.DEFAULT) {
@@ -35,16 +34,22 @@
ns.policy = await Legacy.createOrMigratePolicy();
ns.savePolicy();
}
-
-
-
- await include("/bg/RequestGuard.js");
+
await RequestGuard.start();
await XSS.start(); // we must start it anyway to initialize sub-objects
if (!ns.sync.xss) {
XSS.stop();
}
- Commands.install();
+
+ Messages.addHandler(messageHandler);
+
+ try {
+ await Messages.send("started");
+ } catch (e) {
+ // no embedder to answer us
+ }
+ log("STARTED");
+
};
let Commands = {
@@ -65,8 +70,6 @@
togglePermissions() {},
install() {
-
-
if ("command" in browser) {
// keyboard shortcuts
browser.commands.onCommand.addListener(cmd => {
@@ -182,13 +185,8 @@
deferWebTraffic(init(),
async () => {
-
- await include("/bg/Settings.js");
- Messages.addHandler(messageHandler);
-
- await Messages.send("started");
- log("STARTED");
-
+ Commands.install();
+
this.devMode = (await browser.management.getSelf()).installType === "development";
if (this.local.debug) {
if (this.devMode) {
diff --git a/src/lib/Messages.js b/src/lib/Messages.js
index a58598a..50639ef 100644
--- a/src/lib/Messages.js
+++ b/src/lib/Messages.js
@@ -1,17 +1,23 @@
"use strict";
{
let handlers = new Set();
-
- let forever = new Promise(resolve => {});
+
let dispatch = async (msg, sender) => {
let {_messageName} = msg;
+ let answers = [];
for (let h of handlers) {
let f = h[_messageName];
if (typeof f === "function") {
- return await f(msg, sender);
+ answers.push(f(msg, sender));
}
}
- await forever;
+ if (answers.length) {
+ return await (
+ answers.length === 1 ? answers.pop(): Promise.all(answers)
+ );
+ }
+ console.log("Answering %s", _messageName);
+ return undefined;
};
var Messages = {
diff --git a/src/manifest.json b/src/manifest.json
index 7a78bef..4351a1c 100644
--- a/src/manifest.json
+++ b/src/manifest.json
@@ -8,7 +8,7 @@
"strict_min_version": "59.0"
}
},
- "version": "10.1.9rc1",
+ "version": "10.1.9rc3",
"description": "__MSG_Description__",
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'none'",
@@ -54,6 +54,9 @@
"bg/ReportingCSP.js",
"bg/deferWebTraffic.js",
"bg/ChildPolicies.js",
+ "bg/Defaults.js",
+ "bg/RequestGuard.js",
+ "bg/Settings.js",
"bg/main.js"
]
},