Skip to content

Commit

Permalink
perf: some changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Mar 3, 2024
1 parent fb5933d commit 8c38829
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 37 deletions.
11 changes: 2 additions & 9 deletions app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/kotlin/li/songe/gkd/service/AbExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/kotlin/li/songe/gkd/service/GkdAbService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
26 changes: 18 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/AppConfigPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = "非法选择器",
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/AppItemPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/kotlin/li/songe/gkd/ui/GlobalRulePage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8c38829

Please sign in to comment.