mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
fix: open game Components on the game's profile (#1146)
This commit is contained in:
1 parent
79889755fd
commit
92444946ea
7 files changed
+145
-16
No files matched your search
@@ -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<String?>(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(),
|
||||
|
||||
@@ -151,6 +151,7 @@ fun ComponentsPage(
|
||||
onImport: () -> Unit,
|
||||
onBack: () -> Unit,
|
||||
games: List<Library.SteamGame> = 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<String?>(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<String?>(null) }
|
||||
|
||||
@@ -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 = { _, _ -> },
|
||||
|
||||
@@ -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 ->
|
||||
|
||||
@@ -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<String?>(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()
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user