Skip to content

Commit

Permalink
#1271 fix: ignore double press key maps overlapping short press key m…
Browse files Browse the repository at this point in the history
…aps if the constraints aren't satisfied
  • Loading branch information
sds100 committed Oct 1, 2024
1 parent 5b67bec commit b7dcace
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,7 @@ class ConstraintSnapshotImpl(
}
}

override fun isSatisfied(constraintState: ConstraintState): Boolean =
when (constraintState.mode) {
ConstraintMode.AND -> {
constraintState.constraints.all { isSatisfied(it) }
}

ConstraintMode.OR -> {
constraintState.constraints.any { isSatisfied(it) }
}
}

private fun isSatisfied(constraint: Constraint): Boolean {
override fun isSatisfied(constraint: Constraint): Boolean {
val isSatisfied = when (constraint) {
is Constraint.AppInForeground -> appInForeground == constraint.packageName
is Constraint.AppNotInForeground -> appInForeground != constraint.packageName
Expand Down Expand Up @@ -98,7 +87,6 @@ class ConstraintSnapshotImpl(
is Constraint.FlashlightOff -> !cameraAdapter.isFlashlightOn(constraint.lens)
is Constraint.FlashlightOn -> cameraAdapter.isFlashlightOn(constraint.lens)
is Constraint.WifiConnected -> {
Timber.d("Connected WiFi ssid = $connectedWifiSSID")
if (constraint.ssid == null) {
// connected to any network
connectedWifiSSID != null
Expand Down Expand Up @@ -139,5 +127,22 @@ class ConstraintSnapshotImpl(
}

interface ConstraintSnapshot {
fun isSatisfied(constraintState: ConstraintState): Boolean
fun isSatisfied(constraint: Constraint): Boolean
}

fun ConstraintSnapshot.isSatisfied(constraintState: ConstraintState): Boolean {
// Required in case OR is used with empty list of constraints.
if (constraintState.constraints.isEmpty()) {
return true
}

return when (constraintState.mode) {
ConstraintMode.AND -> {
constraintState.constraints.all { isSatisfied(it) }
}

ConstraintMode.OR -> {
constraintState.constraints.any { isSatisfied(it) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.github.sds100.keymapper.actions.Action
import io.github.sds100.keymapper.actions.PerformActionsUseCase
import io.github.sds100.keymapper.actions.RepeatMode
import io.github.sds100.keymapper.constraints.DetectConstraintsUseCase
import io.github.sds100.keymapper.constraints.isSatisfied
import io.github.sds100.keymapper.data.PreferenceDefaults
import io.github.sds100.keymapper.util.InputEventType
import kotlinx.coroutines.CoroutineScope
Expand Down
Loading

0 comments on commit b7dcace

Please sign in to comment.