37cd59d0a6
See #80.
27 lines
No EOL
837 B
JavaScript
27 lines
No EOL
837 B
JavaScript
define([
|
|
"command",
|
|
"settings!api"
|
|
], function(command, Settings) {
|
|
|
|
//handles sending custom messages based on Caret commands (builds, plugins, etc)
|
|
var targets = Settings.get("api");
|
|
command.on("init:restart", function() {
|
|
targets = Settings.get("api");
|
|
});
|
|
|
|
command.on("api:execute", function(id, c) {
|
|
if (!id in targets) return c();
|
|
var config = targets[id];
|
|
chrome.runtime.sendMessage(config.id, config.message, null, function() {
|
|
if (chrome.runtime.lastError) {
|
|
console.error(chrome.runtime.lastError);
|
|
}
|
|
if (c) c();
|
|
});
|
|
});
|
|
|
|
//External apps can send messages by matching Caret's command/argument config objects
|
|
chrome.runtime.onMessageExternal.addListener(function(message, sender, c) {
|
|
command.fire(message.command, message.argument, c);
|
|
});
|
|
}); |