fix(core): stealth mode indicator

This commit is contained in:
rhunk 2024-09-07 22:44:13 +02:00
parent ae2e4c16ae
commit ccc8000f4f

View File

@ -9,6 +9,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import me.rhunk.snapenhance.common.data.RuleState
import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent import me.rhunk.snapenhance.core.event.events.impl.BindViewEvent
import me.rhunk.snapenhance.core.features.Feature import me.rhunk.snapenhance.core.features.Feature
import me.rhunk.snapenhance.core.features.impl.spying.StealthMode import me.rhunk.snapenhance.core.features.impl.spying.StealthMode
@ -30,7 +31,7 @@ class StealthModeIndicator : Feature("StealthModeIndicator") {
private fun requestUpdate(conversationId: String) { private fun requestUpdate(conversationId: String) {
fetchJob?.cancel() fetchJob?.cancel()
fetchJob = context.coroutineScope.launch { fetchJob = context.coroutineScope.launch {
val isStealth = stealthMode.getState(conversationId) val isStealth = stealthMode.canUseRule(conversationId)
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
listener(isStealth) listener(isStealth)
} }
@ -58,7 +59,7 @@ class StealthModeIndicator : Feature("StealthModeIndicator") {
stealthMode.addStateListener { conversationId, state -> stealthMode.addStateListener { conversationId, state ->
runCatching { runCatching {
listeners[conversationId]?.invoke(state) listeners[conversationId]?.invoke(stealthMode.getRuleState()?.let { if (it == RuleState.BLACKLIST) !state else state } ?: state)
}.onFailure { }.onFailure {
context.log.error("Failed to update stealth mode indicator", it) context.log.error("Failed to update stealth mode indicator", it)
} }