|
@@ -22,10 +22,10 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.plugins;
|
24
|
24
|
|
25
|
|
-import com.dmdirc.actions.ActionManager;
|
26
|
|
-import com.dmdirc.actions.CoreActionType;
|
27
|
25
|
import com.dmdirc.config.ConfigFileBackedConfigProvider;
|
28
|
26
|
import com.dmdirc.config.InvalidIdentityFileException;
|
|
27
|
+import com.dmdirc.events.PluginLoadedEvent;
|
|
28
|
+import com.dmdirc.events.PluginUnloadedEvent;
|
29
|
29
|
import com.dmdirc.interfaces.config.ConfigProvider;
|
30
|
30
|
import com.dmdirc.interfaces.config.IdentityController;
|
31
|
31
|
import com.dmdirc.logger.ErrorLevel;
|
|
@@ -34,6 +34,8 @@ import com.dmdirc.util.SimpleInjector;
|
34
|
34
|
import com.dmdirc.util.resourcemanager.ResourceManager;
|
35
|
35
|
import com.dmdirc.util.validators.ValidationResponse;
|
36
|
36
|
|
|
37
|
+import com.google.common.eventbus.EventBus;
|
|
38
|
+
|
37
|
39
|
import java.io.File;
|
38
|
40
|
import java.io.IOException;
|
39
|
41
|
import java.io.InputStream;
|
|
@@ -91,12 +93,15 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
91
|
93
|
private final Map<String, ExportInfo> exports = new HashMap<>();
|
92
|
94
|
/** List of configuration providers. */
|
93
|
95
|
private final List<ConfigProvider> configProviders = new ArrayList<>();
|
|
96
|
+ /** Event bus to post plugin loaded events to. */
|
|
97
|
+ private final EventBus eventBus;
|
94
|
98
|
|
95
|
99
|
/**
|
96
|
100
|
* Create a new PluginInfo.
|
97
|
101
|
*
|
98
|
102
|
* @param metadata The plugin's metadata information
|
99
|
103
|
* @param injectorInitialiser The initialiser to use for the plugin's injector.
|
|
104
|
+ * @param eventBus Event bus to post event loaded events on.
|
100
|
105
|
* @param identityController The identity controller to add and remove settings from.
|
101
|
106
|
* @param objectGraph The object graph to give to plugins for DI purposes.
|
102
|
107
|
*
|
|
@@ -105,10 +110,12 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
105
|
110
|
public PluginInfo(
|
106
|
111
|
final PluginMetaData metadata,
|
107
|
112
|
final Provider<PluginInjectorInitialiser> injectorInitialiser,
|
|
113
|
+ final EventBus eventBus,
|
108
|
114
|
final IdentityController identityController,
|
109
|
115
|
final ObjectGraph objectGraph) throws PluginException {
|
110
|
116
|
this.injectorInitialiser = injectorInitialiser;
|
111
|
117
|
this.objectGraph = objectGraph;
|
|
118
|
+ this.eventBus = eventBus;
|
112
|
119
|
this.identityController = identityController;
|
113
|
120
|
this.filename = new File(metadata.getPluginUrl().getPath()).getName();
|
114
|
121
|
this.metaData = metadata;
|
|
@@ -627,8 +634,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
627
|
634
|
loadClass(metaData.getMainClass());
|
628
|
635
|
|
629
|
636
|
if (isLoaded()) {
|
630
|
|
- ActionManager.getActionManager().triggerEvent(
|
631
|
|
- CoreActionType.PLUGIN_LOADED, null, this);
|
|
637
|
+ //TODO plugin loading shouldnt be done from here, event bus shouldn't be here.
|
|
638
|
+ eventBus.post(new PluginLoadedEvent(this));
|
632
|
639
|
}
|
633
|
640
|
|
634
|
641
|
isLoading = false;
|
|
@@ -846,8 +853,8 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
|
846
|
853
|
Logger.appError(ErrorLevel.MEDIUM, lastError, e);
|
847
|
854
|
}
|
848
|
855
|
|
849
|
|
- ActionManager.getActionManager().triggerEvent(
|
850
|
|
- CoreActionType.PLUGIN_UNLOADED, null, this);
|
|
856
|
+ //TODO plugin unloading shouldnt be done from here, event bus shouldn't be here.
|
|
857
|
+ eventBus.post(new PluginUnloadedEvent(this));
|
851
|
858
|
synchronized (provides) {
|
852
|
859
|
for (Service service : provides) {
|
853
|
860
|
service.delProvider(this);
|