mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
desktop: run the primary action on Enter in the passphrase screens
The unlock screen and the first-run passphrase setup required a mouse click on the button; Enter did nothing, which every password prompt gets wrong. Preview-key handling on the lock screen scaffold maps Enter (and numpad Enter) to the primary action — a no-op while a check is in progress or the field is empty, so an empty submit cannot spam the wrong-passphrase error.
This commit is contained in:
@@ -22,6 +22,11 @@ import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.input.key.Key
|
||||
import androidx.compose.ui.input.key.KeyEventType
|
||||
import androidx.compose.ui.input.key.key
|
||||
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
||||
import androidx.compose.ui.input.key.type
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
@@ -53,7 +58,10 @@ fun UnlockScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
LockScreenScaffold(subtitle = Strings.get("d_locked", language)) {
|
||||
LockScreenScaffold(
|
||||
subtitle = Strings.get("d_locked", language),
|
||||
onEnter = { submit() },
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = passphrase,
|
||||
onValueChange = { passphrase = it },
|
||||
@@ -114,7 +122,10 @@ fun PassphraseSetupScreen() {
|
||||
}
|
||||
}
|
||||
|
||||
LockScreenScaffold(subtitle = Strings.get("d_passphrase_desc", language)) {
|
||||
LockScreenScaffold(
|
||||
subtitle = Strings.get("d_passphrase_desc", language),
|
||||
onEnter = { submit() },
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = passphrase,
|
||||
onValueChange = { passphrase = it },
|
||||
@@ -158,9 +169,27 @@ fun PassphraseSetupScreen() {
|
||||
@Composable
|
||||
private fun LockScreenScaffold(
|
||||
subtitle: String,
|
||||
onEnter: (() -> Unit)?,
|
||||
content: @Composable ColumnScope.() -> Unit,
|
||||
) {
|
||||
Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
|
||||
Box(
|
||||
Modifier
|
||||
.fillMaxSize()
|
||||
.onPreviewKeyEvent { event ->
|
||||
// Enter (or numpad enter) runs the primary action, the way
|
||||
// every password prompt behaves.
|
||||
if (onEnter != null &&
|
||||
event.type == KeyEventType.KeyUp &&
|
||||
(event.key == Key.Enter || event.key == Key.NumPadEnter)
|
||||
) {
|
||||
onEnter()
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
},
|
||||
contentAlignment = Alignment.Center,
|
||||
) {
|
||||
Column(
|
||||
Modifier.widthIn(max = 480.dp).padding(24.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
|
||||
Reference in New Issue
Block a user