Skip to content

Commit a7915a4

Browse files
committed
Release modifiers after shortcut letters
- Release active PC modifier toggles after a successful alphabet shortcut - Send modifier-up commands in stable reverse modifier order - Update ViewModel coverage for the temporary shortcut chord behavior Auto-generated
1 parent f5effdf commit a7915a4

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

app/src/main/java/com/enaboapps/switchify/screens/pc/PcMouseControlViewModel.kt

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,18 @@ class PcMouseControlViewModel(
183183
return
184184
}
185185
val keys = modifiers.map { it.toShortcutKey() } + letter
186-
sendNoAckCommand(PcControlCommand.KeyboardShortcut(keys)) {
187-
it.copy(
188-
isBusy = false,
189-
busyCommand = null,
190-
message = null
191-
)
186+
viewModelScope.launch {
187+
when (sendNoAckCommandNow(PcControlCommand.KeyboardShortcut(keys)) {
188+
it.copy(
189+
isBusy = false,
190+
busyCommand = null,
191+
message = null
192+
)
193+
}) {
194+
PcCommandResult.Ack -> releaseActiveModifiersIfPossible()
195+
is PcCommandResult.AuthFailed,
196+
is PcCommandResult.Failed -> Unit
197+
}
192198
}
193199
}
194200

@@ -492,7 +498,7 @@ class PcMouseControlViewModel(
492498
}
493499

494500
private fun releaseActiveModifiersIfPossible() {
495-
val modifiers = _uiState.value.activeModifiers.toList()
501+
val modifiers = orderedShortcutModifiers(_uiState.value.activeModifiers).asReversed()
496502
if (modifiers.isEmpty()) return
497503
_uiState.update { it.copy(activeModifiers = emptySet()) }
498504
val controller = serviceControllerProvider()

app/src/test/java/com/enaboapps/switchify/screens/pc/PcMouseControlViewModelTest.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,11 +1204,13 @@ class PcMouseControlViewModelTest {
12041204
PcKeyboardShortcutKey.Shift,
12051205
PcKeyboardShortcutKey.Z
12061206
)
1207-
)
1207+
),
1208+
PcControlCommand.ModifierUp(PcKeyboardModifierKey.Shift),
1209+
PcControlCommand.ModifierUp(PcKeyboardModifierKey.Ctrl)
12081210
),
12091211
connector.realtimeCommands
12101212
)
1211-
assertEquals(setOf(PcKeyboardModifierKey.Shift, PcKeyboardModifierKey.Ctrl), viewModel.uiState.value.activeModifiers)
1213+
assertEquals(emptySet<PcKeyboardModifierKey>(), viewModel.uiState.value.activeModifiers)
12121214
assertNull(viewModel.uiState.value.message)
12131215
}
12141216

0 commit comments

Comments
 (0)