diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index dc35ec198..dddf47204 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -3132,9 +3132,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback { dashboard = if (bottomPages().isEmpty()) null else ({ DroidDeckTheme { BottomDashboard( - bottomPages(), SessionPrefs.bottomPage(this), + bottomPages(), com.droiddeck.launcher.ui.SessionBottomTab.picked(SessionState.sessionId), gameStarts = gameStarts, - onPage = { SessionPrefs.setBottomPage(this, it) }, + onPage = { com.droiddeck.launcher.ui.SessionBottomTab.pick(SessionState.sessionId, it) }, onClose = { selectSecondScreenMode(SecondScreenMode.NONE) }, onMenu = if (dockDrawer()) ({ drawerOpen = true }) else null, ) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt index da0cf34a0..5b82b22f0 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -100,12 +100,6 @@ object SessionPrefs { prefs(context).edit().putString("secondScreenPanel", mode).apply() } - fun bottomPage(context: Context): String? = prefs(context).getString("bottomPage", null) - - fun setBottomPage(context: Context, page: String) { - prefs(context).edit().putString("bottomPage", page).apply() - } - fun statsStrip(context: Context): String? = prefs(context).getString("statsStrip", null) fun setStatsStrip(context: Context, id: String) { diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomDashboard.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomDashboard.kt index f57bbc61b..4943d99d7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomDashboard.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomDashboard.kt @@ -56,7 +56,25 @@ class BottomPage( internal fun pickBottomPage(remembered: String?, ids: List): String? = ids.firstOrNull { it == remembered } ?: ids.firstOrNull { it == DEFAULT_PAGE } ?: ids.firstOrNull() -/** The page a game start switches to; not saved, so the page the user picked still opens next time. */ +/** + * The tab picked during one session. Each Steam session starts with no pick, so the dashboard opens on Chat; reopened + * later in the same session it shows the tab picked last. + */ +internal object SessionBottomTab { + private var session: String? = null + private var tab: String? = null + + @Synchronized + fun picked(sessionId: String?): String? = tab.takeIf { sessionId != null && sessionId == session } + + @Synchronized + fun pick(sessionId: String?, id: String) { + session = sessionId + tab = id + } +} + +/** The page a game start switches to; not remembered as the user's pick. */ internal fun pageForGameStart(ids: List): String? = GAME_PAGE.takeIf { it in ids } private const val DEFAULT_PAGE = "chat" diff --git a/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt b/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt index 4d179d07e..c1fb9c2a7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt @@ -47,7 +47,9 @@ import com.droiddeck.launcher.hud.MangoReadings import com.droiddeck.launcher.runtime.LinuxRuntime import com.droiddeck.launcher.session.GameStatusFiles import com.droiddeck.launcher.session.GameTelemetry +import com.droiddeck.launcher.input.SteamTouchConfig import com.droiddeck.launcher.session.SessionPrefs +import com.droiddeck.launcher.session.SessionService import com.droiddeck.launcher.session.SessionState import com.droiddeck.launcher.session.SpeedUnit import com.droiddeck.launcher.session.StatsDash @@ -96,6 +98,8 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null } var outputs by remember { mutableStateOf>(emptyList()) } var menuGames by remember { mutableStateOf>(emptyList()) } var running by remember { mutableStateOf(null) } + var gameName by remember { mutableStateOf(null) } + val steamClient = remember { if (SessionState.mode == SessionService.MODE_STEAM) SessionPrefs.activeSteamClientArch(context) else null } var outputFailed by remember { mutableStateOf(null) } var rescan by remember { mutableIntStateOf(0) } var auto by remember { mutableStateOf(SessionPrefs.telemetryAuto(context)) } @@ -216,6 +220,11 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null } runCatching { Library.steamGames(context).mapNotNull { TelemetryOutput.MENU_GAMES[it.appId] }.distinct() }.getOrDefault(emptyList()) } } + LaunchedEffect(running) { + val id = running?.toLongOrNull() + gameName = if (id == null) null + else withContext(Dispatchers.IO) { runCatching { SteamTouchConfig.gameName(context, id.toInt()) }.getOrNull() } + } LaunchedEffect(rescan) { while (isActive) { outputs = withContext(Dispatchers.IO) { runCatching { TelemetryOutput.scan(Library.compatdataDirs(context)) }.getOrDefault(emptyList()) } @@ -226,7 +235,8 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null } Column(Modifier.fillMaxSize().verticalScroll(rememberScrollState()), verticalArrangement = Arrangement.spacedBy(10.dp)) { perfTick.let { - StatsStripView(strip, StripData(fpsNow, device, fpsHistory.snapshot(), cpuHistory.snapshot(), gpuHistory.snapshot(), wattsHistory.snapshot(), clock)) { + StatsStripView(strip, StripData(fpsNow, device, fpsHistory.snapshot(), cpuHistory.snapshot(), gpuHistory.snapshot(), wattsHistory.snapshot(), clock, + if (running != null) gameName else steamClient?.let { stringResource(steamClientLabel(it)) })) { strip = strip.next() SessionPrefs.setStatsStrip(context, strip.id) } @@ -325,6 +335,9 @@ private fun httpGet(url: String): String { } +/** The Steam client the session runs, shown in the strip's top line while no game runs. */ +internal fun steamClientLabel(arch: String): Int = if (arch == "x86_64") R.string.stats_steam_client_x86 else R.string.stats_steam_client_arm + @Composable private fun ChoiceRow(title: String, value: String, onClick: () -> Unit) { val colors = MaterialTheme.colorScheme diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StatsStrips.kt b/app/src/main/java/com/droiddeck/launcher/ui/StatsStrips.kt index e67120da7..7e6ae6434 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StatsStrips.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StatsStrips.kt @@ -39,6 +39,7 @@ import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.font.FontFamily import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp @@ -95,13 +96,16 @@ private fun LogoBadge(size: Dp) { } } +/** The mark and "DroidDeck" on the left, the running game's name in the middle, the clock on the right. */ @Composable -private fun LogoHeader(clock: String) { +private fun LogoHeader(clock: String, game: String?) { val colors = MaterialTheme.colorScheme - Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp), modifier = Modifier.padding(horizontal = 2.dp)) { + Row(Modifier.fillMaxWidth().padding(horizontal = 2.dp), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(6.dp)) { DroidDeckLogo(16.dp) Text("DroidDeck", fontSize = 13.sp, fontWeight = FontWeight.Bold, color = colors.onBackground) - if (clock.isNotEmpty()) Text("· $clock", fontSize = 12.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant) + Text(game.orEmpty(), fontSize = 13.sp, fontWeight = FontWeight.Bold, color = colors.onBackground, textAlign = TextAlign.Center, + maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.weight(1f)) + if (clock.isNotEmpty()) Text(clock, fontSize = 12.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant) } } @@ -146,6 +150,7 @@ internal class StripData( val gpuHistory: List, val wattsHistory: List, val clock: String, + val game: String? = null, ) private fun percentTemp(percent: Int?, temp: Int?): String = @@ -212,7 +217,7 @@ private fun TilesStrip(d: StripData) { val gpuPercent: Int? = s?.gpuPercent val gpuTemp: Int? = s?.gpuTempC Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(6.dp)) { - LogoHeader(d.clock) + LogoHeader(d.clock, d.game) Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) { HistoryTile("FPS", accent, fpsText(d.fps), "fps", d.fpsHistory, 75f) HistoryTile("CPU", StatsColors.cpu, s?.cpuPercent?.let { "$it%" } ?: "–", s?.cpuTempC?.let { "$it°" } ?: "", d.cpuHistory, 100f) @@ -248,7 +253,7 @@ private fun RingsStrip(d: StripData) { val gpuPercent: Int? = s?.gpuPercent val gpuTemp: Int? = s?.gpuTempC Column(Modifier.fillMaxWidth(), verticalArrangement = Arrangement.spacedBy(6.dp)) { - LogoHeader(d.clock) + LogoHeader(d.clock, d.game) Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.spacedBy(8.dp)) { RingTile("CPU", StatsColors.cpu, s?.cpuPercent?.let { it / 100f }, s?.cpuPercent?.let { "$it%" } ?: "–", s?.cpuTempC?.let { "$it °C" } ?: "") RingTile("GPU", StatsColors.gpu, gpuPercent?.let { it / 100f }, gpuPercent?.let { "$it%" } ?: gpuTemp?.let { "$it°" } ?: "–", diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9fcf9d129..ed1ebe545 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1903,6 +1903,8 @@ Gear Speed units Automatic (%1$s) + Steam Client ARM + Steam Client x86 Throttle Brake Dashboard diff --git a/app/src/test/java/com/droiddeck/launcher/ui/BottomDashboardTest.kt b/app/src/test/java/com/droiddeck/launcher/ui/BottomDashboardTest.kt index b129ae57f..5a5141889 100644 --- a/app/src/test/java/com/droiddeck/launcher/ui/BottomDashboardTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/ui/BottomDashboardTest.kt @@ -55,4 +55,17 @@ class BottomTelemetryLapTimeTest { assertEquals("1:23.456", lapTime(83.456f)) assertEquals("0:05.000", lapTime(5f)) } + + @Test fun eachSessionStartsWithoutAPickedTab() { + SessionBottomTab.pick("2026-11-01-01-steam", "screenshots") + assertEquals("screenshots", SessionBottomTab.picked("2026-11-01-01-steam")) + assertNull(SessionBottomTab.picked("2026-11-01-02-steam")) + assertNull(SessionBottomTab.picked(null)) + assertEquals("chat", pickBottomPage(SessionBottomTab.picked("2026-11-01-02-steam"), listOf("telemetry", "chat", "screenshots"))) + } + + @Test fun theStripNamesTheSteamClient() { + assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_x86, steamClientLabel("x86_64")) + assertEquals(com.droiddeck.launcher.R.string.stats_steam_client_arm, steamClientLabel("arm64")) + } }