Skip to content

Commit c25f2c1

Browse files
committed
feat: excludeAllMatches
1 parent ebb5a51 commit c25f2c1

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

app/src/main/kotlin/li/songe/gkd/data/RawSubscription.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,13 @@ data class RawSubscription(
220220
val action: String?
221221
val position: Position?
222222
val matches: List<String>?
223-
val excludeMatches: List<String>?
224223
val anyMatches: List<String>?
224+
val excludeMatches: List<String>?
225+
val excludeAllMatches: List<String>?
226+
227+
fun getAllSelectorStrings(): List<String> {
228+
return listOfNotNull(matches, excludeMatches, anyMatches, excludeAllMatches).flatten()
229+
}
225230
}
226231

227232
sealed interface RawGroupProps : RawCommonProps {
@@ -376,6 +381,7 @@ data class RawSubscription(
376381
override val position: Position?,
377382
override val matches: List<String>?,
378383
override val excludeMatches: List<String>?,
384+
override val excludeAllMatches: List<String>?,
379385
override val anyMatches: List<String>?,
380386
override val matchAnyApp: Boolean?,
381387
override val matchSystemApp: Boolean?,
@@ -435,6 +441,7 @@ data class RawSubscription(
435441
override val position: Position?,
436442
override val matches: List<String>?,
437443
override val excludeMatches: List<String>?,
444+
override val excludeAllMatches: List<String>?,
438445
override val anyMatches: List<String>?,
439446

440447
override val actionCdKey: Int?,
@@ -468,7 +475,7 @@ data class RawSubscription(
468475

469476
private fun RawGroupProps.getErrorDesc(): String? {
470477
val allSelectorStrings = rules.map { r ->
471-
listOfNotNull(r.matches, r.excludeMatches, r.anyMatches).flatten()
478+
r.getAllSelectorStrings()
472479
}.flatten()
473480
allSelectorStrings.forEach { source ->
474481
try {
@@ -650,6 +657,7 @@ data class RawSubscription(
650657
excludeActivityIds = getStringIArray(jsonObject, "excludeActivityIds"),
651658
matches = getStringIArray(jsonObject, "matches"),
652659
excludeMatches = getStringIArray(jsonObject, "excludeMatches"),
660+
excludeAllMatches = getStringIArray(jsonObject, "excludeAllMatches"),
653661
anyMatches = getStringIArray(jsonObject, "anyMatches"),
654662
key = getInt(jsonObject, "key"),
655663
name = getString(jsonObject, "name"),
@@ -788,6 +796,7 @@ data class RawSubscription(
788796
action = getString(jsonObject, "action"),
789797
preKeys = getIntIArray(jsonObject, "preKeys"),
790798
excludeMatches = getStringIArray(jsonObject, "excludeMatches"),
799+
excludeAllMatches = getStringIArray(jsonObject, "excludeAllMatches"),
791800
matches = getStringIArray(jsonObject, "matches"),
792801
anyMatches = getStringIArray(jsonObject, "anyMatches"),
793802
order = getInt(jsonObject, "order"),

app/src/main/kotlin/li/songe/gkd/data/ResolvedRule.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ sealed class ResolvedRule(
1515
private val group = g.group
1616
val subsItem = g.subsItem
1717
val rawSubs = g.subscription
18-
val config = g.config
1918
val key = rule.key
2019
val index = group.rules.indexOfFirst { r -> r === rule }
2120
val excludeData = g.excludeData
2221
private val preKeys = (rule.preKeys ?: emptyList()).toSet()
2322
val matches =
2423
(rule.matches ?: emptyList()).map { s -> group.cacheMap[s] ?: Selector.parse(s) }
25-
val excludeMatches =
26-
(rule.excludeMatches ?: emptyList()).map { s -> group.cacheMap[s] ?: Selector.parse(s) }
2724
val anyMatches =
2825
(rule.anyMatches ?: emptyList()).map { s -> group.cacheMap[s] ?: Selector.parse(s) }
26+
val excludeMatches =
27+
(rule.excludeMatches ?: emptyList()).map { s -> group.cacheMap[s] ?: Selector.parse(s) }
28+
val excludeAllMatches =
29+
(rule.excludeAllMatches ?: emptyList()).map { s -> group.cacheMap[s] ?: Selector.parse(s) }
2930

3031
private val resetMatch = rule.resetMatch ?: group.resetMatch
3132
val matchDelay = rule.matchDelay ?: group.matchDelay ?: 0L
@@ -53,7 +54,7 @@ sealed class ResolvedRule(
5354
} ?: group.actionMaximum
5455

5556
private val hasSlowSelector by lazy {
56-
(matches + excludeMatches + anyMatches).any { s -> s.isSlow(matchOption) }
57+
(matches + excludeMatches + anyMatches + excludeAllMatches).any { s -> s.isSlow(matchOption) }
5758
}
5859
val priorityTime = rule.priorityTime ?: group.priorityTime ?: 0
5960
val priorityActionMaximum = rule.priorityActionMaximum ?: group.priorityActionMaximum ?: 1

app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,18 @@ class A11yContext(
552552
rule.matchOption,
553553
)?.let { return null }
554554
}
555+
if (rule.excludeAllMatches.isNotEmpty()) {
556+
val allExclude = rule.excludeAllMatches.all {
557+
a11yContext.querySelfOrSelector(
558+
queryNode,
559+
it,
560+
rule.matchOption,
561+
) == null
562+
}
563+
if (!allExclude) {
564+
return null
565+
}
566+
}
555567
return resultNode
556568
} finally {
557569
currentRule = null

0 commit comments

Comments
 (0)