From 8ccd771059c4c817ef4b6c7b2e2a7631bf2a14b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Mart=C3=AD?= Date: Tue, 20 Oct 2026 19:31:17 -0400 Subject: [PATCH] fix: open game Components on the game's profile (#1146) --- .../com/droiddeck/launcher/MainActivity.kt | 6 +- .../droiddeck/launcher/ui/ComponentsPage.kt | 3 +- .../droiddeck/launcher/ui/FrontEndScreen.kt | 1 + .../droiddeck/launcher/ui/FrontEndSetup.kt | 5 +- .../launcher/ui/ComponentsPageProfileTest.kt | 64 ++++++++++++--- .../ui/LaunchSettingsComponentsTest.kt | 78 +++++++++++++++++++ docs/development/game-environment.md | 4 +- 7 files changed, 145 insertions(+), 16 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/ui/LaunchSettingsComponentsTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt index b9ab65cc52..66b43bc347 100644 --- a/app/src/main/java/com/droiddeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/MainActivity.kt @@ -124,6 +124,7 @@ class MainActivity : ComponentActivity() { private var steamController by mutableStateOf(SessionPrefs.CONTROLLER_DECK) private var showComponents by mutableStateOf(false) private var focusComponentsContent by mutableStateOf(true) + private var componentsGameKey by mutableStateOf(null) private var showMapping by mutableStateOf(false) private var saveBusy: String? = null private var onSavePicked: ((File) -> Unit)? = null @@ -922,6 +923,7 @@ class MainActivity : ComponentActivity() { }, onProtons = { openProtons() }, onComponents = { focusContent -> openComponents(focusContent) }, + onGameComponents = { game -> openComponents(gameKey = game.profileKey) }, onComponentsTab = { tab -> openComponents(focusContent = true, tab = tab) }, onSaveImport = { sg -> importSaves(sg.name) { GameSaves.game(sg) } }, onSaveExport = { sg, layout -> exportSaves(sg.name, layout) { GameSaves.game(sg) } }, @@ -1434,8 +1436,9 @@ class MainActivity : ComponentActivity() { ) } - private fun openComponents(focusContent: Boolean = true, tab: String? = null) { + private fun openComponents(focusContent: Boolean = true, tab: String? = null, gameKey: String? = null) { focusComponentsContent = focusContent + componentsGameKey = gameKey if (tab != null) components.compComp = tab showPerformance = false showMapping = false @@ -1484,6 +1487,7 @@ class MainActivity : ComponentActivity() { onImport = { pickComponent.launch(InAppFilePicker.buildIntent(this, WCP_EXT, getString(R.string.comp_pick_wcp))) }, onBack = { if (!com.droiddeck.launcher.ui.Hops.back { showComponents = false }) showComponents = false }, games = steamGames, + initialGameKey = componentsGameKey, generalFexPreset = fexPreset, onGeneralFexPreset = { id -> SessionPrefs.setFexPreset(this, id); fexPreset = id }, gpu = drivers.state(), diff --git a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt index d50a45c4ea..d44f599406 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/ComponentsPage.kt @@ -151,6 +151,7 @@ fun ComponentsPage( onImport: () -> Unit, onBack: () -> Unit, games: List = emptyList(), + initialGameKey: String? = null, generalFexPreset: String = "", onGeneralFexPreset: (String) -> Unit = {}, requestInitialFocus: Boolean = true, @@ -169,7 +170,7 @@ fun ComponentsPage( val layer = if (comp in LAYERS) comp else GPU_TAB BackHandler(onBack = onBack) var scopeMenu by remember { mutableStateOf(false) } - var selectedGameKey by remember { mutableStateOf(null) } + var selectedGameKey by remember(initialGameKey) { mutableStateOf(initialGameKey) } var fexMenu by remember { mutableStateOf(false) } var gameProtonMenu by remember { mutableStateOf(false) } var gameProtonId by remember { mutableStateOf(null) } 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 2698e6e6d5..6e44aca350 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndScreen.kt @@ -189,6 +189,7 @@ class FrontEndActions( val onImportLossless: () -> Unit, val onProtons: () -> Unit, val onComponents: (focusContent: Boolean) -> Unit, + val onGameComponents: (Library.SteamGame) -> Unit = { onComponents(true) }, val onComponentsTab: (String) -> Unit = {}, val onSaveImport: (Library.SteamGame) -> Unit = {}, val onSaveExport: (Library.SteamGame, com.droiddeck.launcher.session.GameSaves.Layout) -> Unit = { _, _ -> }, diff --git a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt index 42eb27d69b..9b65cc8a91 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/FrontEndSetup.kt @@ -523,8 +523,9 @@ internal fun LaunchSettings(s: FrontEndState, a: FrontEndActions, host: MenuHost val back = stringResource(R.string.hop_from_games) SettingCard(stringResource(R.string.setup_card_components), stringResource(R.string.setup_card_components_hint), "card:components", m.hopSource("card:components")) { val at = Hops.sources["card:components"] - if (at == null) a.onComponents(true) - else Hops.go(HopOrigin("games", HOP_SURFACE_GAMES, null, "card:components", at, back, dest = "components", page = "components")) { a.onComponents(true) } + val open = { if (game == null) a.onComponents(true) else a.onGameComponents(game) } + if (at == null) open() + else Hops.go(HopOrigin("games", HOP_SURFACE_GAMES, null, "card:components", at, back, dest = "components", page = "components"), open) } } add { m -> diff --git a/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt index e01d884da5..501438788e 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/ComponentsPageProfileTest.kt @@ -1,5 +1,6 @@ package com.droiddeck.launcher.ui +import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick import com.droiddeck.launcher.R @@ -15,9 +16,59 @@ import org.robolectric.annotation.Config @Config(sdk = [28]) class ComponentsPageProfileTest { @get:Rule val compose = createRobolectricComposeRule() + private val gameA = Library.SteamGame(42, "Game A", null, "internal") + private val gameB = Library.SteamGame(43, "Game B", null, "internal") @Test fun gameProfilesCoexistWithTheDefaultComponentStack() { val context = RuntimeEnvironment.getApplication() + show() + val stackHeading = context.getString(R.string.comp_this_proton).uppercase() + compose.onNodeWithText(stackHeading).assertExists() + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText("Game A").performClick() + compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists() + compose.onNodeWithText(stackHeading).assertDoesNotExist() + + compose.onNodeWithText("Game A").performClick() + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText(stackHeading).assertExists() + } + + @Test fun opensTheRequestedGameProfileAndAllowsSwitchingToDefault() { + val context = RuntimeEnvironment.getApplication() + show { gameB.profileKey } + compose.onNodeWithText("Game B").assertExists() + compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists() + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertDoesNotExist() + + compose.onNodeWithText("Game B").performClick() + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists() + } + + @Test fun aNewNavigationTargetReplacesThePreviousProfile() { + val context = RuntimeEnvironment.getApplication() + val target = mutableStateOf(gameA.profileKey) + show { target.value } + compose.onNodeWithText("Game A").assertExists() + + compose.runOnIdle { target.value = gameB.profileKey } + compose.onNodeWithText("Game B").assertExists() + compose.onNodeWithText("Game A").assertDoesNotExist() + + compose.runOnIdle { target.value = null } + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).assertExists() + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists() + } + + @Test fun anUnavailableGameFallsBackToTheDefaultProfile() { + val context = RuntimeEnvironment.getApplication() + show { "missing-game" } + compose.onNodeWithText(context.getString(R.string.comp_scope_general)).assertExists() + compose.onNodeWithText(context.getString(R.string.comp_this_proton).uppercase()).assertExists() + } + + private fun show(initialGameKey: () -> String? = { null }) { compose.setContent { DroidDeckTheme { ComponentsPage( @@ -40,20 +91,11 @@ class ComponentsPageProfileTest { onRefresh = {}, onImport = {}, onBack = {}, - games = listOf(Library.SteamGame(42, "Game A", null, "internal")), + games = listOf(gameA, gameB), + initialGameKey = initialGameKey(), requestInitialFocus = false, ) } } - val stackHeading = context.getString(R.string.comp_this_proton).uppercase() - compose.onNodeWithText(stackHeading).assertExists() - compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() - compose.onNodeWithText("Game A").performClick() - compose.onNodeWithText(context.getString(R.string.comp_game_hint)).assertExists() - compose.onNodeWithText(stackHeading).assertDoesNotExist() - - compose.onNodeWithText("Game A").performClick() - compose.onNodeWithText(context.getString(R.string.comp_scope_general)).performClick() - compose.onNodeWithText(stackHeading).assertExists() } } diff --git a/app/src/test/java/com/droiddeck/launcher/ui/LaunchSettingsComponentsTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/LaunchSettingsComponentsTest.kt new file mode 100644 index 0000000000..37544588f3 --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/ui/LaunchSettingsComponentsTest.kt @@ -0,0 +1,78 @@ +package com.droiddeck.launcher.ui + +import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performClick +import com.droiddeck.launcher.R +import com.droiddeck.launcher.frontend.Library +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNull +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.RuntimeEnvironment +import org.robolectric.annotation.Config + +@RunWith(RobolectricTestRunner::class) +@Config(sdk = [28]) +class LaunchSettingsComponentsTest { + @get:Rule val compose = createRobolectricComposeRule() + private var openedGame: Library.SteamGame? = null + private var defaultOpens = 0 + + @Test fun gameComponentsCardPassesItsGameInsteadOfOpeningDefault() { + val game = Library.SteamGame(42, "Game A", null, "internal") + show(game) + clickComponents() + assertEquals(game, openedGame) + assertEquals(0, defaultOpens) + } + + @Test fun addedGameComponentsCardPreservesItsUnsignedProfileKey() { + val game = Library.SteamGame(-42, "Added game", null, Library.ADDED) + show(game) + clickComponents() + assertEquals(game.profileKey, openedGame?.profileKey) + assertEquals("4294967254", openedGame?.profileKey) + assertEquals(0, defaultOpens) + } + + @Test fun generalComponentsCardStillOpensDefault() { + show(null) + clickComponents() + assertNull(openedGame) + assertEquals(1, defaultOpens) + } + + private fun clickComponents() { + compose.onNodeWithText(RuntimeEnvironment.getApplication().getString(R.string.setup_card_components)).performClick() + compose.waitForIdle() + } + + private fun show(game: Library.SteamGame?) { + compose.setContent { + DroidDeckTheme { + LaunchSettings( + FrontEndState( + installed = null, ready = false, available = null, busy = false, stage = "", percent = -1, + desktopInstalled = false, offlineAccount = null, offline = false, frameGenLabel = "", + romsDir = null, logsEnabled = false, steamGames = listOfNotNull(game), + emulators = emptyList(), running = null, + ), + FrontEndActions( + onPlay = {}, onPlayDesktopUi = {}, onSteamGame = {}, onDesktop = {}, onEmulator = {}, + onRom = {}, onResume = {}, onSteamSettings = {}, onDesktopSettings = {}, + onInstallPackage = {}, onRemovePackage = {}, onRuntime = {}, onFrameGenPick = {}, + onImportLossless = {}, onProtons = {}, onComponents = { defaultOpens++ }, + onGameComponents = { openedGame = it }, onPerformance = {}, + onRoms = {}, onFiles = {}, onLogs = {}, onOffline = {}, + onWirelessAdbPair = { _, _, _, _ -> }, onWirelessAdbApply = { _, _, _, _ -> }, + onSetPhantomProcessLimit = { _, _ -> }, + ), + rememberMenuHost(), + game, + ) + } + } + } +} diff --git a/docs/development/game-environment.md b/docs/development/game-environment.md index 2bbf28c786..a6e02b8e27 100644 --- a/docs/development/game-environment.md +++ b/docs/development/game-environment.md @@ -10,7 +10,9 @@ Changes apply on the next game launch, including when Steam is already running. A running game must be restarted. Native Linux games and Steam itself are outside this editor's scope. -The Components page also has a **Configuration** dropdown. **Default profile** owns the +Opening **Components** from a game's launch settings selects that game's profile. +Opening Components from the navigation rail selects **Default profile**. Use the +**Configuration** dropdown to switch profiles explicitly. **Default profile** owns the default Proton and FEX preset. An installed game can inherit those defaults or choose its own Proton and FEX preset. Proton choices are applied through Steam's per-app compatibility mapping, including while Steam is running when its live