🎨 Reduce dependency on Node’s fields
[Sone.git] / src / main / kotlin / net / pterodactylus / sone / main / FreenetModule.kt
index 9b5fa2e..691ae4e 100644 (file)
@@ -2,9 +2,14 @@ package net.pterodactylus.sone.main
 
 import com.google.inject.*
 import freenet.client.*
+import freenet.client.async.ClientContext
+import freenet.client.async.USKManager
 import freenet.clients.http.*
 import freenet.node.*
 import freenet.pluginmanager.*
+import net.pterodactylus.sone.freenet.DefaultHighLevelSimpleClientCreator
+import net.pterodactylus.sone.freenet.HighLevelSimpleClientCreator
+import net.pterodactylus.sone.freenet.plugin.*
 import javax.inject.Provider
 import javax.inject.Singleton
 
@@ -14,8 +19,9 @@ import javax.inject.Singleton
 class FreenetModule(private val pluginRespirator: PluginRespirator) : Module {
 
        override fun configure(binder: Binder): Unit = binder.run {
-               bind(PluginRespirator::class.java).toProvider(Provider<PluginRespirator> { pluginRespirator })
-               pluginRespirator.node!!.let { node -> bind(Node::class.java).toProvider(Provider<Node> { node }) }
+               bind(PluginRespiratorFacade::class.java).toProvider(Provider { FredPluginRespiratorFacade(pluginRespirator) }).`in`(Singleton::class.java)
+               bind(PluginConnector::class.java).to(FredPluginConnector::class.java).`in`(Singleton::class.java)
+               bind(Node::class.java).toProvider(Provider { pluginRespirator.node })
                bind(HighLevelSimpleClient::class.java).toProvider(Provider<HighLevelSimpleClient> { pluginRespirator.hlSimpleClient!! })
                bind(ToadletContainer::class.java).toProvider(Provider<ToadletContainer> { pluginRespirator.toadletContainer })
                bind(PageMaker::class.java).toProvider(Provider<PageMaker> { pluginRespirator.pageMaker })
@@ -25,4 +31,20 @@ class FreenetModule(private val pluginRespirator: PluginRespirator) : Module {
        @Singleton
        fun getSessionManager() = pluginRespirator.getSessionManager("Sone")!!
 
+       @Provides
+       fun getNodeClientCore(node: Node): NodeClientCore =
+               node.clientCore
+
+       @Provides
+       fun getHighLevelSimpleClientCreator(nodeClientCore: NodeClientCore): HighLevelSimpleClientCreator =
+               DefaultHighLevelSimpleClientCreator(nodeClientCore)
+
+       @Provides
+       fun getClientContext(nodeClientCore: NodeClientCore): ClientContext =
+               nodeClientCore.clientContext
+
+       @Provides
+       fun getUskManager(nodeClientCore: NodeClientCore): USKManager =
+               nodeClientCore.uskManager
+
 }