Skip to content

Commit

Permalink
fix: index=0 的 rule 的 preRules 不生效 不生效 (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Oct 28, 2023
1 parent d93070f commit 2c1f0cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
9 changes: 5 additions & 4 deletions app/src/main/java/li/songe/gkd/data/Rule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ data class Rule(
*/
val matches: List<Selector> = emptyList(),
val excludeMatches: List<Selector> = emptyList(),
/**
* 任意一个元素是上次点击过的
*/
val preRules: Set<Rule> = emptySet(),
val actionCd: Long = defaultMiniCd,
val actionDelay: Long = 0,
val matchLauncher: Boolean = false,
Expand All @@ -46,6 +42,11 @@ data class Rule(
val app: SubscriptionRaw.AppRaw,
val subsItem: SubsItem,
) {
/**
* 任意一个元素是上次点击过的
*/
var preRules: Set<Rule> = emptySet()

var actionDelayTriggerTime = 0L
fun triggerDelay() {
// 触发延迟, 一段时间内此规则不可利用
Expand Down
21 changes: 10 additions & 11 deletions app/src/main/java/li/songe/gkd/util/SubsState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ val appIdToRulesFlow by lazy {
// 筛选合法选择器的规则组, 如果一个规则组内某个选择器语法错误, 则禁用/丢弃此规则组
groupRaw.valid
}.forEach { groupRaw ->
val ruleGroupList = mutableListOf<Rule>()
val groupRuleList = mutableListOf<Rule>()
groupRaw.rules.forEachIndexed { ruleIndex, ruleRaw ->
val activityIds =
(ruleRaw.activityIds ?: groupRaw.activityIds ?: appRaw.activityIds
Expand Down Expand Up @@ -106,7 +106,7 @@ val appIdToRulesFlow by lazy {
val actionDelay =
ruleRaw.actionDelay ?: groupRaw.actionDelay ?: appRaw.actionDelay ?: 0

ruleGroupList.add(
groupRuleList.add(
Rule(
matchLauncher = matchLauncher,
quickFind = quickFind,
Expand Down Expand Up @@ -135,16 +135,15 @@ val appIdToRulesFlow by lazy {
)
)
}
ruleGroupList.forEachIndexed { index, ruleConfig ->
ruleGroupList[index] = ruleConfig.copy(
preRules = ruleGroupList.filter {
(it.key != null) && ruleConfig.preKeys.contains(
it.key
)
}.toSet()
)
groupRuleList.forEach { ruleConfig ->
// 保留原始对象引用, 方便判断 lastTriggerRule 时直接使用 ===
ruleConfig.preRules = groupRuleList.filter { otherRule ->
(otherRule.key != null) && ruleConfig.preKeys.contains(
otherRule.key
)
}.toSet()
}
rules.addAll(ruleGroupList)
rules.addAll(groupRuleList)
}
}
}
Expand Down

0 comments on commit 2c1f0cc

Please sign in to comment.