X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fmain%2FSonePlugin.java;h=91f21eb7dca45e0ee3d9b5b53b41adb278b348cf;hb=d5ae76c33a3ef986d2235060c4ade7fdf498493a;hp=a3cb38502c9b6e36e941aad047025def177bc059;hpb=0d9ddd8ae192ab749c224a14e9420306b3e719ed;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index a3cb385..91f21eb 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -22,11 +22,15 @@ import static java.util.logging.Logger.*; import java.util.logging.Logger; import java.util.logging.*; +import javax.annotation.Nonnull; + import net.pterodactylus.sone.core.*; +import net.pterodactylus.sone.core.event.*; import net.pterodactylus.sone.fcp.*; import net.pterodactylus.sone.freenet.wot.*; import net.pterodactylus.sone.web.*; import net.pterodactylus.sone.web.notification.NotificationHandler; +import net.pterodactylus.sone.web.notification.NotificationHandlerModule; import freenet.l10n.BaseL10n.*; import freenet.l10n.*; @@ -58,7 +62,7 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr private final LoadingCache> classCache = CacheBuilder.newBuilder() .build(new CacheLoader>() { @Override - public Class load(String key) throws Exception { + public Class load(@Nonnull String key) throws Exception { return SonePlugin.class.getClassLoader().loadClass(key); } }); @@ -197,16 +201,30 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr /* create the web interface. */ webInterface = injector.getInstance(WebInterface.class); - NotificationHandler notificationHandler = injector.getInstance(NotificationHandler.class); + + /* we need to request this to install all notification handlers. */ + injector.getInstance(NotificationHandler.class); /* start core! */ core.start(); /* start the web interface! */ webInterface.start(); - webInterface.setFirstStart(injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart")))); - webInterface.setNewConfig(injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig")))); - notificationHandler.start(); + + /* send some events on startup */ + EventBus eventBus = injector.getInstance(EventBus.class); + + /* first start? */ + if (injector.getInstance(Key.get(Boolean.class, Names.named("FirstStart")))) { + eventBus.post(new FirstStart()); + } else { + /* new config? */ + if (injector.getInstance(Key.get(Boolean.class, Names.named("NewConfig")))) { + eventBus.post(new ConfigNotRead()); + } + } + + eventBus.post(new Startup()); } @VisibleForTesting @@ -214,8 +232,9 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr FreenetModule freenetModule = new FreenetModule(pluginRespirator); AbstractModule soneModule = new SoneModule(this, new EventBus()); Module webInterfaceModule = new WebInterfaceModule(); + Module notificationHandlerModule = new NotificationHandlerModule(); - return createInjector(freenetModule, soneModule, webInterfaceModule); + return createInjector(freenetModule, soneModule, webInterfaceModule, notificationHandlerModule); } @VisibleForTesting