Skip to content

Commit 94e7dd5

Browse files
committed
细节更新
1 parent f390f3e commit 94e7dd5

9 files changed

Lines changed: 744 additions & 367 deletions

File tree

.idea/dataSources.local.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 164 additions & 163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build.gradle.kts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ val bPlugins = mutableListOf(
4646
"org.intellij.groovy"
4747
)
4848

49-
println(ideType)
5049
if (ideType.toInt() >= 243) {
5150
bPlugins.add("com.intellij.modules.json")
5251
bPlugins.add("com.intellij.platform.images")
@@ -66,8 +65,8 @@ dependencies {
6665
local("/Users/ldd/Applications/IntelliJ IDEA Ultimate.app")
6766
}
6867
"252" -> {
69-
intellijIdeaCommunity("2025.2.1")
70-
// local("/Applications/Android Studio.app")
68+
// intellijIdeaCommunity("2025.2.1")
69+
local("/Applications/Android Studio.app")
7170
}
7271

7372
"251" -> {
@@ -81,6 +80,8 @@ dependencies {
8180
pluginVerifier()
8281
zipSigner()
8382
javaCompiler()
83+
bundledPlugin("com.intellij.java")
84+
8485

8586

8687

@@ -235,13 +236,6 @@ val generateFlutterPluginInfo by tasks.registering {
235236
group = "codegen"
236237
description = "Generates FlutterPluginInfo class with version info"
237238

238-
println(
239-
"""
240-
changelog : \n
241-
${currentVersionChangelog.get()}
242-
""".trimIndent()
243-
)
244-
245239
// 定义输出目录和文件路径
246240
val outputDir = file("src/main/kotlin/codegen")
247241
val outputFile = File(outputDir, "FlutterXPluginInfo.kt")

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

src/main/kotlin/shop/itbug/fluttercheckversionx/actions/DioWindowAnActionEx.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ fun AnActionEvent.api(): IRequest? {
1212
val dioApi = data as? IRequest?
1313
if (dioApi != null) return dioApi
1414
val dart = getData(ComposeHelper.networkRequestDataKey)
15+
1516
return dart as? IRequest?
1617
}

src/main/kotlin/shop/itbug/fluttercheckversionx/model/IRequest.kt

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,11 @@ fun IRequest.getHtmlPrefix(): String {
9797
fun getColorStyle(color: String) = "style='color:${color}'"
9898

9999
return """
100-
<span ${getColorStyle(color)}>${httpStatusCode}</span> <span ${getColorStyle(secColor)}>${httpMethod}</span> <span ${getColorStyle(secColor)}>${durationMs}ms</span>
100+
<span ${getColorStyle(color)}>${httpStatusCode}</span> <span ${getColorStyle(secColor)}>${httpMethod}</span> <span ${
101+
getColorStyle(
102+
secColor
103+
)
104+
}>${durationMs}ms</span>
101105
""".trimIndent()
102106
}
103107

@@ -196,7 +200,7 @@ class HurlGenerate(private val request: IRequest) {
196200

197201
private fun getPostBody(): String {
198202
return when (val body = request.httpRequestBody) {
199-
is String -> if(body.isNotBlank()) body else ""
203+
is String -> if (body.isNotBlank()) body else ""
200204
is Map<*, *> -> if (body.isNotEmpty()) GsonBuilder().setPrettyPrinting().create().toJson(body) else ""
201205
else -> body?.toString() ?: ""
202206
}
@@ -217,8 +221,6 @@ fun formatSize(sizeInBytes: Long): String {
217221
}
218222

219223

220-
221-
222224
/**
223225
* 将 IRequest 对象转换为与 Dart/Flutter DevTools "Copy as cURL" 功能风格完全一致的命令字符串。
224226
*
@@ -228,16 +230,34 @@ fun formatSize(sizeInBytes: Long): String {
228230
* - 精确的参数顺序 (`--request METHOD 'URL' ...`)。
229231
* - 自动过滤掉由 cURL 管理的冗余头信息 (Host, Content-Length, Accept-Encoding)。
230232
* - 格式化为易于阅读和粘贴的多行命令。
233+
* - 跨平台支持:自动适配 Windows (CMD/PowerShell) 和 Unix-like 系统的语法差异。
231234
*
232235
* @param gsonInstance 一个可选的 Gson 实例,用于序列化 JSON 请求体。如果为 null,将创建一个新的实例。
233236
* @return 格式化后的 cURL 命令字符串。
234237
*/
235238
fun IRequest.toCurlStringAsDartDevTools(gsonInstance: Gson? = null): String {
236-
// 创建一个列表来收集 cURL 命令的所有部分,方便最后用 `\` 连接
239+
// 检测操作系统
240+
val isWindows = System.getProperty("os.name").lowercase().contains("win")
241+
242+
// 根据操作系统选择引号和转义方式
243+
val quote = if (isWindows) "\"" else "'"
244+
val lineContinuation = if (isWindows) " `" else " \\"
245+
246+
// 转义函数:根据操作系统选择不同的转义策略
247+
fun escapeForShell(text: String): String {
248+
return if (isWindows) {
249+
// Windows: 转义双引号和反斜杠
250+
text.replace("\\", "\\\\").replace("\"", "\\\"")
251+
} else {
252+
// Unix: 转义单引号
253+
text.replace("'", "'\\''")
254+
}
255+
}
256+
257+
// 创建一个列表来收集 cURL 命令的所有部分
237258
val commandParts = mutableListOf<String>()
238259

239260
// 1. HTTP 方法 (--request)
240-
// Dart DevTools 总是显式包含方法
241261
httpMethod?.let {
242262
commandParts.add("--request ${it.uppercase()}")
243263
}
@@ -259,17 +279,15 @@ fun IRequest.toCurlStringAsDartDevTools(gsonInstance: Gson? = null): String {
259279
}
260280
}
261281
}
262-
// 对 URL 中的特殊字符(主要是单引号)进行转义
263-
commandParts.add("'${finalUrl.replace("'", "'\\''")}'")
282+
commandParts.add("$quote${escapeForShell(finalUrl)}$quote")
264283

265284
// 3. 添加请求头 (--header)
266-
// 过滤掉 cURL 会自动处理或通过标志管理的头
267285
val headersToFilter = setOf("host", "accept-encoding", "content-length")
268286
httpRequestHeaders
269287
.filterKeys { key -> !headersToFilter.contains(key.lowercase()) }
270288
.forEach { (key, value) ->
271-
val escapedValue = value.toString().replace("'", "'\\''")
272-
commandParts.add("--header '$key: $escapedValue'")
289+
val escapedValue = escapeForShell(value.toString())
290+
commandParts.add("--header $quote$key: $escapedValue$quote")
273291
}
274292

275293
// 4. 智能处理请求体 (--data-raw, --data)
@@ -284,28 +302,30 @@ fun IRequest.toCurlStringAsDartDevTools(gsonInstance: Gson? = null): String {
284302
is String -> body
285303
else -> (gsonInstance ?: Gson()).toJson(body)
286304
}
287-
val escapedBody = jsonBody.replace("'", "'\\''")
288-
"--data-raw '$escapedBody'"
305+
val escapedBody = escapeForShell(jsonBody)
306+
"--data-raw $quote$escapedBody$quote"
289307
}
308+
290309
contentType.contains("application/x-www-form-urlencoded") && body is Map<*, *> -> {
291310
val formData = body.map { (key, value) ->
292311
val encodedKey = URLEncoder.encode(key.toString(), "UTF-8")
293312
val encodedValue = URLEncoder.encode(value?.toString() ?: "", "UTF-8")
294313
"$encodedKey=$encodedValue"
295314
}.joinToString("&")
296-
"--data '$formData'"
315+
"--data $quote$formData$quote"
297316
}
317+
298318
else -> {
299-
val escapedBody = body.toString().replace("'", "'\\''")
300-
"--data '$escapedBody'"
319+
val escapedBody = escapeForShell(body.toString())
320+
"--data $quote$escapedBody$quote"
301321
}
302322
}
303323
commandParts.add(bodyPart)
304324
}
305325

306326
// 5. 组合所有部分
307-
// `curl --location --compressed` 是固定的前缀
308-
// 使用 `joinToString` 来优雅地处理 `\` 和换行,确保最后一行没有 `\`
309-
return "curl --location --compressed " + commandParts.joinToString(separator = " \\\n ")
327+
// 使用适合当前操作系统的续行符
328+
return "curl --location --compressed$lineContinuation\n " +
329+
commandParts.joinToString(separator = "$lineContinuation\n ")
310330
}
311331

0 commit comments

Comments
 (0)