add register hook to register global things (settings, commands, types)
from plugins. startup hook is used for starting an individual instance.
This commit is contained in:
parent
38c9fc7a93
commit
b75e43962a
2 changed files with 30 additions and 8 deletions
|
|
@ -121,9 +121,10 @@ console.log(JSON.stringify({
|
||||||
var pluginsModule = require("pilot/plugin_manager");
|
var pluginsModule = require("pilot/plugin_manager");
|
||||||
var settings = require("pilot/settings").settings;
|
var settings = require("pilot/settings").settings;
|
||||||
var catalog = pluginsModule.catalog;
|
var catalog = pluginsModule.catalog;
|
||||||
catalog.registerPlugins(knownPlugins);
|
catalog.registerPlugins(knownPlugins).then(function() {
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback(pluginsModule, settings);
|
callback(pluginsModule, settings);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -61,8 +61,10 @@ exports.Plugin.prototype = {
|
||||||
*/
|
*/
|
||||||
NEW: 0,
|
NEW: 0,
|
||||||
INSTALLED: 1,
|
INSTALLED: 1,
|
||||||
STARTED: 2,
|
REGISTERED: 2,
|
||||||
SHUTDOWN: 3,
|
STARTED: 3,
|
||||||
|
UNREGISTERED: 4,
|
||||||
|
SHUTDOWN: 5,
|
||||||
|
|
||||||
install: function(data, reason) {
|
install: function(data, reason) {
|
||||||
var pr = new Promise();
|
var pr = new Promise();
|
||||||
|
|
@ -80,12 +82,28 @@ exports.Plugin.prototype = {
|
||||||
return pr;
|
return pr;
|
||||||
},
|
},
|
||||||
|
|
||||||
startup: function(data, reason) {
|
register: function(data, reason) {
|
||||||
var pr = new Promise();
|
var pr = new Promise();
|
||||||
if (this.status != this.INSTALLED) {
|
if (this.status != this.INSTALLED) {
|
||||||
pr.resolve(this);
|
pr.resolve(this);
|
||||||
return pr;
|
return pr;
|
||||||
}
|
}
|
||||||
|
require([this.name], function(pluginModule) {
|
||||||
|
if (pluginModule.register) {
|
||||||
|
pluginModule.register(data, reason);
|
||||||
|
}
|
||||||
|
this.status = this.REGISTERED;
|
||||||
|
pr.resolve(this);
|
||||||
|
}.bind(this));
|
||||||
|
return pr;
|
||||||
|
},
|
||||||
|
|
||||||
|
startup: function(data, reason) {
|
||||||
|
var pr = new Promise();
|
||||||
|
if (this.status != this.REGISTERED) {
|
||||||
|
pr.resolve(this);
|
||||||
|
return pr;
|
||||||
|
}
|
||||||
require([this.name], function(pluginModule) {
|
require([this.name], function(pluginModule) {
|
||||||
if (pluginModule.startup) {
|
if (pluginModule.startup) {
|
||||||
pluginModule.startup(data, reason);
|
pluginModule.startup(data, reason);
|
||||||
|
|
@ -112,14 +130,17 @@ exports.PluginCatalog = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.PluginCatalog.prototype = {
|
exports.PluginCatalog.prototype = {
|
||||||
registerPlugins: function(pluginList) {
|
registerPlugins: function(pluginList, data, reason) {
|
||||||
|
var registrationPromises = [];
|
||||||
pluginList.forEach(function(pluginName) {
|
pluginList.forEach(function(pluginName) {
|
||||||
var plugin = this.plugins[pluginName];
|
var plugin = this.plugins[pluginName];
|
||||||
if (plugin === undefined) {
|
if (plugin === undefined) {
|
||||||
plugin = new exports.Plugin(pluginName);
|
plugin = new exports.Plugin(pluginName);
|
||||||
this.plugins[pluginName] = plugin;
|
this.plugins[pluginName] = plugin;
|
||||||
|
registrationPromises.push(plugin.register(data, reason));
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
return Promise.group(registrationPromises);
|
||||||
},
|
},
|
||||||
|
|
||||||
startupPlugins: function(data, reason) {
|
startupPlugins: function(data, reason) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue