From b6998206efe19532bd45b14c60062a70f9baee07 Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Fri, 25 Sep 2026 16:28:15 -0400 Subject: [PATCH] Replace process gate dialogs with pages --- .../launcher/core/PhantomProcessLimit.kt | 6 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 100 +++++++--------- .../launcher/ui/PhantomProcessGatePage.kt | 110 ++++++++++++++++++ 3 files changed, 154 insertions(+), 62 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/ui/PhantomProcessGatePage.kt diff --git a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt index 9b2fcfefe3..eb9f1d98e2 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/PhantomProcessLimit.kt @@ -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) } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt index c3a3cb1626..24a7bea6cb 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -361,6 +361,8 @@ private fun FrontEndScreenBody(s: FrontEndState, a: FrontEndActions, page: (@Com var appToChooseDisplay by remember { mutableStateOf(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 } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/PhantomProcessGatePage.kt b/app/src/main/java/com/droiddeck/launcher/ui/PhantomProcessGatePage.kt new file mode 100644 index 0000000000..76cb107a25 --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/ui/PhantomProcessGatePage.kt @@ -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>, + 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) }) + } + } + } + } + } +}