Parcourir la source

code improvenemts & libs

Milan Jurkulak il y a 1 an
Parent
commit
d585f11224

+ 13 - 1
composeApp/composeApp.gradle.kts

@@ -153,7 +153,7 @@ kotlin {
                 // qr code
                 implementation(libs.qrose)
                 // json
-                implementation(libs.kotlinx.serialization.json)
+                implementation("com.google.code.gson:gson:2.10.1")
                 // desktop file linux
                 implementation(libs.ini4j)
                 // files
@@ -198,6 +198,18 @@ kotlin {
                 implementation(libs.okhttp3.urlconnection)
                 implementation(libs.okhttp3.dnsoverhttps)
                 implementation(libs.okhttp3.tls)
+                implementation("dev.kotbase:couchbase-lite:3.1.9-1.1.1")
+                implementation("io.ktor:ktor-server-core:3.2.1")
+                implementation("io.ktor:ktor-server-netty:3.2.1")
+                implementation("io.ktor:ktor-server-default-headers:3.2.1")
+                implementation("io.ktor:ktor-server-call-logging:3.2.1")
+                implementation("io.ktor:ktor-server-content-negotiation:3.2.1")
+                implementation("io.ktor:ktor-serialization-gson:3.2.1")
+                implementation("io.ktor:ktor-server-status-pages:3.2.1")
+                implementation("io.ktor:ktor-server-cors:3.2.1")
+                implementation("io.ktor:ktor-server-auth:3.2.1")
+                implementation("io.ktor:ktor-server-compression:3.2.1")
+                implementation("ch.qos.logback:logback-classic:1.3.11")
 //                implementation("com.squareup.okhttp3:okhttp-ws:4.12.0")
                 // notification
                 // implementation("io.github.shadmanadman:knotif:0.56.0")

+ 5 - 18
composeApp/src/commonMain/kotlin/org/mjdev/desktop/extensions/CustomExt.kt

@@ -8,12 +8,12 @@ import kotlinx.coroutines.launch
 import kotlinx.datetime.Instant
 import kotlinx.datetime.toLocalDateTime
 import kotlinx.datetime.TimeZone.Companion.currentSystemDefault
-import kotlinx.serialization.ExperimentalSerializationApi
-import kotlinx.serialization.json.Json
 import org.mjdev.desktop.extensions.System.currentTime
 import org.mjdev.desktop.log.Log
 import kotlin.coroutines.suspendCoroutine
 import kotlin.time.ExperimentalTime
+import org.mjdev.desktop.helpers.generic.JsonHelper.toJson
+import org.mjdev.desktop.helpers.generic.JsonHelper.fromJson
 
 @OptIn(ExperimentalTime::class)
 @Suppress("unused")
@@ -126,19 +126,19 @@ object CustomExt {
     }
 
     inline fun <reified T> String.jsonToList(): List<T> = runCatching {
-        jsonSerializer.decodeFromString<List<T>>(this)
+        fromJson<List<T>>(this)
     }.onFailure { err ->
         Log.e(err)
     }.getOrNull() ?: emptyList()
 
     inline fun <reified T> String.to(): T? = runCatching {
-        jsonSerializer.decodeFromString<T>(this)
+        fromJson<T>(this)
     }.onFailure { err ->
         Log.e(err)
     }.getOrNull()
 
     inline fun <reified T> T.asJson(): String = runCatching {
-        jsonSerializer.encodeToString(this)
+        toJson()
     }.onFailure { err ->
         Log.e(err)
     }.getOrDefault("")
@@ -179,17 +179,4 @@ object CustomExt {
 //        }
 //    }
 
-    @OptIn(ExperimentalSerializationApi::class)
-    val jsonSerializer: Json = Json {
-        allowStructuredMapKeys = true
-        coerceInputValues = true
-        useArrayPolymorphism = true
-        allowSpecialFloatingPointValues = true
-        ignoreUnknownKeys = true
-        isLenient = true
-        allowComments = true
-        allowTrailingComma = true
-        prettyPrint = true
-    }
-
 }

+ 23 - 0
composeApp/src/commonMain/kotlin/org/mjdev/desktop/helpers/generic/JsonHelper.kt

@@ -0,0 +1,23 @@
+package org.mjdev.desktop.helpers.generic
+
+import com.google.gson.Gson
+import com.google.gson.GsonBuilder
+
+object JsonHelper {
+    val gson: Gson by lazy {
+        GsonBuilder()
+            .setPrettyPrinting()
+            .setLenient()
+            .serializeNulls()
+            .serializeSpecialFloatingPointValues()
+            .create()
+    }
+
+    fun <T> T.toJson(): String =
+        gson.toJson(this)
+
+    inline fun <reified T> fromJson(
+        json: String
+    ): T = gson.fromJson(json, T::class.java)
+
+}

+ 1 - 1
gradle/wrapper/gradle-wrapper.properties

@@ -1,7 +1,7 @@
 #Mon Jun 09 18:31:21 CEST 2025
 distributionBase=GRADLE_USER_HOME
 distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.2-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
 networkTimeout=10000
 validateDistributionUrl=true
 zipStoreBase=GRADLE_USER_HOME