Replace wireless ADB modal with setup page

This commit is contained in:
xXJsonDeruloXx committed 2026-09-25 16:19:01 -04:00
1 parent f379a1f30a
commit 09f8eb8ee3
3 files changed
+248 -137

No files matched your search

@@ -426,14 +426,16 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
// the pad then had nothing to move from (a press landed back on the rail's first item). So
// once the new page is in, a controller lands on its main button.
val inputModeManager = LocalInputModeManager.current
LaunchedEffect(selected, s.pageKey) {
LaunchedEffect(selected, s.pageKey, showWirelessAdbFix) {
if (showWirelessAdbFix) return@LaunchedEffect
kotlinx.coroutines.delay(450)
if (!anyFocused && inputModeManager.inputMode == InputMode.Keyboard) runCatching {
if (frontFocus.primaryAttached > 0) frontFocus.primary.requestFocus()
else frontFocus.menuToggle.requestFocus()
}
}
LaunchedEffect(navOpen, railSelection) {
LaunchedEffect(navOpen, railSelection, showWirelessAdbFix) {
if (showWirelessAdbFix) return@LaunchedEffect
if (navOpen) {
frontFocus.focusedRail = null
repeat(12) {
@@ -535,15 +537,17 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
)
}
if (showWirelessAdbFix) {
WirelessAdbFixDialog(
onDismiss = { showWirelessAdbFix = false },
desiredEnabled = wirelessAdbDesiredEnabled,
onOpenDeveloperOptions = requestDeveloperOptions,
onCopyCommand = a.onCopyPhantomCommand,
onPair = a.onWirelessAdbPair,
onFindConnectPort = a.onFindWirelessAdbPort,
onApply = a.onWirelessAdbApply,
)
Box(Modifier.fillMaxSize().background(colors.background)) {
WirelessAdbFixPage(
onBack = { showWirelessAdbFix = false },
desiredEnabled = wirelessAdbDesiredEnabled,
onOpenDeveloperOptions = requestDeveloperOptions,
onCopyCommand = a.onCopyPhantomCommand,
onPair = a.onWirelessAdbPair,
onFindConnectPort = a.onFindWirelessAdbPort,
onApply = a.onWirelessAdbApply,
)
}
}
if (showDeveloperDisplayChoice) {
androidx.compose.material3.AlertDialog(
@@ -1263,7 +1267,7 @@ private fun Chip(t: String, ok: Boolean) {
private fun rememberHot(src: MutableInteractionSource): Boolean = src.collectIsFocusedAsState().value || src.collectIsHoveredAsState().value
@Composable
private fun PrimaryButton(text: String, enabled: Boolean = true, main: Boolean = false, onClick: () -> Unit) {
internal fun PrimaryButton(text: String, enabled: Boolean = true, main: Boolean = false, onClick: () -> Unit) {
val colors = MaterialTheme.colorScheme
val pal = LocalPalette.current
// The page's main button is where the pane is entered from the rail.
@@ -1,125 +0,0 @@
package com.droiddeck.launcher.ui
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.ui.unit.dp
@Composable
fun WirelessAdbFixDialog(
onDismiss: () -> Unit,
desiredEnabled: Boolean,
onOpenDeveloperOptions: () -> Unit,
onCopyCommand: () -> Unit,
onPair: (String, Int, String, (String?) -> Unit) -> Unit,
onFindConnectPort: (String, (Int?) -> Unit) -> Unit,
onApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
) {
var step by rememberSaveable { mutableStateOf(0) }
var host by rememberSaveable { mutableStateOf("") }
var pairingPort by rememberSaveable { mutableStateOf("") }
var pairingCode by rememberSaveable { mutableStateOf("") }
var connectPort by rememberSaveable { mutableStateOf("") }
var busy by remember { mutableStateOf(false) }
var message by remember { mutableStateOf<String?>(null) }
AlertDialog(
onDismissRequest = { if (!busy) onDismiss() },
title = { Text("Fix over Wi-Fi") },
text = {
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
when (step) {
0 -> {
Text("Enable Developer options and Wireless debugging on this device, and connect to Wi-Fi. Keep DroidDeck visible beside the pairing-code screen, such as in split screen. Android may close the code if you leave that screen.")
Text(
if (desiredEnabled) "This will restore Android’s child-process limit." else "This will disable Android’s child-process limit for Steam.",
style = MaterialTheme.typography.bodySmall,
)
Text("Enter the IP address and pairing port shown with the code.", style = MaterialTheme.typography.bodySmall)
OutlinedTextField(host, { host = it.trim() }, label = { Text("Device IP address") }, singleLine = true, modifier = Modifier.fillMaxWidth())
OutlinedTextField(pairingPort, { pairingPort = it.filter(Char::isDigit).take(5) }, label = { Text("Pairing port") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
OutlinedTextField(pairingCode, { pairingCode = it.filter(Char::isDigit).take(6) }, label = { Text("Pairing code") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
}
1 -> {
Text("Paired. If automatic discovery did not work, enter the current Wireless debugging port shown in Settings. It differs from the pairing port.")
OutlinedTextField(host, { host = it.trim() }, label = { Text("Device IP address") }, singleLine = true, modifier = Modifier.fillMaxWidth())
OutlinedTextField(connectPort, { connectPort = it.filter(Char::isDigit).take(5) }, label = { Text("Wireless debugging port") }, singleLine = true, keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number), modifier = Modifier.fillMaxWidth())
}
else -> Text(message ?: "Android confirmed the child-process limit is ${if (desiredEnabled) "enabled" else "disabled"}.")
}
message?.let { Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, style = MaterialTheme.typography.bodySmall) }
if (busy) Row(horizontalArrangement = Arrangement.spacedBy(10.dp)) {
CircularProgressIndicator()
Text(if (step == 0) "Pairing…" else "Applying and checking…")
}
}
},
confirmButton = {
when (step) {
0 -> TextButton(enabled = !busy && host.isNotBlank() && validPort(pairingPort) && pairingCode.length >= 6, onClick = {
busy = true
message = null
onPair(host, pairingPort.toInt(), pairingCode) { error ->
busy = false
pairingCode = ""
if (error == null) { step = 1; message = null } else message = error
if (error == null) {
busy = true
message = "Paired. Finding this device’s Wireless debugging port…"
onFindConnectPort(host) { discoveredPort ->
if (discoveredPort == null) {
busy = false
message = "Automatic discovery did not find the device. Enter the current Wireless debugging port below."
} else {
connectPort = discoveredPort.toString()
message = "Device found. Applying the setting…"
onApply(host, discoveredPort, desiredEnabled) { applyError ->
busy = false
if (applyError == null) { step = 2; message = null }
else message = "Could not apply automatically. Check the port below and retry. $applyError"
}
}
}
}
}
}) { Text("Pair") }
1 -> TextButton(enabled = !busy && validPort(connectPort), onClick = {
busy = true
message = null
onApply(host, connectPort.toInt(), desiredEnabled) { error ->
busy = false
if (error == null) { step = 2; message = null } else message = error
}
}) { Text(if (desiredEnabled) "Enable child-process limit" else "Disable child-process limit") }
else -> TextButton(onClick = onDismiss) { Text("Done") }
}
},
dismissButton = {
Column(horizontalAlignment = androidx.compose.ui.Alignment.End) {
if (step < 2) Row {
TextButton(enabled = !busy, onClick = onOpenDeveloperOptions) { Text("Developer options") }
TextButton(enabled = !busy, onClick = onCopyCommand) { Text("Copy ADB") }
}
TextButton(enabled = !busy, onClick = onDismiss) { Text(if (step == 2) "Close" else "Cancel") }
}
},
)
}
private fun validPort(value: String): Boolean = value.toIntOrNull()?.let { it in 1..65535 } == true
@@ -0,0 +1,232 @@
package com.droiddeck.launcher.ui
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusDirection
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
@Composable
fun WirelessAdbFixPage(
onBack: () -> Unit,
desiredEnabled: Boolean,
onOpenDeveloperOptions: () -> Unit,
onCopyCommand: () -> Unit,
onPair: (String, Int, String, (String?) -> Unit) -> Unit,
onFindConnectPort: (String, (Int?) -> Unit) -> Unit,
onApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
) {
var step by rememberSaveable { mutableStateOf(0) }
var host by rememberSaveable { mutableStateOf("") }
var pairingPort by rememberSaveable { mutableStateOf("") }
var pairingCode by rememberSaveable { mutableStateOf("") }
var connectPort by rememberSaveable { mutableStateOf("") }
var busy by remember { mutableStateOf(false) }
var message by remember { mutableStateOf<String?>(null) }
val focusManager = LocalFocusManager.current
BackHandler { if (!busy) onBack() }
SettingsPage(
host = rememberMenuHost(),
title = if (step == 2) "Wireless ADB ready" else "Connect over Wi-Fi",
eyebrow = "Setup",
lede = "Pair Android Wireless debugging so DroidDeck can ${if (desiredEnabled) "restore" else "disable"} the child-process limit for Steam.",
onBack = { if (!busy) onBack() },
) {
Box(Modifier.fillMaxWidth(), contentAlignment = Alignment.TopStart) {
Column(
modifier = Modifier
.widthIn(max = 720.dp)
.fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
when (step) {
0 -> {
SettingsGroup("Pairing details") {
Column(
modifier = Modifier.fillMaxWidth().padding(14.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
Text("In Settings, open Developer options → Wireless debugging → Pair device with pairing code. Keep the code screen open while you enter these details.", color = MaterialTheme.colorScheme.onSurfaceVariant)
OutlinedTextField(
value = host,
onValueChange = { host = it.trim() },
label = { Text("Device IP address") },
placeholder = { Text("For example, 192.168.1.25") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }),
modifier = Modifier.fillMaxWidth(),
)
OutlinedTextField(
value = pairingPort,
onValueChange = { pairingPort = it.filter(Char::isDigit).take(5) },
label = { Text("Pairing port") },
placeholder = { Text("Shown with the pairing code") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }),
modifier = Modifier.fillMaxWidth(),
)
OutlinedTextField(
value = pairingCode,
onValueChange = { pairingCode = it.filter(Char::isDigit).take(6) },
label = { Text("6-digit pairing code") },
placeholder = { Text("Shown in the pairing dialog") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
modifier = Modifier.fillMaxWidth(),
)
}
}
SettingsGroup("What will change") {
Text(
if (desiredEnabled) "DroidDeck will restore Android’s child-process limit for Steam."
else "DroidDeck will disable Android’s child-process limit for Steam.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(14.dp),
)
}
}
1 -> {
SettingsGroup("Wireless debugging connection") {
Column(
modifier = Modifier.fillMaxWidth().padding(14.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
Text("Pairing is complete. Automatic discovery did not find the connection port, so enter the current Wireless debugging port from Settings. It is different from the pairing port.", color = MaterialTheme.colorScheme.onSurfaceVariant)
OutlinedTextField(
value = host,
onValueChange = { host = it.trim() },
label = { Text("Device IP address") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Ascii, imeAction = ImeAction.Next),
keyboardActions = KeyboardActions(onNext = { focusManager.moveFocus(FocusDirection.Next) }),
modifier = Modifier.fillMaxWidth(),
)
OutlinedTextField(
value = connectPort,
onValueChange = { connectPort = it.filter(Char::isDigit).take(5) },
label = { Text("Wireless debugging port") },
placeholder = { Text("Current port shown in Settings") },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number, imeAction = ImeAction.Done),
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
modifier = Modifier.fillMaxWidth(),
)
}
}
}
else -> {
SettingsGroup("Child-process limit") {
Text(
"Android confirmed the limit is ${if (desiredEnabled) "enabled" else "disabled"}.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(14.dp),
)
}
}
}
if (busy) {
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(10.dp)) {
CircularProgressIndicator()
Text(message ?: if (step == 0) "Pairing…" else "Applying and checking…")
}
} else {
message?.let { Text(it, color = MaterialTheme.colorScheme.error) }
}
if (step < 2) {
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
SecondaryButton("Developer options", enabled = !busy, onClick = onOpenDeveloperOptions)
if (!desiredEnabled) SecondaryButton("Copy ADB", enabled = !busy, onClick = onCopyCommand)
}
}
when (step) {
0 -> PrimaryButton(
"Pair",
enabled = !busy && host.isNotBlank() && validPort(pairingPort) && pairingCode.length == 6,
onClick = {
busy = true
message = null
onPair(host, pairingPort.toInt(), pairingCode) { error ->
busy = false
pairingCode = ""
if (error == null) {
step = 1
busy = true
message = "Paired. Finding the Wireless debugging port…"
onFindConnectPort(host) { discoveredPort ->
if (discoveredPort == null) {
busy = false
message = "Automatic discovery did not find the port. Enter the current port from Settings."
} else {
connectPort = discoveredPort.toString()
message = "Device found. Applying the setting…"
onApply(host, discoveredPort, desiredEnabled) { applyError ->
busy = false
if (applyError == null) {
step = 2
message = null
} else {
message = "Could not apply automatically. Check the port below and retry. $applyError"
}
}
}
}
} else {
message = error
}
}
},
)
1 -> PrimaryButton(
if (desiredEnabled) "Enable child-process limit" else "Disable child-process limit",
enabled = !busy && validPort(connectPort),
onClick = {
busy = true
message = null
onApply(host, connectPort.toInt(), desiredEnabled) { error ->
busy = false
if (error == null) {
step = 2
message = null
} else {
message = error
}
}
},
)
else -> PrimaryButton("Done", enabled = !busy, onClick = onBack)
}
}
}
}
}
private fun validPort(value: String): Boolean = value.toIntOrNull()?.let { it in 1..65535 } == true