mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 06:15:58 +00:00
Harden input migration and session lifecycle
Keep migration binding IDs stable, preserve unreadable libraries before recovery, and retain forward-version protection. Release keyboard owners on focus loss, handle unavailable settings displays, and allow controller confirmation or cancellation after physical key capture. Stop BLE routing and publication synchronously before asynchronous disconnect. Add regression coverage and record local and Thor validation.
This commit is contained in:
1 parent
7b7722bd25
commit
915f373d82
16 files changed
+414
-49
No files matched your search
@@ -1,14 +1,14 @@
|
||||
package com.droiddeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.focusable
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.window.DialogProperties
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.input.*
|
||||
|
||||
@@ -37,19 +37,43 @@ internal fun commandLabel(command: InputCommand) = stringResource(when (command)
|
||||
|
||||
@Composable
|
||||
internal fun InputCaptureDialog(onDismiss: () -> Unit, onPick: (PhysicalInputKey) -> Unit) {
|
||||
val focus = remember { FocusRequester() }
|
||||
val confirmFocus = remember { FocusRequester() }
|
||||
var captured by remember { mutableStateOf<PhysicalInputKey?>(null) }
|
||||
var capturedDevice by remember { mutableIntStateOf(-1) }
|
||||
var ready by remember { mutableStateOf(false) }
|
||||
AlertDialog(onDismissRequest = onDismiss, title = { Text(stringResource(R.string.input_capture)) },
|
||||
modifier = Modifier.onPreviewKeyEvent {
|
||||
val event = it.nativeKeyEvent
|
||||
val key = PhysicalInputKey.capture(event)
|
||||
if (key != null) {
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.repeatCount == 0) captured = key
|
||||
true
|
||||
} else false
|
||||
}.focusRequester(focus).focusable(),
|
||||
text = { Text(captured?.label ?: stringResource(R.string.input_capture_hint)) },
|
||||
confirmButton = { TextButton(enabled = captured != null, onClick = { captured?.let(onPick) }) { Text(stringResource(R.string.ctrl_edit)) } },
|
||||
dismissButton = { TextButton(onClick = onDismiss) { Text(stringResource(R.string.gesture_cancel)) } })
|
||||
LaunchedEffect(Unit) { focus.requestFocus() }
|
||||
properties = DialogProperties(dismissOnBackPress = ready),
|
||||
text = {
|
||||
CaptureShortcutKeys { event ->
|
||||
if (ready) {
|
||||
if (event.keyCode == android.view.KeyEvent.KEYCODE_BACK || event.keyCode == android.view.KeyEvent.KEYCODE_BUTTON_B) {
|
||||
if (event.action == android.view.KeyEvent.ACTION_DOWN && event.repeatCount == 0) onDismiss()
|
||||
true
|
||||
} else false
|
||||
} else {
|
||||
val key = PhysicalInputKey.capture(event)
|
||||
if (key == null) false else {
|
||||
if (captured == null && event.action == android.view.KeyEvent.ACTION_DOWN && event.repeatCount == 0) {
|
||||
captured = key
|
||||
capturedDevice = event.deviceId
|
||||
} else if (captured == key && capturedDevice == event.deviceId && event.action == android.view.KeyEvent.ACTION_UP) ready = true
|
||||
true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column {
|
||||
Text(captured?.label ?: stringResource(R.string.input_capture_hint))
|
||||
if (captured != null) Text(stringResource(R.string.input_capture_confirm))
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(enabled = ready, modifier = Modifier.focusRequester(confirmFocus)
|
||||
.controllerConfirm(ready) { captured?.let(onPick) }, onClick = { captured?.let(onPick) }) { Text(stringResource(R.string.ctrl_edit)) }
|
||||
LaunchedEffect(ready) { if (ready) confirmFocus.requestFocus() }
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(modifier = Modifier.controllerConfirm { onDismiss() }, onClick = onDismiss) { Text(stringResource(R.string.gesture_cancel)) }
|
||||
if (ready) TextButton(modifier = Modifier.controllerConfirm { captured = null; ready = false },
|
||||
onClick = { captured = null; ready = false }) { Text(stringResource(R.string.input_capture_retry)) }
|
||||
})
|
||||
}
|
||||
@@ -47,10 +47,19 @@ internal fun InputDisplayContent(host: ComponentActivity, display: Display, onDi
|
||||
override fun dismiss() { compose?.disposeComposition(); compose = null; super.dismiss() }
|
||||
}
|
||||
presentation.setOnCancelListener { dismiss() }
|
||||
presentation.show()
|
||||
fun showPresentation() {
|
||||
if (!display.isValid) { dismiss(); return }
|
||||
try {
|
||||
presentation.show()
|
||||
} catch (_: WindowManager.InvalidDisplayException) {
|
||||
presentation.dismiss()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
showPresentation()
|
||||
val observer = LifecycleEventObserver { _, event ->
|
||||
if (event == Lifecycle.Event.ON_STOP) presentation.hide()
|
||||
if (event == Lifecycle.Event.ON_START) presentation.show()
|
||||
if (event == Lifecycle.Event.ON_START) showPresentation()
|
||||
}
|
||||
host.lifecycle.addObserver(observer)
|
||||
onDispose { host.lifecycle.removeObserver(observer); presentation.dismiss() }
|
||||
|
||||
@@ -167,6 +167,7 @@ private fun InputSettingsContent(onBack: () -> Unit, onChanged: () -> Unit, embe
|
||||
}
|
||||
}
|
||||
if (InputLibraries.hasPendingScreenKeyMigration(context)) InputHint(stringResource(R.string.input_import_failed))
|
||||
if (InputLibraries.hasLibraryRecovery(context)) InputHint(stringResource(R.string.input_library_recovered))
|
||||
if (library.profiles.any { it.id.startsWith("migrated.screenkeys.") }) Text(stringResource(R.string.input_imported_keys_hint),
|
||||
Modifier.padding(16.dp), style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
SettingsGroup(stringResource(R.string.input_profiles)) {
|
||||
|
||||
@@ -189,7 +189,7 @@ internal fun PhysicalShortcutsDialog(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CaptureShortcutKeys(onKey: (KeyEvent) -> Boolean) {
|
||||
internal fun CaptureShortcutKeys(onKey: (KeyEvent) -> Boolean) {
|
||||
val currentOnKey by rememberUpdatedState(onKey)
|
||||
val window = (LocalView.current.parent as DialogWindowProvider).window
|
||||
DisposableEffect(window) {
|
||||
|
||||
Reference in new issue
Block a user