Change message subject format and rename some messages

This commit is contained in:
hensm
2019-02-11 18:52:01 +00:00
parent 53a16ccde7
commit da17c6df0d
14 changed files with 324 additions and 319 deletions

View File

@@ -5,7 +5,7 @@ export default async function getBridgeInfo () {
try {
const response = await browser.runtime.sendNativeMessage(
APPLICATION_NAME
, { subject: "bridge:getInfo"
, { subject: "bridge:/getInfo"
, data: EXTENSION_VERSION });
applicationVersion = response.data;

View File

@@ -0,0 +1,25 @@
"use strict";
const routeMap = new Map();
function register (routeName, senderCallback) {
routeMap.set(routeName, senderCallback);
}
function deregister (routeName) {
routeMap.delete(routeName);
}
function handleMessage (message, details) {
const destination = message.subject.split(":")[0];
if (routeMap.has(destination)) {
routeMap.get(destination)(message, details);
}
}
export default {
register
, deregister
, handleMessage
}