Skip to content

Commit

Permalink
Switch to Koin from Injekt (#1109)
Browse files Browse the repository at this point in the history
replace "com.github.inorichi.injekt" with "com.github.null2264:injekt-koin"
  • Loading branch information
schroda authored Nov 9, 2024
1 parent 654a3cc commit f5680c6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 33 deletions.
6 changes: 5 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ twelvemonkeys = "3.11.0"
graphqlkotlin = "6.8.5"
xmlserialization = "0.86.2"
ktlint = "1.3.1"
koin-bom = "4.0.0"

[libraries]
# Kotlin
Expand Down Expand Up @@ -69,13 +70,16 @@ exposed-migrations = "com.github.Suwayomi:exposed-migrations:3.2.0"
# Dependency Injection
kodein = "org.kodein.di:kodein-di-conf-jvm:7.20.2"

koin-bom = { module = "io.insert-koin:koin-bom", version.ref = "koin-bom" }
koin-core = { module = "io.insert-koin:koin-core" }

# tray icon
systemtray-core = "com.dorkbox:SystemTray:4.4"
systemtray-utils = "com.dorkbox:Utilities:1.46" # version locked by SystemTray
systemtray-desktop = "com.dorkbox:Desktop:1.1" # version locked by SystemTray

# dependencies of Tachiyomi extensions
injekt = "com.github.inorichi.injekt:injekt-core:65b0440"
injekt = "com.github.null2264:injekt-koin:ee267b2e27"
rxjava = "io.reactivex:rxjava:1.3.8"
jsoup = "org.jsoup:jsoup:1.18.1"

Expand Down
4 changes: 4 additions & 0 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ dependencies {
implementation(libs.cron4j)

implementation(libs.cronUtils)

// koin
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
}

application {
Expand Down
9 changes: 4 additions & 5 deletions server/src/main/kotlin/eu/kanade/tachiyomi/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@ package eu.kanade.tachiyomi

import android.app.Application
import android.content.Context
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.InjektScope
import uy.kohesive.injekt.registry.default.DefaultRegistrar
import org.koin.core.context.startKoin

open class App : Application() {
override fun onCreate() {
super.onCreate()
Injekt = InjektScope(DefaultRegistrar())
Injekt.importModule(AppModule(this))

startKoin {
modules(createAppModule(this@App))
}
// if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
}

Expand Down
41 changes: 14 additions & 27 deletions server/src/main/kotlin/eu/kanade/tachiyomi/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,12 @@ import nl.adaptivity.xmlutil.serialization.XML
import org.kodein.di.DI
import org.kodein.di.conf.global
import org.kodein.di.instance
import rx.Observable
import rx.schedulers.Schedulers
import uy.kohesive.injekt.api.InjektModule
import uy.kohesive.injekt.api.InjektRegistrar
import uy.kohesive.injekt.api.addSingleton
import uy.kohesive.injekt.api.addSingletonFactory
import uy.kohesive.injekt.api.get
import org.koin.core.module.Module
import org.koin.dsl.module

class AppModule(
val app: Application,
) : InjektModule {
override fun InjektRegistrar.registerInjectables() {
addSingleton(app)
fun createAppModule(app: Application): Module {
return module {
single { app }

// addSingletonFactory { PreferencesHelper(app) }
//
Expand All @@ -46,9 +39,9 @@ class AppModule(
//
// addSingletonFactory { CoverCache(app) }

addSingletonFactory { NetworkHelper(app) }
single { NetworkHelper(app) }

addSingletonFactory { JavaScriptEngine(app) }
single { JavaScriptEngine(app) }

// addSingletonFactory { SourceManager(app).also { get<ExtensionManager>().init(it) } }
//
Expand All @@ -60,36 +53,30 @@ class AppModule(
//
// addSingletonFactory { LibrarySyncManager(app) }

addSingletonFactory {
single {
val json by DI.global.instance<Json>()
json
}

addSingletonFactory {
single {
val xml by DI.global.instance<XML>()
xml
}

addSingletonFactory {
single {
val protobuf by DI.global.instance<ProtoBuf>()
protobuf
}
}

// Asynchronously init expensive components for a faster cold start
// Asynchronously init expensive components for a faster cold start

// rxAsync { get<PreferencesHelper>() }

rxAsync { get<NetworkHelper>() }

rxAsync {
// rxAsync {
// get<SourceManager>()
// get<DownloadManager>()
}
// }

// rxAsync { get<DatabaseHelper>() }
}

private fun rxAsync(block: () -> Unit) {
Observable.fromCallable { block() }.subscribeOn(Schedulers.computation()).subscribe()
}
}

0 comments on commit f5680c6

Please sign in to comment.