mirror of
https://github.com/Suwayomi/TachideskJUI.git
synced 2025-12-10 14:52:03 +01:00
Use HMPP and deduplicate a bunch of platform specific code
This commit is contained in:
@@ -134,26 +134,6 @@ subprojects {
|
||||
toolVersion = "0.8.7"
|
||||
}
|
||||
}
|
||||
|
||||
plugins.withType<org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper> {
|
||||
configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
|
||||
afterEvaluate {
|
||||
if (!Config.androidDev) {
|
||||
sourceSets.addSrcDir("desktopMain", "src/jvmMain/kotlin")
|
||||
sourceSets.addSrcDir("desktopTest", "src/jvmTest/kotlin")
|
||||
}
|
||||
sourceSets.addSrcDir("androidMain", "src/jvmMain/kotlin")
|
||||
sourceSets.addSrcDir("androidTest", "src/jvmTest/kotlin")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun NamedDomainObjectContainer<org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet>.addSrcDir(configuration: String, srcDir: String) {
|
||||
filter { it.name.contains(configuration) }
|
||||
.forEach {
|
||||
it.kotlin.srcDir(srcDir)
|
||||
}
|
||||
}
|
||||
|
||||
fun isNonStable(version: String): Boolean {
|
||||
|
||||
@@ -12,6 +12,4 @@ object Config {
|
||||
|
||||
val desktopJvmTarget = JavaVersion.VERSION_17
|
||||
val androidJvmTarget = JavaVersion.VERSION_11
|
||||
|
||||
const val androidDev = false
|
||||
}
|
||||
@@ -59,23 +59,27 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val jvmMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val desktopMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.appDirs)
|
||||
}
|
||||
}
|
||||
val desktopTest by getting {
|
||||
}
|
||||
val desktopTest by getting
|
||||
|
||||
val androidMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.compose.ui.text)
|
||||
}
|
||||
}
|
||||
val androidTest by getting {
|
||||
}
|
||||
val androidTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import me.tatarka.inject.annotations.Inject
|
||||
|
||||
actual class PreferenceStoreFactory @Inject constructor(private val context: Context) {
|
||||
actual fun create(vararg names: String): PreferenceStore {
|
||||
return AndroidPreferenceStore(
|
||||
return StandardPreferenceStore(
|
||||
SharedPreferencesSettings(
|
||||
context.getSharedPreferences(
|
||||
names.joinToString(separator = "_"),
|
||||
|
||||
@@ -8,8 +8,16 @@ package ca.gosyer.jui.core.lang
|
||||
|
||||
import androidx.compose.ui.text.intl.Locale
|
||||
|
||||
/**
|
||||
* First Locale: en_IN
|
||||
* Language: English
|
||||
*/
|
||||
expect fun Locale.getDisplayLanguage(displayLocale: Locale): String
|
||||
|
||||
/**
|
||||
* First Locale: en_US
|
||||
* Language: English (United States)
|
||||
*/
|
||||
expect fun Locale.getDisplayName(displayLocale: Locale): String
|
||||
|
||||
expect val Locale.displayName: String
|
||||
|
||||
@@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
|
||||
internal class AndroidPreference<T>(
|
||||
internal class StandardPreference<T>(
|
||||
private val preferences: ObservableSettings,
|
||||
private val key: String,
|
||||
private val defaultValue: T,
|
||||
@@ -10,48 +10,48 @@ import com.russhwolf.settings.ObservableSettings
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
|
||||
class AndroidPreferenceStore(private val preferences: ObservableSettings) : PreferenceStore {
|
||||
class StandardPreferenceStore(private val preferences: ObservableSettings) : PreferenceStore {
|
||||
|
||||
/**
|
||||
* Returns an [String] preference for this [key].
|
||||
*/
|
||||
override fun getString(key: String, defaultValue: String): Preference<String> {
|
||||
return AndroidPreference(preferences, key, defaultValue, StringAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, StringAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Long] preference for this [key].
|
||||
*/
|
||||
override fun getLong(key: String, defaultValue: Long): Preference<Long> {
|
||||
return AndroidPreference(preferences, key, defaultValue, LongAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, LongAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an [Int] preference for this [key].
|
||||
*/
|
||||
override fun getInt(key: String, defaultValue: Int): Preference<Int> {
|
||||
return AndroidPreference(preferences, key, defaultValue, IntAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, IntAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Float] preference for this [key].
|
||||
*/
|
||||
override fun getFloat(key: String, defaultValue: Float): Preference<Float> {
|
||||
return AndroidPreference(preferences, key, defaultValue, FloatAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, FloatAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Boolean] preference for this [key].
|
||||
*/
|
||||
override fun getBoolean(key: String, defaultValue: Boolean): Preference<Boolean> {
|
||||
return AndroidPreference(preferences, key, defaultValue, BooleanAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, BooleanAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set<String>] preference for this [key].
|
||||
*/
|
||||
override fun getStringSet(key: String, defaultValue: Set<String>): Preference<Set<String>> {
|
||||
return AndroidPreference(preferences, key, defaultValue, StringSetAdapter)
|
||||
return StandardPreference(preferences, key, defaultValue, StringSetAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -65,7 +65,7 @@ class AndroidPreferenceStore(private val preferences: ObservableSettings) : Pref
|
||||
deserializer: (String) -> T
|
||||
): Preference<T> {
|
||||
val adapter = ObjectAdapter(serializer, deserializer)
|
||||
return AndroidPreference(preferences, key, defaultValue, adapter)
|
||||
return StandardPreference(preferences, key, defaultValue, adapter)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -78,6 +78,6 @@ class AndroidPreferenceStore(private val preferences: ObservableSettings) : Pref
|
||||
serializersModule: SerializersModule
|
||||
): Preference<T> {
|
||||
val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule)
|
||||
return AndroidPreference(preferences, key, defaultValue, adapter)
|
||||
return StandardPreference(preferences, key, defaultValue, adapter)
|
||||
}
|
||||
}
|
||||
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.core.prefs
|
||||
|
||||
import com.russhwolf.settings.ObservableSettings
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.callbackFlow
|
||||
import kotlinx.coroutines.flow.stateIn
|
||||
|
||||
internal class JvmPreference<T>(
|
||||
private val preferences: ObservableSettings,
|
||||
private val key: String,
|
||||
private val defaultValue: T,
|
||||
private val adapter: Adapter<T>
|
||||
) : Preference<T> {
|
||||
|
||||
/**
|
||||
* Returns the key of this preference.
|
||||
*/
|
||||
override fun key(): String {
|
||||
return key
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current value of this preference.
|
||||
*/
|
||||
override fun get(): T {
|
||||
return if (isSet()) {
|
||||
adapter.get(key, preferences)
|
||||
} else {
|
||||
defaultValue
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a new [value] for this preference.
|
||||
*/
|
||||
override fun set(value: T) {
|
||||
adapter.set(key, value, preferences)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether there's an existing entry for this preference.
|
||||
*/
|
||||
override fun isSet(): Boolean {
|
||||
return adapter.isSet(preferences.keys, key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the entry of this preference.
|
||||
*/
|
||||
override fun delete() {
|
||||
preferences.remove(key)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default value of this preference
|
||||
*/
|
||||
override fun defaultValue(): T {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a cold [Flow] of this preference to receive updates when its value changes.
|
||||
*/
|
||||
override fun changes(): Flow<T> {
|
||||
return callbackFlow {
|
||||
val listener = adapter.addListener(key, preferences) {
|
||||
trySend(get())
|
||||
}
|
||||
awaitClose { listener.deactivate() }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a hot [StateFlow] of this preference bound to the given [scope], allowing to read the
|
||||
* current value and receive preference updates.
|
||||
*/
|
||||
override fun stateIn(scope: CoroutineScope): StateFlow<T> {
|
||||
return changes().stateIn(scope, SharingStarted.Eagerly, get())
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.core.prefs
|
||||
|
||||
import com.russhwolf.settings.ObservableSettings
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.modules.SerializersModule
|
||||
|
||||
class JvmPreferenceStore(private val preferences: ObservableSettings) : PreferenceStore {
|
||||
|
||||
/**
|
||||
* Returns an [String] preference for this [key].
|
||||
*/
|
||||
override fun getString(key: String, defaultValue: String): Preference<String> {
|
||||
return JvmPreference(preferences, key, defaultValue, StringAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Long] preference for this [key].
|
||||
*/
|
||||
override fun getLong(key: String, defaultValue: Long): Preference<Long> {
|
||||
return JvmPreference(preferences, key, defaultValue, LongAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an [Int] preference for this [key].
|
||||
*/
|
||||
override fun getInt(key: String, defaultValue: Int): Preference<Int> {
|
||||
return JvmPreference(preferences, key, defaultValue, IntAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Float] preference for this [key].
|
||||
*/
|
||||
override fun getFloat(key: String, defaultValue: Float): Preference<Float> {
|
||||
return JvmPreference(preferences, key, defaultValue, FloatAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Boolean] preference for this [key].
|
||||
*/
|
||||
override fun getBoolean(key: String, defaultValue: Boolean): Preference<Boolean> {
|
||||
return JvmPreference(preferences, key, defaultValue, BooleanAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a [Set<String>] preference for this [key].
|
||||
*/
|
||||
override fun getStringSet(key: String, defaultValue: Set<String>): Preference<Set<String>> {
|
||||
return JvmPreference(preferences, key, defaultValue, StringSetAdapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns preference of type [T] for this [key]. The [serializer] and [deserializer] function
|
||||
* must be provided.
|
||||
*/
|
||||
override fun <T> getObject(
|
||||
key: String,
|
||||
defaultValue: T,
|
||||
serializer: (T) -> String,
|
||||
deserializer: (String) -> T
|
||||
): Preference<T> {
|
||||
val adapter = ObjectAdapter(serializer, deserializer)
|
||||
return JvmPreference(preferences, key, defaultValue, adapter)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns preference of type [T] for this [key]. The [serializer] must be provided.
|
||||
*/
|
||||
override fun <T> getJsonObject(
|
||||
key: String,
|
||||
defaultValue: T,
|
||||
serializer: KSerializer<T>,
|
||||
serializersModule: SerializersModule
|
||||
): Preference<T> {
|
||||
val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule)
|
||||
return JvmPreference(preferences, key, defaultValue, adapter)
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ actual class PreferenceStoreFactory @Inject constructor() {
|
||||
.node("ca/gosyer/tachideskjui")
|
||||
|
||||
actual fun create(vararg names: String): PreferenceStore {
|
||||
return JvmPreferenceStore(
|
||||
return StandardPreferenceStore(
|
||||
PreferencesSettings(
|
||||
rootNode.node(names.joinToString(separator = "/"))
|
||||
)
|
||||
|
||||
@@ -53,21 +53,25 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val desktopMain by getting {
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val desktopTest by getting {
|
||||
val jvmMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val androidMain by getting {
|
||||
val desktopMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val androidTest by getting {
|
||||
val desktopTest by getting
|
||||
|
||||
val androidMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val androidTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,23 +57,28 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val desktopMain by getting {
|
||||
val jvmMain by creating {
|
||||
dependsOn(commonMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.ktor.okHttp)
|
||||
}
|
||||
}
|
||||
val desktopTest by getting {
|
||||
}
|
||||
|
||||
val androidMain by getting {
|
||||
val desktopMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.ktor.okHttp)
|
||||
}
|
||||
}
|
||||
val androidTest by getting {
|
||||
val desktopTest by getting
|
||||
|
||||
val androidMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val androidTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,112 +6,6 @@
|
||||
|
||||
package ca.gosyer.jui.domain
|
||||
|
||||
import ca.gosyer.jui.core.CoreComponent
|
||||
import ca.gosyer.jui.core.di.AppScope
|
||||
import ca.gosyer.jui.domain.download.service.DownloadService
|
||||
import ca.gosyer.jui.domain.extension.service.ExtensionPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryUpdateService
|
||||
import ca.gosyer.jui.domain.migration.interactor.RunMigrations
|
||||
import ca.gosyer.jui.domain.migration.service.MigrationPreferences
|
||||
import ca.gosyer.jui.domain.reader.service.ReaderPreferences
|
||||
import ca.gosyer.jui.domain.server.Http
|
||||
import ca.gosyer.jui.domain.server.HttpProvider
|
||||
import ca.gosyer.jui.domain.server.service.ServerPreferences
|
||||
import ca.gosyer.jui.domain.source.service.CatalogPreferences
|
||||
import ca.gosyer.jui.domain.ui.service.UiPreferences
|
||||
import ca.gosyer.jui.domain.updates.interactor.UpdateChecker
|
||||
import ca.gosyer.jui.domain.updates.service.UpdatePreferences
|
||||
import me.tatarka.inject.annotations.Provides
|
||||
|
||||
actual interface DomainComponent : CoreComponent {
|
||||
// Providers
|
||||
val httpProvider: HttpProvider
|
||||
|
||||
// Factories
|
||||
val migrations: RunMigrations
|
||||
|
||||
val updateChecker: UpdateChecker
|
||||
|
||||
// Singletons
|
||||
val downloadService: DownloadService
|
||||
|
||||
val libraryUpdateService: LibraryUpdateService
|
||||
|
||||
val http: Http
|
||||
|
||||
val serverPreferences: ServerPreferences
|
||||
|
||||
val extensionPreferences: ExtensionPreferences
|
||||
|
||||
val catalogPreferences: CatalogPreferences
|
||||
|
||||
val libraryPreferences: LibraryPreferences
|
||||
|
||||
val readerPreferences: ReaderPreferences
|
||||
|
||||
val uiPreferences: UiPreferences
|
||||
|
||||
val migrationPreferences: MigrationPreferences
|
||||
|
||||
val updatePreferences: UpdatePreferences
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val serverPreferencesFactory: ServerPreferences
|
||||
get() = ServerPreferences(preferenceFactory.create("server"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val extensionPreferencesFactory: ExtensionPreferences
|
||||
get() = ExtensionPreferences(preferenceFactory.create("extension"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val catalogPreferencesFactory: CatalogPreferences
|
||||
get() = CatalogPreferences(preferenceFactory.create("catalog"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryPreferencesFactory: LibraryPreferences
|
||||
get() = LibraryPreferences(preferenceFactory.create("library"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val readerPreferencesFactory: ReaderPreferences
|
||||
get() = ReaderPreferences(preferenceFactory.create("reader")) { name ->
|
||||
preferenceFactory.create("reader", name)
|
||||
}
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val uiPreferencesFactory: UiPreferences
|
||||
get() = UiPreferences(preferenceFactory.create("ui"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val migrationPreferencesFactory: MigrationPreferences
|
||||
get() = MigrationPreferences(preferenceFactory.create("migration"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val updatePreferencesFactory: UpdatePreferences
|
||||
get() = UpdatePreferences(preferenceFactory.create("update"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val httpFactory: Http
|
||||
get() = httpProvider.get(serverPreferences)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryUpdateServiceFactory: LibraryUpdateService
|
||||
get() = LibraryUpdateService(serverPreferences, http)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val downloadServiceFactory: DownloadService
|
||||
get() = DownloadService(serverPreferences, http)
|
||||
|
||||
actual interface DomainComponent : SharedDomainComponent {
|
||||
companion object
|
||||
}
|
||||
|
||||
@@ -6,4 +6,4 @@
|
||||
|
||||
package ca.gosyer.jui.domain
|
||||
|
||||
expect interface DomainComponent
|
||||
expect interface DomainComponent : SharedDomainComponent
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package ca.gosyer.jui.domain
|
||||
|
||||
import ca.gosyer.jui.core.CoreComponent
|
||||
import ca.gosyer.jui.core.di.AppScope
|
||||
import ca.gosyer.jui.domain.download.service.DownloadService
|
||||
import ca.gosyer.jui.domain.extension.service.ExtensionPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryUpdateService
|
||||
import ca.gosyer.jui.domain.migration.interactor.RunMigrations
|
||||
import ca.gosyer.jui.domain.migration.service.MigrationPreferences
|
||||
import ca.gosyer.jui.domain.reader.service.ReaderPreferences
|
||||
import ca.gosyer.jui.domain.server.Http
|
||||
import ca.gosyer.jui.domain.server.HttpProvider
|
||||
import ca.gosyer.jui.domain.server.service.ServerPreferences
|
||||
import ca.gosyer.jui.domain.source.service.CatalogPreferences
|
||||
import ca.gosyer.jui.domain.ui.service.UiPreferences
|
||||
import ca.gosyer.jui.domain.updates.interactor.UpdateChecker
|
||||
import ca.gosyer.jui.domain.updates.service.UpdatePreferences
|
||||
import me.tatarka.inject.annotations.Provides
|
||||
|
||||
interface SharedDomainComponent : CoreComponent {
|
||||
// Providers
|
||||
val httpProvider: HttpProvider
|
||||
|
||||
// Factories
|
||||
val migrations: RunMigrations
|
||||
|
||||
val updateChecker: UpdateChecker
|
||||
|
||||
// Singletons
|
||||
val downloadService: DownloadService
|
||||
|
||||
val libraryUpdateService: LibraryUpdateService
|
||||
|
||||
val http: Http
|
||||
|
||||
val serverPreferences: ServerPreferences
|
||||
|
||||
val extensionPreferences: ExtensionPreferences
|
||||
|
||||
val catalogPreferences: CatalogPreferences
|
||||
|
||||
val libraryPreferences: LibraryPreferences
|
||||
|
||||
val readerPreferences: ReaderPreferences
|
||||
|
||||
val uiPreferences: UiPreferences
|
||||
|
||||
val migrationPreferences: MigrationPreferences
|
||||
|
||||
val updatePreferences: UpdatePreferences
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val serverPreferencesFactory: ServerPreferences
|
||||
get() = ServerPreferences(preferenceFactory.create("server"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val extensionPreferencesFactory: ExtensionPreferences
|
||||
get() = ExtensionPreferences(preferenceFactory.create("extension"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val catalogPreferencesFactory: CatalogPreferences
|
||||
get() = CatalogPreferences(preferenceFactory.create("catalog"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryPreferencesFactory: LibraryPreferences
|
||||
get() = LibraryPreferences(preferenceFactory.create("library"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val readerPreferencesFactory: ReaderPreferences
|
||||
get() = ReaderPreferences(preferenceFactory.create("reader")) { name ->
|
||||
preferenceFactory.create("reader", name)
|
||||
}
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val uiPreferencesFactory: UiPreferences
|
||||
get() = UiPreferences(preferenceFactory.create("ui"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val migrationPreferencesFactory: MigrationPreferences
|
||||
get() = MigrationPreferences(preferenceFactory.create("migration"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val updatePreferencesFactory: UpdatePreferences
|
||||
get() = UpdatePreferences(preferenceFactory.create("update"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val httpFactory: Http
|
||||
get() = httpProvider.get(serverPreferences)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryUpdateServiceFactory: LibraryUpdateService
|
||||
get() = LibraryUpdateService(serverPreferences, http)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val downloadServiceFactory: DownloadService
|
||||
get() = DownloadService(serverPreferences, http)
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import ca.gosyer.jui.domain.server.model.Auth
|
||||
import ca.gosyer.jui.domain.server.model.Proxy
|
||||
import ca.gosyer.jui.domain.server.service.ServerPreferences
|
||||
import io.ktor.client.HttpClient
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngineConfig
|
||||
import io.ktor.client.engine.HttpClientEngineFactory
|
||||
import io.ktor.client.engine.ProxyBuilder
|
||||
@@ -32,12 +33,15 @@ import io.ktor.client.plugins.auth.Auth as AuthPlugin
|
||||
|
||||
typealias Http = HttpClient
|
||||
|
||||
@Suppress("NO_ACTUAL_FOR_EXPECT")
|
||||
expect val Engine: HttpClientEngineFactory<HttpClientEngineConfig>
|
||||
|
||||
expect fun HttpClientConfig<HttpClientEngineConfig>.configurePlatform()
|
||||
|
||||
class HttpProvider @Inject constructor() {
|
||||
fun get(serverPreferences: ServerPreferences): Http {
|
||||
return HttpClient(Engine) {
|
||||
configurePlatform()
|
||||
|
||||
engine {
|
||||
proxy = when (serverPreferences.proxy().get()) {
|
||||
Proxy.NO_PROXY -> null
|
||||
|
||||
@@ -6,129 +6,28 @@
|
||||
|
||||
package ca.gosyer.jui.domain
|
||||
|
||||
import ca.gosyer.jui.core.CoreComponent
|
||||
import ca.gosyer.jui.core.di.AppScope
|
||||
import ca.gosyer.jui.domain.download.service.DownloadService
|
||||
import ca.gosyer.jui.domain.extension.service.ExtensionPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryPreferences
|
||||
import ca.gosyer.jui.domain.library.service.LibraryUpdateService
|
||||
import ca.gosyer.jui.domain.migration.interactor.RunMigrations
|
||||
import ca.gosyer.jui.domain.migration.service.MigrationPreferences
|
||||
import ca.gosyer.jui.domain.reader.service.ReaderPreferences
|
||||
import ca.gosyer.jui.domain.server.Http
|
||||
import ca.gosyer.jui.domain.server.HttpProvider
|
||||
import ca.gosyer.jui.domain.server.service.ServerHostPreferences
|
||||
import ca.gosyer.jui.domain.server.service.ServerPreferences
|
||||
import ca.gosyer.jui.domain.server.service.ServerService
|
||||
import ca.gosyer.jui.domain.source.service.CatalogPreferences
|
||||
import ca.gosyer.jui.domain.ui.service.UiPreferences
|
||||
import ca.gosyer.jui.domain.updates.interactor.UpdateChecker
|
||||
import ca.gosyer.jui.domain.updates.service.UpdatePreferences
|
||||
import me.tatarka.inject.annotations.Provides
|
||||
|
||||
actual interface DomainComponent : CoreComponent {
|
||||
|
||||
// Providers
|
||||
val httpProvider: HttpProvider
|
||||
|
||||
// Factories
|
||||
val migrations: RunMigrations
|
||||
|
||||
val updateChecker: UpdateChecker
|
||||
actual interface DomainComponent : SharedDomainComponent {
|
||||
|
||||
// Singletons
|
||||
val downloadService: DownloadService
|
||||
|
||||
val libraryUpdateService: LibraryUpdateService
|
||||
|
||||
val serverService: ServerService
|
||||
|
||||
val http: Http
|
||||
|
||||
val serverHostPreferences: ServerHostPreferences
|
||||
|
||||
val serverPreferences: ServerPreferences
|
||||
|
||||
val extensionPreferences: ExtensionPreferences
|
||||
|
||||
val catalogPreferences: CatalogPreferences
|
||||
|
||||
val libraryPreferences: LibraryPreferences
|
||||
|
||||
val readerPreferences: ReaderPreferences
|
||||
|
||||
val uiPreferences: UiPreferences
|
||||
|
||||
val migrationPreferences: MigrationPreferences
|
||||
|
||||
val updatePreferences: UpdatePreferences
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val serverHostPreferencesFactory: ServerHostPreferences
|
||||
get() = ServerHostPreferences(preferenceFactory.create("host"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val serverPreferencesFactory: ServerPreferences
|
||||
get() = ServerPreferences(preferenceFactory.create("server"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val extensionPreferencesFactory: ExtensionPreferences
|
||||
get() = ExtensionPreferences(preferenceFactory.create("extension"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val catalogPreferencesFactory: CatalogPreferences
|
||||
get() = CatalogPreferences(preferenceFactory.create("catalog"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryPreferencesFactory: LibraryPreferences
|
||||
get() = LibraryPreferences(preferenceFactory.create("library"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val readerPreferencesFactory: ReaderPreferences
|
||||
get() = ReaderPreferences(preferenceFactory.create("reader")) { name ->
|
||||
preferenceFactory.create("reader", name)
|
||||
}
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val uiPreferencesFactory: UiPreferences
|
||||
get() = UiPreferences(preferenceFactory.create("ui"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val migrationPreferencesFactory: MigrationPreferences
|
||||
get() = MigrationPreferences(preferenceFactory.create("migration"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val updatePreferencesFactory: UpdatePreferences
|
||||
get() = UpdatePreferences(preferenceFactory.create("update"))
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val httpFactory: Http
|
||||
get() = httpProvider.get(serverPreferences)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val serverServiceFactory: ServerService
|
||||
get() = ServerService(serverHostPreferences)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val libraryUpdateServiceFactory: LibraryUpdateService
|
||||
get() = LibraryUpdateService(serverPreferences, http)
|
||||
|
||||
@get:AppScope
|
||||
@get:Provides
|
||||
val downloadServiceFactory: DownloadService
|
||||
get() = DownloadService(serverPreferences, http)
|
||||
|
||||
companion object
|
||||
}
|
||||
|
||||
@@ -6,9 +6,18 @@
|
||||
|
||||
package ca.gosyer.jui.domain.server
|
||||
|
||||
import io.ktor.client.HttpClientConfig
|
||||
import io.ktor.client.engine.HttpClientEngineConfig
|
||||
import io.ktor.client.engine.HttpClientEngineFactory
|
||||
import io.ktor.client.engine.okhttp.OkHttp
|
||||
import io.ktor.client.engine.okhttp.OkHttpConfig
|
||||
|
||||
actual val Engine: HttpClientEngineFactory<HttpClientEngineConfig>
|
||||
get() = OkHttp
|
||||
|
||||
actual fun HttpClientConfig<HttpClientEngineConfig>.configurePlatform() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
(this as HttpClientConfig<OkHttpConfig>).realConfigurePlatform()
|
||||
}
|
||||
|
||||
private fun HttpClientConfig<OkHttpConfig>.realConfigurePlatform() {}
|
||||
@@ -71,16 +71,21 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val jvmMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val desktopMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.coroutines.swing)
|
||||
}
|
||||
}
|
||||
val desktopTest by getting {
|
||||
}
|
||||
val desktopTest by getting
|
||||
|
||||
val androidMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.bundles.compose.android)
|
||||
@@ -89,8 +94,7 @@ kotlin {
|
||||
api(libs.androidx.activity.compose)
|
||||
}
|
||||
}
|
||||
val androidTest by getting {
|
||||
}
|
||||
val androidTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,22 +55,26 @@ kotlin {
|
||||
}
|
||||
}
|
||||
|
||||
val jvmMain by creating {
|
||||
dependsOn(commonMain)
|
||||
}
|
||||
|
||||
val desktopMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
}
|
||||
val desktopTest by getting {
|
||||
}
|
||||
val desktopTest by getting
|
||||
|
||||
val androidMain by getting {
|
||||
dependsOn(jvmMain)
|
||||
dependencies {
|
||||
api(kotlin("stdlib-jdk8"))
|
||||
api(libs.bundles.compose.android)
|
||||
}
|
||||
}
|
||||
val androidTest by getting {
|
||||
}
|
||||
val androidTest by getting
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user