Replace process gate dialogs with pages

This commit is contained in:
xXJsonDeruloXx committed 2026-09-25 16:28:15 -04:00
1 parent 09f8eb8ee3
commit b6998206ef
3 files changed
+154 -62

No files matched your search

@@ -52,9 +52,9 @@ object PhantomProcessLimit {
}
fun gateInstructions(status: PhantomProcessStatus): String = when (status) {
PhantomProcessStatus.ENABLED -> "Turn off “Restrict child processes” in Developer options. If it is not listed, connect this device to a computer with ADB and run the command below."
PhantomProcessStatus.UNSET -> "The ROM default may enforce this limit. Turn off “Restrict child processes” in Developer options. If it is not listed, connect this device to a computer with ADB and run the command below."
PhantomProcessStatus.UNREADABLE -> "DroidDeck could not check this setting. Turn off “Restrict child processes” in Developer options, or connect this device to a computer with ADB and run the command below."
PhantomProcessStatus.ENABLED -> "Turn off “Restrict child processes” in Developer options."
PhantomProcessStatus.UNSET -> "The ROM default may enforce this limit. Explicitly turn off “Restrict child processes” in Developer options."
PhantomProcessStatus.UNREADABLE -> "DroidDeck could not check this setting. Turn off “Restrict child processes” in Developer options."
else -> instructions(status)
}
@@ -361,6 +361,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
var appToChooseDisplay by remember { mutableStateOf<HomeApp.LaunchableApp?>(null) }
val colors = MaterialTheme.colorScheme
val ctx = LocalContext.current
val phantomGateVisible = s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)
val processSettingsPageVisible = phantomGateVisible || showWirelessAdbFix || showDeveloperDisplayChoice
val requestDeveloperOptions = {
if (s.secondScreenDisplays.isEmpty()) a.onOpenDeveloperOptions(null)
else showDeveloperDisplayChoice = true
@@ -370,18 +372,18 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
showWirelessAdbFix = true
}
LaunchedEffect(s.showPhantomGate, s.phantomProcessStatus) {
if (s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
if (phantomGateVisible) {
while (true) {
kotlinx.coroutines.delay(2_000)
a.onRefreshPhantomStatus()
}
}
}
BackHandler(enabled = s.pageKey != null && page != null) { a.onPageBack() }
BackHandler(enabled = !processSettingsPageVisible && s.pageKey != null && page != null) { a.onPageBack() }
// Back (and B) from a game or an emulator steps out one level, as its "‹" link does, instead
// of leaving the app: a game -> its emulator (or Steam), an emulator -> Desktop.
BackHandler(
enabled = (s.pageKey == null || page == null) &&
enabled = !processSettingsPageVisible && (s.pageKey == null || page == null) &&
(selected.startsWith("app:") || selected.startsWith("emu:") || selected.startsWith("rom:")),
) {
selected = when {
@@ -412,7 +414,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
// Start controllers on the current page's main action; the rail is initially collapsed.
val window = LocalWindowInfo.current
val inputMode = LocalInputModeManager.current
LaunchedEffect(Unit) {
LaunchedEffect(processSettingsPageVisible) {
if (processSettingsPageVisible) return@LaunchedEffect
snapshotFlow { window.isWindowFocused }.first { it }
repeat(20) {
if (anyFocused) return@LaunchedEffect
@@ -426,16 +429,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, showWirelessAdbFix) {
if (showWirelessAdbFix) return@LaunchedEffect
LaunchedEffect(selected, s.pageKey, processSettingsPageVisible) {
if (processSettingsPageVisible) 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, showWirelessAdbFix) {
if (showWirelessAdbFix) return@LaunchedEffect
LaunchedEffect(navOpen, railSelection, processSettingsPageVisible) {
if (processSettingsPageVisible) return@LaunchedEffect
if (navOpen) {
frontFocus.focusedRail = null
repeat(12) {
@@ -511,32 +514,19 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
onDismiss = { appToChooseDisplay = null },
)
}
if (s.showPhantomGate && PhantomProcessLimit.blocksSteam(s.phantomProcessStatus)) {
androidx.compose.material3.AlertDialog(
onDismissRequest = a.onDismissPhantomGate,
title = { Text("Steam cannot start yet") },
text = {
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 = {
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") }
}
},
)
if (phantomGateVisible && !showWirelessAdbFix && !showDeveloperDisplayChoice) {
Box(Modifier.fillMaxSize().background(colors.background)) {
PhantomProcessGatePage(
status = s.phantomProcessStatus,
onDismiss = a.onDismissPhantomGate,
onRefresh = a.onRefreshPhantomStatus,
onOpenDeveloperOptions = requestDeveloperOptions,
onFixOverWifi = { requestWirelessAdbFix(false) },
onCopyCommand = a.onCopyPhantomCommand,
)
}
}
if (showWirelessAdbFix) {
if (showWirelessAdbFix && !showDeveloperDisplayChoice) {
Box(Modifier.fillMaxSize().background(colors.background)) {
WirelessAdbFixPage(
onBack = { showWirelessAdbFix = false },
@@ -550,37 +540,29 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com
}
}
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") }
},
)
Box(Modifier.fillMaxSize().background(colors.background)) {
DeveloperDisplayChoicePage(
displays = s.secondScreenDisplays.map { display ->
display.id to if (s.secondScreenDisplays.size == 1) "Bottom screen" else display.label
},
onMainScreen = {
showDeveloperDisplayChoice = false
a.onOpenDeveloperOptions(null)
},
onSecondaryScreen = { displayId ->
showDeveloperDisplayChoice = false
a.onOpenDeveloperOptions(displayId)
},
onBack = { showDeveloperDisplayChoice = false },
)
}
}
}
BackHandler(enabled = navOpen) { navOpen = false }
BackHandler(enabled = navOpen && !processSettingsPageVisible) { navOpen = false }
val hasBackTarget = (s.pageKey != null && page != null) ||
((s.pageKey == null || page == null) &&
(selected.startsWith("app:") || selected.startsWith("emu:") || selected.startsWith("rom:")))
BackHandler(enabled = !navOpen && !hasBackTarget) { navOpen = true }
BackHandler(enabled = !processSettingsPageVisible && !navOpen && !hasBackTarget) { navOpen = true }
}
@@ -0,0 +1,110 @@
package com.droiddeck.launcher.ui
import androidx.activity.compose.BackHandler
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.foundation.layout.padding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.droiddeck.launcher.core.PhantomProcessLimit
import com.droiddeck.launcher.core.PhantomProcessStatus
@Composable
fun PhantomProcessGatePage(
status: PhantomProcessStatus,
onDismiss: () -> Unit,
onRefresh: () -> Unit,
onOpenDeveloperOptions: () -> Unit,
onFixOverWifi: () -> Unit,
onCopyCommand: () -> Unit,
) {
BackHandler(onBack = onDismiss)
SettingsPage(
host = rememberMenuHost(),
title = "Steam cannot start yet",
eyebrow = "Steam",
lede = PhantomProcessLimit.title(status),
onBack = onDismiss,
) {
Column(
modifier = Modifier.widthIn(max = 720.dp).fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
SettingsGroup("What to change") {
Text(
PhantomProcessLimit.gateInstructions(status),
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(14.dp),
)
}
SettingsGroup("Computer ADB fallback") {
Column(
modifier = Modifier.fillMaxWidth().padding(14.dp),
verticalArrangement = Arrangement.spacedBy(8.dp),
) {
Text(
"If you cannot find the setting in Developer options, connect this device to a computer with ADB and run:",
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Text(PhantomProcessLimit.ADB_COMMAND, style = MaterialTheme.typography.bodySmall)
SecondaryButton("Copy ADB command", onClick = onCopyCommand)
}
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
PrimaryButton("Fix over Wi-Fi", onClick = onFixOverWifi)
SecondaryButton("Developer options", onClick = onOpenDeveloperOptions)
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
SecondaryButton("Check again", onClick = onRefresh)
SecondaryButton("Not now", onClick = onDismiss)
}
Text(
"DroidDeck checks this setting again automatically every two seconds.",
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodySmall,
)
}
}
}
@Composable
fun DeveloperDisplayChoicePage(
displays: List<Pair<Int, String>>,
onMainScreen: () -> Unit,
onSecondaryScreen: (Int) -> Unit,
onBack: () -> Unit,
) {
BackHandler(onBack = onBack)
SettingsPage(
host = rememberMenuHost(),
title = "Open Developer options",
eyebrow = "Setup",
lede = "Choose which display to open Android Settings on.",
onBack = onBack,
) {
Column(
modifier = Modifier.widthIn(max = 720.dp).fillMaxWidth(),
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
SettingsGroup("Display") {
Column(
modifier = Modifier.fillMaxWidth().padding(14.dp),
verticalArrangement = Arrangement.spacedBy(10.dp),
) {
PrimaryButton("Main screen", onClick = onMainScreen)
displays.forEach { (id, label) ->
SecondaryButton(label, onClick = { onSecondaryScreen(id) })
}
}
}
}
}
}