Skip to content

Commit 603476f

Browse files
committed
移除对ktor的依赖及相关实现,简化依赖管理和代码逻辑,同时通过fetch替代实现以解决wasm兼容性问题。
1 parent e69a95e commit 603476f

File tree

4 files changed

+10
-55
lines changed

4 files changed

+10
-55
lines changed

composeApp/build.gradle.kts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag
21
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpackConfig
32

43
plugins {
@@ -45,7 +44,6 @@ kotlin {
4544
}
4645

4746
sourceSets {
48-
4947
commonMain.dependencies {
5048
implementation(compose.runtime)
5149
implementation(compose.foundation)
@@ -64,11 +62,6 @@ kotlin {
6462
// implementation(libs.androidx.lifecycle)
6563
implementation(libs.kotlinpoet)
6664
implementation(libs.kotlin.coroutine)
67-
val ktor = "3.1.3"
68-
implementation("io.ktor:ktor-client-core:$ktor")
69-
implementation("io.ktor:ktor-client-content-negotiation:$ktor")
70-
implementation("io.ktor:ktor-serialization-kotlinx-json:$ktor")
71-
implementation("io.ktor:ktor-client-core:$ktor")
7265

7366
implementation(libs.kotlin.serialization.core)
7467
implementation(libs.kotlin.serialization.json)

composeApp/src/wasmJsMain/kotlin/love/forte/simbot/codegen/versions/Versions.kt

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
package love.forte.simbot.codegen.versions
22

3-
import io.ktor.client.*
4-
import io.ktor.client.engine.js.*
5-
import io.ktor.client.plugins.contentnegotiation.*
6-
import io.ktor.client.request.*
7-
import io.ktor.serialization.kotlinx.json.*
83
import kotlinx.browser.window
94
import kotlinx.coroutines.await
105
import kotlinx.serialization.ExperimentalSerializationApi
@@ -23,59 +18,18 @@ private val json = Json {
2318
allowTrailingComma = true
2419
}
2520

26-
val Client by lazy {
27-
createClient()
28-
}
29-
30-
fun createClient(): HttpClient {
31-
return HttpClient(JsClient()) {
32-
engine {
33-
this.pipelining = true
34-
}
35-
install(ContentNegotiation) {
36-
json(json)
37-
}
38-
}
39-
}
40-
41-
suspend fun queryLatest(owner: String, repo: String): GitHubRelease? {
42-
return createClient().use {
43-
// val resp = it.get("https://api.github.com/repos/$owner/$repo/releases/latest") {
44-
val resp = it.get("https://api.forte.love/me/description?code=1") {
45-
// headers {
46-
// this["X-GitHub-Api-Version"] = "2022-11-28"
47-
// }
48-
}
49-
50-
null
51-
}
52-
}
53-
5421
suspend fun fetchLatest(owner: String, repo: String): GitHubRelease {
5522
val req = Request(input = "https://api.github.com/repos/$owner/$repo/releases/latest".toJsString())
5623
req.headers.append("X-GitHub-Api-Version", "2022-11-28")
5724

5825
val fetchResponse = window.fetch(input = req)
5926
.await<Response>()
60-
println(fetchResponse)
27+
// println(fetchResponse)
6128
val fetchBody = fetchResponse.text().await<JsString>()
62-
println(fetchBody)
29+
// println(fetchBody)
6330
return json.decodeFromString(fetchBody.toString())
64-
65-
// return createClient().use {
66-
// it.get("https://api.github.com/repos/$owner/$repo/releases/latest") {
67-
// headers {
68-
// this["X-GitHub-Api-Version"] = "2022-11-28"
69-
// }
70-
// }.body<GitHubRelease>()
71-
// }
7231
}
7332

74-
private fun toJSON(o: JsAny): String =
75-
js("JSON.stringify(o)")
76-
77-
// private fun
78-
7933
@Serializable
8034
data class GitHubRelease(
8135
val id: String,

gradle/libs.versions.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ junit = "4.13.2"
55
kotlin = "2.2.20-Beta1"
66
kotlin-coroutine = "1.10.2"
77
kotlin-serialization = "1.9.0"
8+
#ktor = "3.1.3"
89

910
kotlinpoet = "1.19.0-KMP-SNAPSHOT"
1011

@@ -18,6 +19,12 @@ androidx-lifecycle-runtime-compose = { group = "org.jetbrains.androidx.lifecycle
1819
kotlinpoet = { group = "com.squareup", name = "kotlinpoet", version.ref = "kotlinpoet" }
1920
kotlin-coroutine = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlin-coroutine" }
2021

22+
# ktor
23+
# 直接用的fetch,因为之前用ktor的wasm有bug
24+
#ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
25+
#ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
26+
#ktor-serialization-kotlinx-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
27+
2128
# composes
2229
## ICON https://www.jetbrains.com/help/kotlin-multiplatform-dev/whats-new-compose-180.html#implicit-dependency-on-material-icons-core-removed
2330

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pluginManagement {
1010
}
1111

1212
dependencyResolutionManagement {
13+
@Suppress("UnstableApiUsage")
1314
repositories {
1415
google()
1516
mavenCentral()

0 commit comments

Comments
 (0)