diff --git a/build.gradle.kts b/build.gradle.kts index a237acbf..543af5d0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -134,26 +134,6 @@ subprojects { toolVersion = "0.8.7" } } - - plugins.withType { - configure { - 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.addSrcDir(configuration: String, srcDir: String) { - filter { it.name.contains(configuration) } - .forEach { - it.kotlin.srcDir(srcDir) - } } fun isNonStable(version: String): Boolean { diff --git a/buildSrc/src/main/kotlin/Config.kt b/buildSrc/src/main/kotlin/Config.kt index 285490e4..43bc1c0e 100644 --- a/buildSrc/src/main/kotlin/Config.kt +++ b/buildSrc/src/main/kotlin/Config.kt @@ -12,6 +12,4 @@ object Config { val desktopJvmTarget = JavaVersion.VERSION_17 val androidJvmTarget = JavaVersion.VERSION_11 - - const val androidDev = false } \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts index bc7bf7d2..c66e8737 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -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 } } diff --git a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt b/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt index 7672056a..f6fcfe28 100644 --- a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt @@ -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 = "_"), diff --git a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/Locale.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/Locale.kt index 7a5db548..0ad8bb28 100644 --- a/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/Locale.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/lang/Locale.kt @@ -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 diff --git a/core/src/jvmMain/kotlin/ca/gosyer/jui/core/prefs/JvmAdapters.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardAdapters.kt similarity index 100% rename from core/src/jvmMain/kotlin/ca/gosyer/jui/core/prefs/JvmAdapters.kt rename to core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardAdapters.kt diff --git a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreference.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt similarity index 98% rename from core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreference.kt rename to core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt index e085363f..9c34941a 100644 --- a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreference.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreference.kt @@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.stateIn -internal class AndroidPreference( +internal class StandardPreference( private val preferences: ObservableSettings, private val key: String, private val defaultValue: T, diff --git a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreferenceStore.kt b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt similarity index 74% rename from core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreferenceStore.kt rename to core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt index 2fd0f80a..ca33082f 100644 --- a/core/src/androidMain/kotlin/ca/gosyer/jui/core/prefs/AndroidPreferenceStore.kt +++ b/core/src/commonMain/kotlin/ca/gosyer/jui/core/prefs/StandardPreferenceStore.kt @@ -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 { - 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 { - 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 { - 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 { - 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 { - return AndroidPreference(preferences, key, defaultValue, BooleanAdapter) + return StandardPreference(preferences, key, defaultValue, BooleanAdapter) } /** * Returns a [Set] preference for this [key]. */ override fun getStringSet(key: String, defaultValue: Set): Preference> { - 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 { 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 { val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule) - return AndroidPreference(preferences, key, defaultValue, adapter) + return StandardPreference(preferences, key, defaultValue, adapter) } } diff --git a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreference.kt b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreference.kt deleted file mode 100644 index 7697d98d..00000000 --- a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreference.kt +++ /dev/null @@ -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( - private val preferences: ObservableSettings, - private val key: String, - private val defaultValue: T, - private val adapter: Adapter -) : Preference { - - /** - * 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 { - 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 { - return changes().stateIn(scope, SharingStarted.Eagerly, get()) - } -} diff --git a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreferenceStore.kt b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreferenceStore.kt deleted file mode 100644 index 3b3eacac..00000000 --- a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/JvmPreferenceStore.kt +++ /dev/null @@ -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 { - return JvmPreference(preferences, key, defaultValue, StringAdapter) - } - - /** - * Returns a [Long] preference for this [key]. - */ - override fun getLong(key: String, defaultValue: Long): Preference { - return JvmPreference(preferences, key, defaultValue, LongAdapter) - } - - /** - * Returns an [Int] preference for this [key]. - */ - override fun getInt(key: String, defaultValue: Int): Preference { - return JvmPreference(preferences, key, defaultValue, IntAdapter) - } - - /** - * Returns a [Float] preference for this [key]. - */ - override fun getFloat(key: String, defaultValue: Float): Preference { - return JvmPreference(preferences, key, defaultValue, FloatAdapter) - } - - /** - * Returns a [Boolean] preference for this [key]. - */ - override fun getBoolean(key: String, defaultValue: Boolean): Preference { - return JvmPreference(preferences, key, defaultValue, BooleanAdapter) - } - - /** - * Returns a [Set] preference for this [key]. - */ - override fun getStringSet(key: String, defaultValue: Set): Preference> { - return JvmPreference(preferences, key, defaultValue, StringSetAdapter) - } - - /** - * Returns preference of type [T] for this [key]. The [serializer] and [deserializer] function - * must be provided. - */ - override fun getObject( - key: String, - defaultValue: T, - serializer: (T) -> String, - deserializer: (String) -> T - ): Preference { - 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 getJsonObject( - key: String, - defaultValue: T, - serializer: KSerializer, - serializersModule: SerializersModule - ): Preference { - val adapter = JsonObjectAdapter(defaultValue, serializer, serializersModule) - return JvmPreference(preferences, key, defaultValue, adapter) - } -} diff --git a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt index 885f816d..328027a1 100644 --- a/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt +++ b/core/src/desktopMain/kotlin/ca/gosyer/jui/core/prefs/PreferenceStoreFactory.kt @@ -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 = "/")) ) diff --git a/data/build.gradle.kts b/data/build.gradle.kts index 762d1e0d..034e40a1 100644 --- a/data/build.gradle.kts +++ b/data/build.gradle.kts @@ -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 } } diff --git a/domain/build.gradle.kts b/domain/build.gradle.kts index a4fe7484..d5090dd4 100644 --- a/domain/build.gradle.kts +++ b/domain/build.gradle.kts @@ -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 } } diff --git a/domain/src/androidMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt b/domain/src/androidMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt index ee32ccd0..c0b847a0 100644 --- a/domain/src/androidMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt +++ b/domain/src/androidMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt @@ -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 } diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt index 187b536e..53992830 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt @@ -6,4 +6,4 @@ package ca.gosyer.jui.domain -expect interface DomainComponent +expect interface DomainComponent : SharedDomainComponent diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/SharedDomainComponent.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/SharedDomainComponent.kt new file mode 100644 index 00000000..c8d3cb06 --- /dev/null +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/SharedDomainComponent.kt @@ -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) +} \ No newline at end of file diff --git a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt index 8c67bf8a..8cbc2b0c 100644 --- a/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt +++ b/domain/src/commonMain/kotlin/ca/gosyer/jui/domain/server/HttpClient.kt @@ -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 +expect fun HttpClientConfig.configurePlatform() + class HttpProvider @Inject constructor() { fun get(serverPreferences: ServerPreferences): Http { return HttpClient(Engine) { + configurePlatform() + engine { proxy = when (serverPreferences.proxy().get()) { Proxy.NO_PROXY -> null diff --git a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt index 278872ee..f056358f 100644 --- a/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt +++ b/domain/src/desktopMain/kotlin/ca/gosyer/jui/domain/DomainComponent.kt @@ -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 } diff --git a/domain/src/jvmMain/kotlin/ca/gosyer/jui/domain/server/Engine.kt b/domain/src/jvmMain/kotlin/ca/gosyer/jui/domain/server/Engine.kt index 156e1d18..2ac15127 100644 --- a/domain/src/jvmMain/kotlin/ca/gosyer/jui/domain/server/Engine.kt +++ b/domain/src/jvmMain/kotlin/ca/gosyer/jui/domain/server/Engine.kt @@ -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 get() = OkHttp + +actual fun HttpClientConfig.configurePlatform() { + @Suppress("UNCHECKED_CAST") + (this as HttpClientConfig).realConfigurePlatform() +} + +private fun HttpClientConfig.realConfigurePlatform() {} \ No newline at end of file diff --git a/presentation/build.gradle.kts b/presentation/build.gradle.kts index 16d6c374..a293e862 100644 --- a/presentation/build.gradle.kts +++ b/presentation/build.gradle.kts @@ -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 } } diff --git a/ui-core/build.gradle.kts b/ui-core/build.gradle.kts index 84a91081..7fe058bb 100644 --- a/ui-core/build.gradle.kts +++ b/ui-core/build.gradle.kts @@ -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 } }