mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
Add reversible process limit controls
This commit is contained in:
1 parent
ddd4a0c24d
commit
ecff3240a6
4 files changed
+177
-50
No files matched your search
@@ -212,10 +212,11 @@ class FrontEndActions(
|
||||
val onBackActionsInverted: (Boolean) -> Unit = {},
|
||||
val onCheckLatestBuild: () -> Unit = {},
|
||||
val onRefreshPhantomStatus: () -> Unit = {},
|
||||
val onOpenDeveloperOptions: () -> Unit = {},
|
||||
val onOpenDeveloperOptions: (Int?) -> Unit = {},
|
||||
val onWirelessAdbPair: (String, Int, String, (String?) -> Unit) -> Unit = { _, _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onFindWirelessAdbPort: (String, (Int?) -> Unit) -> Unit = { _, done -> done(null) },
|
||||
val onWirelessAdbApply: (String, Int, (String?) -> Unit) -> Unit = { _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onWirelessAdbApply: (String, Int, Boolean, (String?) -> Unit) -> Unit = { _, _, _, done -> done("Wireless ADB is unavailable") },
|
||||
val onSetPhantomProcessLimit: (Boolean, (String?) -> Unit) -> Unit = { _, done -> done("Wireless ADB is unavailable") },
|
||||
val onCopyPhantomCommand: () -> Unit = {},
|
||||
val onDismissPhantomGate: () -> Unit = {},
|
||||
val controller: ControllerActions? = null,
|
||||
@@ -355,9 +356,19 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
var selected by rememberSaveable { mutableStateOf("steam") }
|
||||
var navOpen by rememberSaveable { mutableStateOf(false) }
|
||||
var showWirelessAdbFix by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeveloperDisplayChoice by rememberSaveable { mutableStateOf(false) }
|
||||
var wirelessAdbDesiredEnabled by rememberSaveable { mutableStateOf(false) }
|
||||
var appToChooseDisplay by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val ctx = LocalContext.current
|
||||
val requestDeveloperOptions = {
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onOpenDeveloperOptions(null)
|
||||
else showDeveloperDisplayChoice = true
|
||||
}
|
||||
val requestWirelessAdbFix: (Boolean) -> Unit = { enabled ->
|
||||
wirelessAdbDesiredEnabled = enabled
|
||||
showWirelessAdbFix = true
|
||||
}
|
||||
LaunchedEffect(s.showPhantomGate, s.phantomProcessStatus) {
|
||||
if (s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
|
||||
while (true) {
|
||||
@@ -443,10 +454,15 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
.focusProperties { enter = { frontFocus.paneEntry() } }
|
||||
.focusGroup()
|
||||
val content: @Composable (Modifier) -> Unit = { m ->
|
||||
Pane(s, selected, a, page, m.then(paneFocus), { selected = it }) { app ->
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
|
||||
else appToChooseDisplay = app
|
||||
}
|
||||
Pane(
|
||||
s, selected, a, page, m.then(paneFocus), { selected = it },
|
||||
onAndroidAppClick = { app ->
|
||||
if (s.secondScreenDisplays.isEmpty()) a.onAndroidApp(app, null)
|
||||
else appToChooseDisplay = app
|
||||
},
|
||||
onOpenDeveloperOptions = requestDeveloperOptions,
|
||||
onRequestWirelessAdb = requestWirelessAdbFix,
|
||||
)
|
||||
}
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
@@ -498,16 +514,21 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
onDismissRequest = a.onDismissPhantomGate,
|
||||
title = { Text("Steam cannot start yet") },
|
||||
text = {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
Column(
|
||||
modifier = Modifier.heightIn(max = 320.dp).verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
) {
|
||||
Text(PhantomProcessLimit.title(s.phantomProcessStatus))
|
||||
Text(PhantomProcessLimit.gateInstructions(s.phantomProcessStatus))
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall)
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
androidx.compose.material3.TextButton(onClick = a.onOpenDeveloperOptions) { Text("Developer options") }
|
||||
androidx.compose.material3.TextButton(onClick = { showWirelessAdbFix = true }) { Text("Fix over Wi-Fi") }
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
androidx.compose.material3.TextButton(onClick = requestDeveloperOptions) { Text("Developer options") }
|
||||
androidx.compose.material3.TextButton(onClick = { requestWirelessAdbFix(false) }) { Text("Fix over Wi-Fi") }
|
||||
}
|
||||
androidx.compose.material3.TextButton(onClick = a.onCopyPhantomCommand) { Text("Copy ADB") }
|
||||
}
|
||||
},
|
||||
@@ -516,12 +537,40 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
|
||||
if (showWirelessAdbFix) {
|
||||
WirelessAdbFixDialog(
|
||||
onDismiss = { showWirelessAdbFix = false },
|
||||
onOpenDeveloperOptions = a.onOpenDeveloperOptions,
|
||||
desiredEnabled = wirelessAdbDesiredEnabled,
|
||||
onOpenDeveloperOptions = requestDeveloperOptions,
|
||||
onCopyCommand = a.onCopyPhantomCommand,
|
||||
onPair = a.onWirelessAdbPair,
|
||||
onFindConnectPort = a.onFindWirelessAdbPort,
|
||||
onApply = a.onWirelessAdbApply,
|
||||
)
|
||||
}
|
||||
if (showDeveloperDisplayChoice) {
|
||||
androidx.compose.material3.AlertDialog(
|
||||
onDismissRequest = { showDeveloperDisplayChoice = false },
|
||||
title = { Text("Open Developer options") },
|
||||
text = { Text("Choose where Settings should open.") },
|
||||
confirmButton = {
|
||||
Column(horizontalAlignment = Alignment.End) {
|
||||
androidx.compose.material3.TextButton(onClick = {
|
||||
showDeveloperDisplayChoice = false
|
||||
a.onOpenDeveloperOptions(null)
|
||||
}) { Text("Main screen") }
|
||||
s.secondScreenDisplays.forEach { display ->
|
||||
androidx.compose.material3.TextButton(onClick = {
|
||||
showDeveloperDisplayChoice = false
|
||||
a.onOpenDeveloperOptions(display.id)
|
||||
}) {
|
||||
Text(if (s.secondScreenDisplays.size == 1) "Bottom screen" else display.label)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
androidx.compose.material3.TextButton(onClick = { showDeveloperDisplayChoice = false }) { Text("Cancel") }
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
BackHandler(enabled = navOpen) { navOpen = false }
|
||||
val hasBackTarget = (s.pageKey != null && page != null) ||
|
||||
@@ -740,6 +789,7 @@ private fun NavItem(
|
||||
private fun Pane(
|
||||
s: FrontEndState, selected: String, a: FrontEndActions, page: (@Composable () -> Unit)?, modifier: Modifier,
|
||||
onSelect: (String) -> Unit, onAndroidAppClick: (HomeApp.LaunchableApp) -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit, onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
Box(modifier = modifier) {
|
||||
val wash: Pair<File?, Float> = when {
|
||||
@@ -761,7 +811,10 @@ private fun Pane(
|
||||
.apply { targetContentZIndex = 1f }
|
||||
},
|
||||
label = "pane",
|
||||
) { key -> if (page != null && key == s.pageKey) page() else Content(s, key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick) }
|
||||
) { key ->
|
||||
if (page != null && key == s.pageKey) page()
|
||||
else Content(s, key, a, Modifier.fillMaxSize(), onSelect, onAndroidAppClick, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -834,6 +887,7 @@ private fun romFor(s: FrontEndState, selected: String): Pair<Library.Emulator, L
|
||||
private fun Content(
|
||||
s: FrontEndState, selected: String, a: FrontEndActions, modifier: Modifier,
|
||||
onSelect: (String) -> Unit, onAndroidAppClick: (HomeApp.LaunchableApp) -> Unit,
|
||||
onOpenDeveloperOptions: () -> Unit, onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val detailPosterWidth = if (LocalConfiguration.current.screenHeightDp < 600) 72.dp else 120.dp
|
||||
@@ -917,7 +971,7 @@ private fun Content(
|
||||
ArtGrid(s.emulators.map { e -> Tile(e.name, if (e.installed) (if (e.id == "retroarch") null else "${e.games.size} game${if (e.games.size == 1) "" else "s"}") else "Select to install", null, "emu:${e.id}", e.iconRes, dim = !e.installed) { onSelect("emu:${e.id}") } })
|
||||
}
|
||||
}
|
||||
selected == "setup" -> SetupPanel(s, a)
|
||||
selected == "setup" -> SetupPanel(s, a, onOpenDeveloperOptions, onRequestWirelessAdb)
|
||||
selected.startsWith("emu:") -> {
|
||||
val e = s.emulators.firstOrNull { "emu:${it.id}" == selected }
|
||||
if (e == null) Note("Not installed.") else {
|
||||
@@ -1036,8 +1090,28 @@ private fun Content(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SetupPanel(s: FrontEndState, a: FrontEndActions) {
|
||||
private fun SetupPanel(
|
||||
s: FrontEndState,
|
||||
a: FrontEndActions,
|
||||
onOpenDeveloperOptions: () -> Unit,
|
||||
onRequestWirelessAdb: (Boolean) -> Unit,
|
||||
) {
|
||||
val host = rememberMenuHost()
|
||||
var processLimitBusy by remember { mutableStateOf(false) }
|
||||
var processLimitMessage by remember { mutableStateOf<String?>(null) }
|
||||
val setProcessLimit: (Boolean) -> Unit = { enabled ->
|
||||
processLimitBusy = true
|
||||
processLimitMessage = null
|
||||
a.onSetPhantomProcessLimit(enabled) { error ->
|
||||
processLimitBusy = false
|
||||
if (error == null) {
|
||||
a.onRefreshPhantomStatus()
|
||||
} else {
|
||||
processLimitMessage = "Wireless ADB is unavailable. Pair this device or use Developer options."
|
||||
onRequestWirelessAdb(enabled)
|
||||
}
|
||||
}
|
||||
}
|
||||
val runtime = when {
|
||||
s.busy -> "Working…"
|
||||
!s.ready -> "Install"
|
||||
@@ -1048,22 +1122,32 @@ private fun SetupPanel(s: FrontEndState, a: FrontEndActions) {
|
||||
Column(modifier = Modifier.fillMaxSize().verticalScroll(rememberScrollState()).padding(bottom = 24.dp)) {
|
||||
Rise(0) { Eyebrow("Setup") }
|
||||
Rise(1) { Title("Setup") }
|
||||
if (PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
|
||||
SettingsGroup("Android process limit") {
|
||||
Text(
|
||||
PhantomProcessLimit.title(s.phantomProcessStatus),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.error,
|
||||
)
|
||||
Text(PhantomProcessLimit.instructions(s.phantomProcessStatus), color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SecondaryButton("Developer options", onClick = a.onOpenDeveloperOptions)
|
||||
SecondaryButton("Check again", onClick = a.onRefreshPhantomStatus)
|
||||
}
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
|
||||
SecondaryButton("Copy ADB command", onClick = a.onCopyPhantomCommand)
|
||||
SettingsGroup("Android process limit") {
|
||||
Text(
|
||||
PhantomProcessLimit.title(s.phantomProcessStatus),
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = if (PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) MaterialTheme.colorScheme.error else MaterialTheme.colorScheme.onBackground,
|
||||
modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp),
|
||||
)
|
||||
Text(
|
||||
"Enabling restores Android’s child-process limit. Disabling it is recommended for Steam sessions.",
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
modifier = Modifier.padding(horizontal = 14.dp),
|
||||
)
|
||||
if (s.phantomProcessStatus != PhantomProcessStatus.NOT_APPLICABLE) {
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) {
|
||||
SecondaryButton("Enable limit", enabled = !processLimitBusy && s.phantomProcessStatus != PhantomProcessStatus.ENABLED) { setProcessLimit(true) }
|
||||
SecondaryButton("Disable limit", enabled = !processLimitBusy && s.phantomProcessStatus != PhantomProcessStatus.DISABLED) { setProcessLimit(false) }
|
||||
}
|
||||
if (processLimitBusy) LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(horizontal = 14.dp, vertical = 8.dp))
|
||||
processLimitMessage?.let { Text(it, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp)) }
|
||||
}
|
||||
Text(PhantomProcessLimit.instructions(s.phantomProcessStatus), color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp))
|
||||
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 4.dp))
|
||||
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.padding(horizontal = 14.dp, vertical = 8.dp)) {
|
||||
SecondaryButton("Developer options", onClick = onOpenDeveloperOptions)
|
||||
SecondaryButton("Check again", onClick = a.onRefreshPhantomStatus)
|
||||
SecondaryButton("Copy ADB", onClick = a.onCopyPhantomCommand)
|
||||
}
|
||||
}
|
||||
SettingsGroup("Launcher tools") {
|
||||
|
||||
@@ -24,10 +24,12 @@ 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, (String?) -> Unit) -> Unit,
|
||||
onApply: (String, Int, Boolean, (String?) -> Unit) -> Unit,
|
||||
) {
|
||||
var step by rememberSaveable { mutableStateOf(0) }
|
||||
var host by rememberSaveable { mutableStateOf("") }
|
||||
@@ -45,17 +47,21 @@ fun WirelessAdbFixDialog(
|
||||
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. Return to the Wireless debugging screen and enter the current IP address and port shown there. This connect port is different from the pairing port.")
|
||||
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 disabled. You can start Steam now.")
|
||||
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)) {
|
||||
@@ -83,7 +89,7 @@ fun WirelessAdbFixDialog(
|
||||
} else {
|
||||
connectPort = discoveredPort.toString()
|
||||
message = "Device found. Applying the setting…"
|
||||
onApply(host, discoveredPort) { applyError ->
|
||||
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"
|
||||
@@ -96,17 +102,20 @@ fun WirelessAdbFixDialog(
|
||||
1 -> TextButton(enabled = !busy && validPort(connectPort), onClick = {
|
||||
busy = true
|
||||
message = null
|
||||
onApply(host, connectPort.toInt()) { error ->
|
||||
onApply(host, connectPort.toInt(), desiredEnabled) { error ->
|
||||
busy = false
|
||||
if (error == null) { step = 2; message = null } else message = error
|
||||
}
|
||||
}) { Text("Disable child-process limit") }
|
||||
}) { Text(if (desiredEnabled) "Enable child-process limit" else "Disable child-process limit") }
|
||||
else -> TextButton(onClick = onDismiss) { Text("Done") }
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
Row {
|
||||
if (step < 2) TextButton(enabled = !busy, onClick = onOpenDeveloperOptions) { Text("Developer options") }
|
||||
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") }
|
||||
}
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user