settings wird so langsam (#1)
This commit is contained in:
1 parent
231132dd9e
commit
632d7c34ef
10 files changed
+68
-3
No files matched your search
@@ -0,0 +1,3 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
expect fun configProperties(): ConfigProperties
|
||||
@@ -0,0 +1,8 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
import org.koin.core.annotation.Singleton
|
||||
|
||||
@Singleton
|
||||
actual fun configProperties(): ConfigProperties {
|
||||
return JvmConfigProperties("config.properties")
|
||||
}
|
||||
@@ -19,6 +19,7 @@ import kotlinx.coroutines.withContext
|
||||
import net.keinekekse.app.auth.AuthResult
|
||||
import net.keinekekse.app.auth.Authenticator
|
||||
import net.keinekekse.app.books.di.KoinApp
|
||||
import net.keinekekse.app.config.ConfigProperties
|
||||
import net.keinekekse.app.config.Settings
|
||||
import net.keinekekse.app.ui.ProgressIndicator
|
||||
import org.koin.compose.koinInject
|
||||
@@ -37,12 +38,14 @@ fun main() = application {
|
||||
|
||||
startKoin<KoinApp>()
|
||||
|
||||
val config: ConfigProperties = koinInject()
|
||||
val settings: Settings = koinInject()
|
||||
|
||||
// val settings: Settings = PreferencesSettings(delegate)
|
||||
//
|
||||
// settings.put("kc_server", "kec.keinekekse.net")
|
||||
println(settings.get("kc_server", "default"))
|
||||
println("Properties: ${config["keycloakServer"]}")
|
||||
println("Settings: ${settings.get("kc_server", "default")}")
|
||||
// println(Preferences.userRoot())
|
||||
|
||||
// println("System properties:")
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
keycloakServer=kec.keinekekse.net
|
||||
keycloakRealm=app-server-realm
|
||||
keycloakClient=pkce-book-app
|
||||
@@ -24,6 +24,7 @@ kotlin {
|
||||
sourceSets {
|
||||
commonMain.dependencies {
|
||||
implementation(libs.bundles.kotlin.compose)
|
||||
implementation(libs.ktor.serializationJson)
|
||||
|
||||
}
|
||||
jvmMain.dependencies {
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
interface ConfigProperties {
|
||||
operator fun get(key: String): String?
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
@Serializable
|
||||
data class SettingsEntry(val key: String, val value: String)
|
||||
|
||||
interface Settings {
|
||||
fun get(key: String): String?
|
||||
fun get(key: String, default: String): String = get(key) ?: default
|
||||
@@ -24,4 +29,7 @@ interface Settings {
|
||||
|
||||
fun size(): Int
|
||||
fun keys(): Set<String>
|
||||
|
||||
fun export(): String
|
||||
fun import(data: String)
|
||||
}
|
||||
@@ -10,8 +10,6 @@ import androidx.compose.ui.draw.drawBehind
|
||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
// TODO (ProgressIndicator.() -> Unit) --> { animationSize = ....
|
||||
|
||||
@Composable
|
||||
fun ProgressIndicator(animationSize: Int = 48, paddingTop: Int = 16, strokeWidth: Int = 5) {
|
||||
val primaryColor = MaterialTheme.colorScheme.primary
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
import java.io.InputStream
|
||||
import java.util.*
|
||||
|
||||
class JvmConfigProperties(val configFileName: String = "config.properties") : ConfigProperties {
|
||||
|
||||
private var properties = Properties()
|
||||
|
||||
override operator fun get(key: String): String? = properties.getProperty(key)
|
||||
|
||||
init {
|
||||
loadConfigFile()
|
||||
}
|
||||
|
||||
private fun loadConfigFile() {
|
||||
getConfigStream().use { stream ->
|
||||
properties.load(stream)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getConfigStream(): InputStream {
|
||||
return javaClass.classLoader.getResourceAsStream(configFileName)
|
||||
?: throw IllegalStateException("Could not load configuration from $configFileName")
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.keinekekse.app.config
|
||||
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
class JvmSettings(clazz: Class<*>? = null) : Settings {
|
||||
@@ -52,4 +53,13 @@ class JvmSettings(clazz: Class<*>? = null) : Settings {
|
||||
override fun keys(): Set<String> {
|
||||
return preferences.keys().toSet()
|
||||
}
|
||||
|
||||
override fun export(): String {
|
||||
val prefList = keys().filter { get(it) != null }.map { SettingsEntry(it, get(it)!!) }
|
||||
return Json {}.encodeToString(prefList)
|
||||
}
|
||||
|
||||
override fun import(data: String) {
|
||||
Json { }.decodeFromString<List<SettingsEntry>>(data).forEach { put(it.key, it.value) }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user