From 04cb974fe7ece5052bf3db3adfca885f30e95fab Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 4 Jul 2026 14:52:00 -0600 Subject: [PATCH 1/5] Draft new AppConfig API --- .../lagradost/cloudstream3/utils/AppConfig.kt | 71 +++++++++++++++++++ .../lagradost/cloudstream3/utils/AppDebug.kt | 10 --- 2 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt delete mode 100644 library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt new file mode 100644 index 00000000000..42349e78d3b --- /dev/null +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt @@ -0,0 +1,71 @@ +package com.lagradost.cloudstream3.utils + +import com.lagradost.cloudstream3.InternalAPI +import kotlinx.atomicfu.locks.SynchronizedObject +import kotlinx.atomicfu.locks.synchronized +import kotlin.concurrent.Volatile + +// Remove and update usages of it after next stable +// It is used in inline code so we can only actually +// replace it once the code also exists on stable. +@InternalAPI +object AppDebug { + @Volatile + var isDebug: Boolean = false +} + +@InternalAPI +enum class AppFlavor { + Stable, + Prerelease, + Debug; + + val isDebug: Boolean get() = this == Debug + val isPrerelease: Boolean get() = this == Prerelease + val isStable: Boolean get() = this == Stable + + companion object { + fun fromString(value: String?): AppFlavor { + if (value == null) return Stable + return entries.firstOrNull { it.name.equals(value, ignoreCase = true) } ?: Stable + } + } +} + +@InternalAPI +object AppConfig : SynchronizedObject() { + /* FLAVORS */ + @Volatile + private var flavor: AppFlavor = AppFlavor.Stable + + fun setFlavor(value: AppFlavor) { + flavor = value + } + + fun setFlavor(value: String?) { + flavor = AppFlavor.fromString(value) + } + + val isDebug: Boolean get() = flavor.isDebug + val isPrerelease: Boolean get() = flavor.isPrerelease + val isStable: Boolean get() = flavor.isStable + + /* STRINGS */ + private val strings = mutableMapOf() + + fun setString(key: String, value: String) { + synchronized(this) { strings[key] = value } + } + + fun setStrings(values: Map) { + synchronized(this) { strings.putAll(values) } + } + + fun getString(key: String): String? { + synchronized(this) { return strings[key] } + } + + fun getStringOrDefault(key: String, default: String): String { + synchronized(this) { return strings[key] ?: default } + } +} diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt deleted file mode 100644 index 180aee11a78..00000000000 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppDebug.kt +++ /dev/null @@ -1,10 +0,0 @@ -package com.lagradost.cloudstream3.utils - -import com.lagradost.cloudstream3.InternalAPI -import kotlin.concurrent.Volatile - -@InternalAPI -object AppDebug { - @Volatile - var isDebug: Boolean = false -} From 461ef2b2c19ee447beccf6b379c5031a9570e995 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 4 Jul 2026 15:15:21 -0600 Subject: [PATCH 2/5] Better API --- .../lagradost/cloudstream3/utils/AppConfig.kt | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt index 42349e78d3b..6616d169924 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt @@ -1,8 +1,6 @@ package com.lagradost.cloudstream3.utils import com.lagradost.cloudstream3.InternalAPI -import kotlinx.atomicfu.locks.SynchronizedObject -import kotlinx.atomicfu.locks.synchronized import kotlin.concurrent.Volatile // Remove and update usages of it after next stable @@ -33,8 +31,14 @@ enum class AppFlavor { } @InternalAPI -object AppConfig : SynchronizedObject() { - /* FLAVORS */ +enum class AppString { + // TODO + AppName, +} + +@InternalAPI +object AppConfig { + /* FLAVOR */ @Volatile private var flavor: AppFlavor = AppFlavor.Stable @@ -51,21 +55,18 @@ object AppConfig : SynchronizedObject() { val isStable: Boolean get() = flavor.isStable /* STRINGS */ - private val strings = mutableMapOf() - - fun setString(key: String, value: String) { - synchronized(this) { strings[key] = value } - } + @Volatile + private var strings: Map = emptyMap() - fun setStrings(values: Map) { - synchronized(this) { strings.putAll(values) } + fun setStrings(block: MutableMap.() -> Unit) { + strings = buildMap(block) } - fun getString(key: String): String? { - synchronized(this) { return strings[key] } + fun getString(key: AppString): String? { + return strings[key] } - fun getStringOrDefault(key: String, default: String): String { - synchronized(this) { return strings[key] ?: default } + fun getStringOrDefault(key: AppString, default: String): String { + return strings[key] ?: default } } From 19be08fe85938b546948a68ba5146015fb245c3f Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sat, 4 Jul 2026 15:45:10 -0600 Subject: [PATCH 3/5] Update --- .../kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt index 6616d169924..2fa9e0d9da6 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt @@ -38,7 +38,7 @@ enum class AppString { @InternalAPI object AppConfig { - /* FLAVOR */ + /* FLAVORS */ @Volatile private var flavor: AppFlavor = AppFlavor.Stable From ca615557c5cc33841fdb013c5f8c74022452ce52 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sun, 5 Jul 2026 10:44:39 -0600 Subject: [PATCH 4/5] Order --- .../kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt index 2fa9e0d9da6..757cec0124f 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt @@ -14,9 +14,9 @@ object AppDebug { @InternalAPI enum class AppFlavor { - Stable, + Debug, Prerelease, - Debug; + Stable; val isDebug: Boolean get() = this == Debug val isPrerelease: Boolean get() = this == Prerelease From 80477d4e1ff77896960b8f44951dfbf6c78492d8 Mon Sep 17 00:00:00 2001 From: Luna712 <142361265+Luna712@users.noreply.github.com> Date: Sun, 5 Jul 2026 12:15:40 -0600 Subject: [PATCH 5/5] Split AppFlavor Debug into AppBuildType --- .../lagradost/cloudstream3/utils/AppConfig.kt | 46 +++++++++++-------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt index 757cec0124f..77c4cdeee01 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/utils/AppConfig.kt @@ -12,21 +12,26 @@ object AppDebug { var isDebug: Boolean = false } +private inline fun > enumFromString(value: String?, default: T): T { + if (value == null) return default + return enumValues().firstOrNull { it.name.equals(value, ignoreCase = true) } ?: default +} + @InternalAPI -enum class AppFlavor { - Debug, - Prerelease, - Stable; +enum class AppBuildType { + Debug, Release; - val isDebug: Boolean get() = this == Debug - val isPrerelease: Boolean get() = this == Prerelease - val isStable: Boolean get() = this == Stable + companion object { + fun fromString(value: String?): AppBuildType = enumFromString(value, Release) + } +} + +@InternalAPI +enum class AppFlavor { + Prerelease, Stable; companion object { - fun fromString(value: String?): AppFlavor { - if (value == null) return Stable - return entries.firstOrNull { it.name.equals(value, ignoreCase = true) } ?: Stable - } + fun fromString(value: String?): AppFlavor = enumFromString(value, Stable) } } @@ -38,21 +43,24 @@ enum class AppString { @InternalAPI object AppConfig { + + /* BUILD TYPES */ + @Volatile + private var buildType: AppBuildType = AppBuildType.Release + fun setBuildType(value: AppBuildType) { + buildType = value + } + /* FLAVORS */ @Volatile private var flavor: AppFlavor = AppFlavor.Stable - fun setFlavor(value: AppFlavor) { flavor = value } - fun setFlavor(value: String?) { - flavor = AppFlavor.fromString(value) - } - - val isDebug: Boolean get() = flavor.isDebug - val isPrerelease: Boolean get() = flavor.isPrerelease - val isStable: Boolean get() = flavor.isStable + /* CONVENIENCE ACCESS */ + val isDebug: Boolean get() = buildType == AppBuildType.Debug + val isPrerelease: Boolean get() = flavor == AppFlavor.Prerelease /* STRINGS */ @Volatile