fix: index=0 的 rule 的 preRules 不生效 不生效 (#213)

This commit is contained in:
lisonge 2023-10-28 13:58:59 +08:00
parent d93070ff7b
commit 2c1f0ccfbd
2 changed files with 15 additions and 15 deletions

View File

@ -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,
@ -46,6 +42,11 @@ data class Rule(
val app: SubscriptionRaw.AppRaw,
val subsItem: SubsItem,
) {
/**
* 任意一个元素是上次点击过的
*/
var preRules: Set<Rule> = emptySet()
var actionDelayTriggerTime = 0L
fun triggerDelay() {
// 触发延迟, 一段时间内此规则不可利用

View File

@ -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
@ -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,
@ -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)
}
}
}