2013-11-25 01:53:55 +00:00
|
|
|
define(["command", "settings!api"], function(command, Settings) {
|
|
|
|
//handles sending custom messages based on Caret commands (builds, plugins, etc)
|
|
|
|
var targets = Settings.get("api");
|
2013-12-02 23:17:46 +00:00
|
|
|
command.on("init:restart", function() {
|
|
|
|
targets = Settings.get("api");
|
|
|
|
});
|
2013-11-25 01:53:55 +00:00
|
|
|
|
|
|
|
command.on("api:execute", function(id) {
|
|
|
|
if (!id in targets) return;
|
|
|
|
var config = targets[id];
|
2013-12-02 23:38:12 +00:00
|
|
|
chrome.runtime.sendMessage(config.id, config.message, null, function() {
|
|
|
|
if (chrome.runtime.lastError) {
|
|
|
|
console.error(chrome.runtime.lastError);
|
|
|
|
}
|
|
|
|
});
|
2013-11-25 01:53:55 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
//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);
|
|
|
|
});
|
|
|
|
});
|