diff --git a/deluge/ui/web/js/deluge-all/Deluge.js b/deluge/ui/web/js/deluge-all/Deluge.js
index 96810bee8..de82dd7af 100644
--- a/deluge/ui/web/js/deluge-all/Deluge.js
+++ b/deluge/ui/web/js/deluge-all/Deluge.js
@@ -87,6 +87,9 @@ Ext.USE_NATIVE_JSON = true;
// Create the Deluge namespace
Ext.apply(Deluge, {
+
+ // private
+ pluginStore: {},
// private
progressTpl: '
' +
@@ -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;
}
});
diff --git a/deluge/ui/web/js/deluge-all/EventsManager.js b/deluge/ui/web/js/deluge-all/EventsManager.js
index df669ff45..0981d4393 100644
--- a/deluge/ui/web/js/deluge-all/EventsManager.js
+++ b/deluge/ui/web/js/deluge-all/EventsManager.js
@@ -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) {
diff --git a/deluge/ui/web/js/deluge-all/UI.js b/deluge/ui/web/js/deluge-all/UI.js
index 5ec69cc10..a73a8c641 100644
--- a/deluge/ui/web/js/deluge-all/UI.js
+++ b/deluge/ui/web/js/deluge-all/UI.js
@@ -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;
},
/**
diff --git a/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js b/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
index 63da922f1..c805cba06 100644
--- a/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
+++ b/deluge/ui/web/js/deluge-all/preferences/PluginsPage.js
@@ -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();