From a307c833d08de37d8c43d190ffc09656673d2e8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=88=BA=E8=9E=88?= Date: Mon, 18 Nov 2024 00:34:08 +0800 Subject: [PATCH] perf: skipMatch --- app/src/main/kotlin/li/songe/gkd/service/A11yService.kt | 6 +++--- app/src/main/kotlin/li/songe/gkd/service/A11yState.kt | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt b/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt index 933b78365..0476ff60a 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/A11yService.kt @@ -234,7 +234,7 @@ private fun A11yService.useMatchRule() { } } val activityRule = getAndUpdateCurrentRules() - if (activityRule.currentRules.isEmpty() || !storeFlow.value.enableMatch) { + if (activityRule.skipMatch) { if (META.debuggable) { Log.d("queryEvents", "没有规则或者禁用匹配") } @@ -448,8 +448,8 @@ private fun A11yService.useMatchRule() { updateTopActivity(TopActivity(rightAppId)) } } - - if (getAndUpdateCurrentRules().currentRules.isEmpty() || !storeFlow.value.enableMatch || evAppId != rightAppId) { + val activityRule = getAndUpdateCurrentRules() + if (evAppId != rightAppId || activityRule.skipMatch) { // 放在 evAppId != rightAppId 的前面使得 TopActivity 能借助 lastTopActivity 恢复 return@launchEvent } diff --git a/app/src/main/kotlin/li/songe/gkd/service/A11yState.kt b/app/src/main/kotlin/li/songe/gkd/service/A11yState.kt index ffda14035..f9db99359 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/A11yState.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/A11yState.kt @@ -95,6 +95,10 @@ class ActivityRule( } else { currentRules } + val skipMatch: Boolean + get() { + return !currentRules.any { r -> r.status.ok } || !storeFlow.value.enableMatch + } } val activityRuleFlow by lazy { MutableStateFlow(ActivityRule()) }