From 8c38829b16411dc1e4e5f9062b146a95bc6ad987 Mon Sep 17 00:00:00 2001 From: lisonge Date: Sun, 3 Mar 2024 18:28:47 +0800 Subject: [PATCH] perf: some changes --- .../li/songe/gkd/data/RawSubscription.kt | 11 ++------ .../main/kotlin/li/songe/gkd/service/AbExt.kt | 12 +++++++++ .../li/songe/gkd/service/GkdAbService.kt | 6 ++--- .../kotlin/li/songe/gkd/ui/AppConfigPage.kt | 26 +++++++++++++------ .../kotlin/li/songe/gkd/ui/AppItemPage.kt | 10 ++----- .../kotlin/li/songe/gkd/ui/GlobalRulePage.kt | 10 ++----- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt b/app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt index d803da3..40429b5 100644 --- a/app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt +++ b/app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt @@ -15,7 +15,7 @@ import kotlinx.serialization.json.jsonArray import kotlinx.serialization.json.jsonObject import kotlinx.serialization.json.jsonPrimitive import kotlinx.serialization.json.long -import li.songe.gkd.service.allowPropertyNames +import li.songe.gkd.service.checkSelector import li.songe.gkd.util.json import li.songe.gkd.util.json5ToJson import li.songe.gkd.util.toast @@ -386,14 +386,7 @@ data class RawSubscription( } } allSelector.forEach { s -> - s?.nameToTypeList?.forEach { (name, type) -> - if (!allowPropertyNames.contains(name)) { - return "非法属性名:${name}" - } - if (type != "null" && allowPropertyNames[name] != type) { - return "非法类型:${name}=$type" - } - } + s?.checkSelector()?.let { return it } } rules.forEach { r -> if (r.position?.isValid == false) { diff --git a/app/src/main/kotlin/li/songe/gkd/service/AbExt.kt b/app/src/main/kotlin/li/songe/gkd/service/AbExt.kt index d70e014..3ea5257 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/AbExt.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/AbExt.kt @@ -161,6 +161,18 @@ val allowPropertyNames by lazy { ) } +fun Selector.checkSelector(): String? { + nameToTypeList.forEach { (name, type) -> + if (!allowPropertyNames.contains(name)) { + return "未知属性:${name}" + } + if (type != "null" && allowPropertyNames[name] != type) { + return "非法类型:${name}=$type" + } + } + return null +} + private val getAttr: (AccessibilityNodeInfo, String) -> Any? = { node, name -> when (name) { "id" -> node.viewIdResourceName diff --git a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt index bdc171b..538a9f2 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt @@ -502,10 +502,8 @@ class GkdAbService : CompositionAbService({ fun execAction(gkdAction: GkdAction): ActionResult { val serviceVal = service ?: throw RpcError("无障碍没有运行") val selector = Selector.parseOrNull(gkdAction.selector) ?: throw RpcError("非法选择器") - selector.propertyNames.forEach { n -> - if (!allowPropertyNames.contains(n)) { - throw RpcError("未知属性名:$n") - } + selector.checkSelector()?.let { + throw RpcError(it) } val targetNode = serviceVal.safeActiveWindow?.querySelector( diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt index 52b0247..a8f61c7 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt @@ -18,6 +18,7 @@ import androidx.compose.material.icons.filled.Edit import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.LocalContentColor import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Switch @@ -200,14 +201,23 @@ private fun AppGroupCard( modifier = Modifier.fillMaxWidth() ) if (group.valid) { - Text( - text = group.desc ?: "", - maxLines = 1, - softWrap = false, - overflow = TextOverflow.Ellipsis, - modifier = Modifier.fillMaxWidth(), - fontSize = 14.sp - ) + if (!group.desc.isNullOrBlank()) { + Text( + text = group.desc!!, + maxLines = 1, + softWrap = false, + overflow = TextOverflow.Ellipsis, + modifier = Modifier.fillMaxWidth(), + fontSize = 14.sp + ) + } else { + Text( + text = "暂无描述", + modifier = Modifier.fillMaxWidth(), + fontSize = 14.sp, + color = LocalContentColor.current.copy(alpha = 0.5f) + ) + } } else { Text( text = "非法选择器", diff --git a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt index 88a4272..9a878ea 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt @@ -185,7 +185,7 @@ fun AppItemPage( modifier = Modifier.fillMaxWidth() ) if (group.valid) { - if (group.desc != null) { + if (!group.desc.isNullOrBlank()) { Text( text = group.desc, maxLines = 1, @@ -265,13 +265,7 @@ fun AppItemPage( Text(text = showGroupItemVal.name) }, text = { - Column { - if (showGroupItemVal.enable == false) { - Text(text = "该规则组默认不启用") - Spacer(modifier = Modifier.height(10.dp)) - } - Text(text = showGroupItemVal.desc ?: "") - } + Text(text = showGroupItemVal.desc ?: "") }, confirmButton = { Row { diff --git a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt index 1f3a866..f5e7512 100644 --- a/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt +++ b/app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt @@ -152,7 +152,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { modifier = Modifier.fillMaxWidth() ) if (group.valid) { - if (group.desc != null) { + if (!group.desc.isNullOrBlank()) { Text( text = group.desc, maxLines = 1, @@ -402,13 +402,7 @@ fun GlobalRulePage(subsItemId: Long, focusGroupKey: Int? = null) { Text(text = showGroupItem.name) }, text = { - Column { - if (showGroupItem.enable == false) { - Text(text = "该规则组默认不启用") - Spacer(modifier = Modifier.height(10.dp)) - } - Text(text = showGroupItem.desc ?: "") - } + Text(text = showGroupItem.desc ?: "") }, confirmButton = { Row {