mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 12:34:43 +00:00
create a plugin registration system to allow for plugin loading on the fly
remove the plugin event handlers from the event manager fix enabling/disabling plugins when the preferences page hasn't been rendered yet
This commit is contained in:
parent
bf2fc64ce0
commit
7e12222d33
@ -87,6 +87,9 @@ Ext.USE_NATIVE_JSON = true;
|
||||
|
||||
// Create the Deluge namespace
|
||||
Ext.apply(Deluge, {
|
||||
|
||||
// private
|
||||
pluginStore: {},
|
||||
|
||||
// private
|
||||
progressTpl: '<div class="x-progress-wrap x-progress-renderered">' +
|
||||
@ -117,6 +120,31 @@ Ext.apply(Deluge, {
|
||||
var barWidth = progressWidth - 1;
|
||||
var textWidth = ((progressWidth - modifier) > 0 ? progressWidth - modifier : 0);
|
||||
return String.format(Deluge.progressTpl, text, width, barWidth, textWidth);
|
||||
},
|
||||
|
||||
/**
|
||||
* Constructs a new instance of the specified plugin.
|
||||
* @param {String} name The plugin name to create
|
||||
*/
|
||||
createPlugin: function(name) {
|
||||
return new Deluge.pluginStore[name]();
|
||||
},
|
||||
|
||||
/**
|
||||
* Check to see if a plugin has been registered.
|
||||
* @param {String} name The plugin name to check
|
||||
*/
|
||||
hasPlugin: function(name) {
|
||||
return (Deluge.pluginStore[name]) ? true : false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Register a plugin with the Deluge interface.
|
||||
* @param {String} name The plugin name to register
|
||||
* @param {Plugin} plugin The plugin to register
|
||||
*/
|
||||
registerPlugin: function(name, plugin) {
|
||||
Deluge.pluginStore[name] = plugin;
|
||||
}
|
||||
|
||||
});
|
||||
|
@ -88,8 +88,6 @@ Deluge.EventsManager = Ext.extend(Ext.util.Observable, {
|
||||
// private
|
||||
onLogin: function() {
|
||||
this.start();
|
||||
this.on('PluginEnabledEvent', this.onPluginEnabled, this);
|
||||
this.on('PluginDisabledEvent', this.onPluginDisabled, this);
|
||||
},
|
||||
|
||||
onGetEventsSuccess: function(events) {
|
||||
|
@ -81,8 +81,9 @@ deluge.ui = {
|
||||
url: deluge.config.base + 'json'
|
||||
});
|
||||
|
||||
for (var plugin in Deluge.plugins) {
|
||||
plugin = new Deluge.plugins[plugin]();
|
||||
// enable all the already active plugins
|
||||
for (var plugin in Deluge.pluginStore) {
|
||||
plugin = Deluge.createPlugin(plugin);
|
||||
plugin.enable();
|
||||
deluge.plugins[plugin.name] = plugin;
|
||||
}
|
||||
@ -161,14 +162,19 @@ deluge.ui = {
|
||||
},
|
||||
|
||||
onPluginEnabled: function(pluginName) {
|
||||
deluge.client.web.get_plugin_resources(pluginName, {
|
||||
success: this.onGotPluginResources,
|
||||
scope: this
|
||||
})
|
||||
alert('enabled ' + pluginName);
|
||||
if (deluge.plugins[pluginName]) {
|
||||
deluge.plugins[pluginName].enable();
|
||||
} else {
|
||||
deluge.client.web.get_plugin_resources(pluginName, {
|
||||
success: this.onGotPluginResources,
|
||||
scope: this
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
onGotPluginResources: function(resources) {
|
||||
var scripts = (deluge.debug) ? resources.debug_scripts : resources.scripts;
|
||||
var scripts = (Deluge.debug) ? resources.debug_scripts : resources.scripts;
|
||||
Ext.each(scripts, function(script) {
|
||||
Ext.ux.JSLoader({
|
||||
url: script,
|
||||
@ -179,15 +185,18 @@ deluge.ui = {
|
||||
},
|
||||
|
||||
onPluginDisabled: function(pluginName) {
|
||||
alert('disabled ' + pluginName);
|
||||
deluge.plugins[pluginName].disable();
|
||||
},
|
||||
|
||||
onPluginLoaded: function(options) {
|
||||
// This could happen if the plugin has multiple scripts
|
||||
if (!deluge.plugins[options.pluginName]) return;
|
||||
if (!Deluge.hasPlugin(options.pluginName)) return;
|
||||
|
||||
// Enable the plugin
|
||||
deluge.plugins[options.pluginName].enable();
|
||||
plugin = Deluge.createPlugin(options.pluginName);
|
||||
plugin.enable();
|
||||
deluge.plugins[plugin.name] = plugin;
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -310,6 +310,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||
|
||||
onPluginEnabled: function(pluginName) {
|
||||
var index = this.grid.getStore().find('plugin', pluginName);
|
||||
if (index == -1) return;
|
||||
var plugin = this.grid.getStore().getAt(index);
|
||||
plugin.set('enabled', true);
|
||||
plugin.commit();
|
||||
@ -317,6 +318,7 @@ Deluge.preferences.Plugins = Ext.extend(Ext.Panel, {
|
||||
|
||||
onPluginDisabled: function(pluginName) {
|
||||
var index = this.grid.getStore().find('plugin', pluginName);
|
||||
if (index == -1) return;
|
||||
var plugin = this.grid.getStore().getAt(index);
|
||||
plugin.set('enabled', false);
|
||||
plugin.commit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user