/* 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"))));
/* first start? */
}
/**
- * Sets whether the current start of the plugin is the first start. It is
- * considered a first start if the configuration file does not exist.
- *
- * @param firstStart
- * {@code true} if no configuration file existed when Sone was
- * loaded, {@code false} otherwise
- */
- public void setFirstStart(boolean firstStart) {
- if (firstStart) {
- Template firstStartNotificationTemplate = loaders.loadTemplate("/templates/notify/firstStartNotification.html");
- Notification firstStartNotification = new TemplateNotification("first-start-notification", firstStartNotificationTemplate);
- notificationManager.addNotification(firstStartNotification);
- }
- }
-
- /**
* Sets whether Sone was started with a fresh configuration file.
*
* @param newConfig
import com.google.common.eventbus.*
import net.pterodactylus.sone.core.event.*
import net.pterodactylus.util.notify.*
+import javax.inject.*
/**
* Handles the notification shown on first start of Sone.
*/
-class FirstStartHandler(private val notificationManager: NotificationManager, private val notification: TemplateNotification) {
+class FirstStartHandler @Inject constructor(private val notificationManager: NotificationManager, @Named("firstStart") private val notification: TemplateNotification) {
@Subscribe
fun firstStart(firstStart: FirstStart) {
soneLockedOnStartupHandler: SoneLockedOnStartupHandler,
soneLockedHandler: SoneLockedHandler,
newVersionHandler: NewVersionHandler,
- imageInsertHandler: ImageInsertHandler
+ imageInsertHandler: ImageInsertHandler,
+ firstStartHandler: FirstStartHandler
)
bind<LocalPostHandler>().asSingleton()
bind<NewVersionHandler>().asSingleton()
bind<ImageInsertHandler>().asSingleton()
+ bind<FirstStartHandler>().asSingleton()
}
@Provides
fun getImageInsertedNotification(loaders: Loaders) =
ListNotification<Image>("inserted-images-notification", "images", loaders.loadTemplate("/templates/notify/inserted-images-notification.html"), dismissable = true)
+ @Provides
+ @Singleton
+ @Named("firstStart")
+ fun getFirstStartNotification(loaders: Loaders) =
+ TemplateNotification("first-start-notification", loaders.loadTemplate("/templates/notify/firstStartNotification.html"))
+
private inline fun <reified T> bind(): AnnotatedBindingBuilder<T> = bind(T::class.java)
private fun ScopedBindingBuilder.asSingleton() = `in`(Singleton::class.java)
injector.verifySingletonInstance<ImageInsertHandler>()
}
+ @Test
+ fun `first-start notification is created as singleton`() {
+ injector.verifySingletonInstance<TemplateNotification>(named("firstStart"))
+ }
+
+ @Test
+ fun `first-start notification has correct ID`() {
+ assertThat(injector.getInstance<TemplateNotification>(named("firstStart")).id, equalTo("first-start-notification"))
+ }
+
+ @Test
+ fun `first-start notification is dismissable`() {
+ assertThat(injector.getInstance<TemplateNotification>(named("firstStart")).isDismissable, equalTo(true))
+ }
+
+ @Test
+ fun `first-start notification loads correct template`() {
+ loaders.templates += "/templates/notify/firstStartNotification.html" to "1".asTemplate()
+ val notification = injector.getInstance<TemplateNotification>(named("firstStart"))
+ assertThat(notification.render(), equalTo("1"))
+ }
+
+ @Test
+ fun `first-start handler is created as singleton`() {
+ injector.verifySingletonInstance<FirstStartHandler>()
+ }
+
}