Switch to Koin from Injekt (#1109)

replace "com.github.inorichi.injekt" with "com.github.null2264:injekt-koin"
This commit is contained in:
schroda
2024-11-09 17:32:51 +01:00
committed by GitHub
parent 654a3cc7ed
commit f5680c6d69
4 changed files with 27 additions and 33 deletions

View File

@@ -13,6 +13,7 @@ twelvemonkeys = "3.11.0"
graphqlkotlin = "6.8.5" graphqlkotlin = "6.8.5"
xmlserialization = "0.86.2" xmlserialization = "0.86.2"
ktlint = "1.3.1" ktlint = "1.3.1"
koin-bom = "4.0.0"
[libraries] [libraries]
# Kotlin # Kotlin
@@ -69,13 +70,16 @@ exposed-migrations = "com.github.Suwayomi:exposed-migrations:3.2.0"
# Dependency Injection # Dependency Injection
kodein = "org.kodein.di:kodein-di-conf-jvm:7.20.2" 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 # tray icon
systemtray-core = "com.dorkbox:SystemTray:4.4" systemtray-core = "com.dorkbox:SystemTray:4.4"
systemtray-utils = "com.dorkbox:Utilities:1.46" # version locked by SystemTray systemtray-utils = "com.dorkbox:Utilities:1.46" # version locked by SystemTray
systemtray-desktop = "com.dorkbox:Desktop:1.1" # version locked by SystemTray systemtray-desktop = "com.dorkbox:Desktop:1.1" # version locked by SystemTray
# dependencies of Tachiyomi extensions # 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" rxjava = "io.reactivex:rxjava:1.3.8"
jsoup = "org.jsoup:jsoup:1.18.1" jsoup = "org.jsoup:jsoup:1.18.1"

View File

@@ -92,6 +92,10 @@ dependencies {
implementation(libs.cron4j) implementation(libs.cron4j)
implementation(libs.cronUtils) implementation(libs.cronUtils)
// koin
implementation(project.dependencies.platform(libs.koin.bom))
implementation(libs.koin.core)
} }
application { application {

View File

@@ -9,16 +9,15 @@ package eu.kanade.tachiyomi
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import uy.kohesive.injekt.Injekt import org.koin.core.context.startKoin
import uy.kohesive.injekt.api.InjektScope
import uy.kohesive.injekt.registry.default.DefaultRegistrar
open class App : Application() { open class App : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
Injekt = InjektScope(DefaultRegistrar())
Injekt.importModule(AppModule(this))
startKoin {
modules(createAppModule(this@App))
}
// if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) // if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree())
} }

View File

@@ -24,19 +24,12 @@ import nl.adaptivity.xmlutil.serialization.XML
import org.kodein.di.DI import org.kodein.di.DI
import org.kodein.di.conf.global import org.kodein.di.conf.global
import org.kodein.di.instance import org.kodein.di.instance
import rx.Observable import org.koin.core.module.Module
import rx.schedulers.Schedulers import org.koin.dsl.module
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
class AppModule( fun createAppModule(app: Application): Module {
val app: Application, return module {
) : InjektModule { single { app }
override fun InjektRegistrar.registerInjectables() {
addSingleton(app)
// addSingletonFactory { PreferencesHelper(app) } // addSingletonFactory { PreferencesHelper(app) }
// //
@@ -46,9 +39,9 @@ class AppModule(
// //
// addSingletonFactory { CoverCache(app) } // addSingletonFactory { CoverCache(app) }
addSingletonFactory { NetworkHelper(app) } single { NetworkHelper(app) }
addSingletonFactory { JavaScriptEngine(app) } single { JavaScriptEngine(app) }
// addSingletonFactory { SourceManager(app).also { get<ExtensionManager>().init(it) } } // addSingletonFactory { SourceManager(app).also { get<ExtensionManager>().init(it) } }
// //
@@ -60,36 +53,30 @@ class AppModule(
// //
// addSingletonFactory { LibrarySyncManager(app) } // addSingletonFactory { LibrarySyncManager(app) }
addSingletonFactory { single {
val json by DI.global.instance<Json>() val json by DI.global.instance<Json>()
json json
} }
addSingletonFactory { single {
val xml by DI.global.instance<XML>() val xml by DI.global.instance<XML>()
xml xml
} }
addSingletonFactory { single {
val protobuf by DI.global.instance<ProtoBuf>() val protobuf by DI.global.instance<ProtoBuf>()
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<PreferencesHelper>() }
rxAsync { get<NetworkHelper>() } // rxAsync {
rxAsync {
// get<SourceManager>() // get<SourceManager>()
// get<DownloadManager>() // get<DownloadManager>()
} // }
// rxAsync { get<DatabaseHelper>() } // rxAsync { get<DatabaseHelper>() }
}
private fun rxAsync(block: () -> Unit) {
Observable.fromCallable { block() }.subscribeOn(Schedulers.computation()).subscribe()
}
} }