From 66abf0c7075677353e3489d2eecdc54c9132949e Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sat, 31 Oct 2026 20:26:16 +0000 Subject: [PATCH] fix(dual-screen): tap-only In-game stats styles; Automatic leaves DiRT 3 and Showdown off - The Layout row is gone; tapping the top strip or the dash changes its style, and one line under the page says so. - DiRT 3 and DiRT Showdown can stop at the end of a race with WinSock error 10038 while their UDP output is on (a known game bug; the community workaround by RoccoC/DiRTTelemetryErrorFix intercepts that error). Automatic now leaves those two off and puts back one it had switched on; their switch says why, and turning it on by hand is remembered. - A switch locked while its game runs keeps its on colours instead of looking off. - The Circuit dash hides the fuel and tyre cards when the game sends neither (DiRT Showdown). --- .../launcher/session/SessionPrefs.kt | 7 ++ .../launcher/session/SettingsReset.kt | 2 +- .../launcher/session/TelemetryOutput.kt | 20 ++++-- .../launcher/ui/BottomTelemetryPage.kt | 68 ++++--------------- .../com/droiddeck/launcher/ui/StatsDashes.kt | 17 ++--- app/src/main/res/values/strings.xml | 15 +--- .../launcher/session/TelemetryOutputTest.kt | 34 ++++++++-- 7 files changed, 77 insertions(+), 86 deletions(-) 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 74b071efb4..3d0bfbd958 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionPrefs.kt @@ -132,6 +132,13 @@ object SessionPrefs { prefs(context).edit().putStringSet("telemetryOff", keys.toSet()).apply() } + /** Games the user switched on by hand, as TelemetryOutput keys; Automatic keeps them on. */ + fun telemetryOnByHand(context: Context): Set = prefs(context).getStringSet("telemetryOnByHand", null)?.toSet().orEmpty() + + fun setTelemetryOnByHand(context: Context, keys: Set) { + prefs(context).edit().putStringSet("telemetryOnByHand", keys.toSet()).apply() + } + fun dualScreenLauncher(context: Context): Boolean = prefs(context).getBoolean("dualScreenLauncher", true) fun setDualScreenLauncher(context: Context, on: Boolean) { diff --git a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt index 1756c631ac..3bd1c09e7d 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SettingsReset.kt @@ -26,7 +26,7 @@ object SettingsReset { "upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias", "steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds", "bootMovieApplyNext", "bootMovieSteamSeen", - "questDefaultsV1", "telemetryAuto", "telemetryOff", "statsStrip", "statsDash", + "questDefaultsV1", "telemetryAuto", "telemetryOff", "telemetryOnByHand", "statsStrip", "statsDash", ) internal val SESSION_PREFIXES = listOf( diff --git a/app/src/main/java/com/droiddeck/launcher/session/TelemetryOutput.kt b/app/src/main/java/com/droiddeck/launcher/session/TelemetryOutput.kt index afd60b02d1..6673e8aecf 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/TelemetryOutput.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/TelemetryOutput.kt @@ -10,7 +10,10 @@ import java.io.File * In-game stats listener; the file as it was is kept beside it, and its element is put back when turned off. */ object TelemetryOutput { - data class Game(val name: String, val prefixId: String, val file: File, val on: Boolean) + data class Game(val name: String, val prefixId: String, val file: File, val on: Boolean) { + /** DiRT 3 and DiRT Showdown can stop at the end of a race with WinSock error 10038 while this output is on. */ + val raceEndCrash: Boolean get() = name.lowercase().replace(" ", "") in RACE_END_CRASH + } data class MenuGame(val name: String, val setting: String, val port: Int) @@ -28,6 +31,7 @@ object TelemetryOutput { private const val ADDRESS = "127.0.0.1" private const val EXTRADATA = "3" private val TAGS = listOf("udp", "motion") + private val RACE_END_CRASH = setOf("dirtshowdown", "dirt3") // Byte-for-byte: every byte maps to one char and back, whatever the file's own encoding is. private val BYTES = Charsets.ISO_8859_1 @@ -62,16 +66,24 @@ object TelemetryOutput { true }.getOrDefault(false) - /** Automatic: turns the output on for every found game the user has not switched off and that is not running. */ + /** + * Automatic: turns the output on for every found game the user has not switched off and that is not running. + * Games with the race-end crash are left to the user, and ones Automatic switched on go back to their own setting. + */ fun applyAutomatic(context: Context, running: String?) { if (!SessionPrefs.telemetryAuto(context)) return - automaticTargets(scan(Library.compatdataDirs(context)), SessionPrefs.telemetryOff(context), running).forEach { set(it, true) } + val games = scan(Library.compatdataDirs(context)) + automaticTargets(games, SessionPrefs.telemetryOff(context), running).forEach { set(it, true) } + automaticRestores(games, SessionPrefs.telemetryOnByHand(context), running).forEach { set(it, false) } } internal fun key(game: Game) = "${game.prefixId}/${game.name}" internal fun automaticTargets(games: List, off: Set, running: String?): List = - games.filter { !it.on && key(it) !in off && !isRunning(it.prefixId, running) } + games.filter { !it.on && !it.raceEndCrash && key(it) !in off && !isRunning(it.prefixId, running) } + + internal fun automaticRestores(games: List, onByHand: Set, running: String?): List = + games.filter { it.raceEndCrash && it.on && key(it) !in onByHand && File(it.file.path + ORIGINAL_SUFFIX).isFile && !isRunning(it.prefixId, running) } /** Games DroidDeck changed, which go back to their own setting when Automatic is switched off. */ internal fun restoreTargets(games: List, running: String?): List = 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 93593b3713..da2d286cc7 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/BottomTelemetryPage.kt @@ -1,9 +1,6 @@ package com.droiddeck.launcher.ui import androidx.compose.foundation.background -import androidx.compose.foundation.border -import androidx.compose.foundation.clickable -import androidx.compose.foundation.horizontalScroll import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -20,6 +17,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Switch +import androidx.compose.material3.SwitchDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect @@ -273,12 +271,18 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null } } for (game in outputs) { val locked = TelemetryOutput.isRunning(game.prefixId, running) - SwitchRow(game.name, if (locked) stringResource(R.string.bottom_telemetry_send_close, game.name) else null, game.on, !locked) { want -> + val hint = listOfNotNull( + if (locked) stringResource(R.string.bottom_telemetry_send_close, game.name) else null, + if (game.raceEndCrash) stringResource(R.string.bottom_telemetry_send_crash) else null, + ).joinToString("\n").ifEmpty { null } + SwitchRow(game.name, hint, game.on, !locked) { want -> scope.launch { val ok = withContext(Dispatchers.IO) { val key = TelemetryOutput.key(game) val off = SessionPrefs.telemetryOff(context) + val byHand = SessionPrefs.telemetryOnByHand(context) SessionPrefs.setTelemetryOff(context, if (want) off - key else off + key) + SessionPrefs.setTelemetryOnByHand(context, if (want) byHand + key else byHand - key) TelemetryOutput.set(game, want) } outputFailed = if (ok) null else game.name @@ -300,54 +304,7 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null } Text(stringResource(R.string.bottom_telemetry_port_busy, busyPorts.sorted().joinToString()), fontSize = 13.sp, color = colors.error, modifier = Modifier.padding(horizontal = 4.dp)) } - LayoutPicker(strip, dash, - onStrip = { strip = it; SessionPrefs.setStatsStrip(context, it.id) }, - onDash = { dash = it; SessionPrefs.setStatsDash(context, it.id) }) - } -} - -@Composable -private fun LayoutPicker(strip: StatsStrip, dash: StatsDash, onStrip: (StatsStrip) -> Unit, onDash: (StatsDash) -> Unit) { - val colors = MaterialTheme.colorScheme - TelemetryCard(stringResource(R.string.stats_layout)) { - PickRow(stringResource(R.string.stats_layout_top), StatsStrip.entries.map { it to stringResource(stripLabel(it)) }, strip, onStrip) - PickRow(stringResource(R.string.stats_layout_dash), StatsDash.entries.map { it to stringResource(dashLabel(it)) }, dash, onDash) - Text(stringResource(R.string.stats_layout_hint), fontSize = 12.sp, color = colors.onSurfaceVariant) - } -} - -private fun stripLabel(s: StatsStrip): Int = when (s) { - StatsStrip.PANEL -> R.string.stats_strip_panel - StatsStrip.TILES -> R.string.stats_strip_tiles - StatsStrip.RINGS -> R.string.stats_strip_rings -} - -private fun dashLabel(d: StatsDash): Int = when (d) { - StatsDash.AUTO -> R.string.stats_dash_auto - StatsDash.SPEEDOMETER -> R.string.stats_dash_speedometer - StatsDash.CIRCUIT -> R.string.stats_dash_circuit - StatsDash.TRACE -> R.string.stats_dash_trace - StatsDash.DIALS -> R.string.stats_dash_dials - StatsDash.GLANCE -> R.string.stats_dash_glance -} - -@Composable -private fun PickRow(title: String, options: List>, selected: T, onPick: (T) -> Unit) { - val pal = LocalPalette.current - val colors = MaterialTheme.colorScheme - val shape = RoundedCornerShape(50) - Row(Modifier.fillMaxWidth().horizontalScroll(rememberScrollState()), verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(6.dp)) { - Text(title, fontSize = 13.sp, color = colors.onSurfaceVariant, modifier = Modifier.width(44.dp)) - for ((value, label) in options) { - val on = value == selected - Text(label, fontSize = 13.sp, fontWeight = if (on) FontWeight.Bold else FontWeight.Normal, - color = if (on) colors.background else colors.onBackground, maxLines = 1, - modifier = Modifier.clip(shape).background(if (on) pal.primary else Color.Transparent) - .border(1.dp, if (on) pal.primary else pal.line, shape) - .clickable { onPick(value) } - .padding(horizontal = 12.dp, vertical = 6.dp)) - } + Text(stringResource(R.string.stats_tap_hint), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp)) } } @@ -374,7 +331,12 @@ private fun SwitchRow(title: String, hint: String?, checked: Boolean, enabled: B Text(title, fontSize = 15.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis) if (hint != null) Text(hint, fontSize = 12.sp, color = colors.onSurfaceVariant) } - Switch(checked, null, enabled = enabled) + val pal = LocalPalette.current + Switch(checked, null, enabled = enabled, colors = SwitchDefaults.colors( + disabledCheckedTrackColor = pal.primary.copy(alpha = 0.45f), + disabledCheckedThumbColor = colors.background, + disabledCheckedBorderColor = pal.primary.copy(alpha = 0.45f), + )) } } diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StatsDashes.kt b/app/src/main/java/com/droiddeck/launcher/ui/StatsDashes.kt index 3ccc055630..651ae759b4 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StatsDashes.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StatsDashes.kt @@ -240,17 +240,14 @@ private fun CircuitDash(t: Telemetry) { fontSize = 12.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant) } } - Column(Modifier.weight(0.9f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(8.dp)) { - StatsCard(stringResource(R.string.bottom_telemetry_fuel), Modifier.fillMaxWidth().weight(1f)) { - val fuel = t.fuel - if (fuel != null) { - Bar(fuel, colors.onBackground, Modifier.fillMaxWidth().height(14.dp)) - Text("${(fuel * 100).roundToInt()}%", fontSize = 13.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant) - } else Text("–", fontSize = 13.sp, color = colors.onSurfaceVariant) - } - t.tireTempsC?.takeIf { it.size == 4 }?.let { tires -> - StatsCard(stringResource(R.string.stats_tires), Modifier.fillMaxWidth().weight(1.3f)) { Tires(tires, Modifier.fillMaxWidth().weight(1f)) } + val fuel = t.fuel + val tires = t.tireTempsC?.takeIf { it.size == 4 } + if (fuel != null || tires != null) Column(Modifier.weight(0.9f).fillMaxHeight(), verticalArrangement = Arrangement.spacedBy(8.dp)) { + if (fuel != null) StatsCard(stringResource(R.string.bottom_telemetry_fuel), Modifier.fillMaxWidth().weight(1f)) { + Bar(fuel, colors.onBackground, Modifier.fillMaxWidth().height(14.dp)) + Text("${(fuel * 100).roundToInt()}%", fontSize = 13.sp, fontFamily = FontFamily.Monospace, color = colors.onSurfaceVariant) } + if (tires != null) StatsCard(stringResource(R.string.stats_tires), Modifier.fillMaxWidth().weight(1.3f)) { Tires(tires, Modifier.fillMaxWidth().weight(1f)) } } } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8c82992f95..cf986262bd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1915,19 +1915,8 @@ Fuel, t Main %1$s t Reserve %1$s t - Layout - Top - Dash - Tapping the top strip or the dash also switches to the next style. - Panel - Tiles - Rings - Auto - Speedometer - Circuit - Trace - Dials - Glance + Tap the top strip or the dash to change its style. + This game can stop at the end of a race while this is on, so Automatic leaves it off. Send dashboard data Automatic Turns it on for every game listed here, including games found later. Games you switch off stay off. diff --git a/app/src/test/java/com/droiddeck/launcher/session/TelemetryOutputTest.kt b/app/src/test/java/com/droiddeck/launcher/session/TelemetryOutputTest.kt index 597820af8b..fbd2e37514 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/TelemetryOutputTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/TelemetryOutputTest.kt @@ -79,13 +79,13 @@ class TelemetryOutputTest { @Test fun automaticSkipsGamesThatAreOnSwitchedOffOrRunning() { val f = File("x") - val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false) + val dirt4 = TelemetryOutput.Game("DiRT 4", "421020", f, on = false) val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false) val grid = TelemetryOutput.Game("GRID", "703860", f, on = true) - val games = listOf(showdownGame, rally, grid) - assertEquals(listOf(showdownGame, rally), TelemetryOutput.automaticTargets(games, emptySet(), null)) - assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("2848447563/DiRT Showdown"), null)) - assertEquals(listOf(showdownGame), TelemetryOutput.automaticTargets(games, emptySet(), "690790")) + val games = listOf(dirt4, rally, grid) + assertEquals(listOf(dirt4, rally), TelemetryOutput.automaticTargets(games, emptySet(), null)) + assertEquals(listOf(rally), TelemetryOutput.automaticTargets(games, setOf("421020/DiRT 4"), null)) + assertEquals(listOf(dirt4), TelemetryOutput.automaticTargets(games, emptySet(), "690790")) assertEquals("690790/DiRT Rally 2.0", TelemetryOutput.key(rally)) } @@ -101,6 +101,30 @@ class TelemetryOutputTest { assertTrue(TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), "2848447563").isEmpty()) } + @Test fun automaticLeavesTheRaceEndCrashGamesToTheUser() { + val f = File("x") + val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", f, on = false) + val dirt3 = TelemetryOutput.Game("DiRT3", "321040", f, on = false) + val rally = TelemetryOutput.Game("DiRT Rally 2.0", "690790", f, on = false) + assertTrue(showdownGame.raceEndCrash) + assertTrue(dirt3.raceEndCrash) + assertFalse(rally.raceEndCrash) + assertEquals(listOf(rally), TelemetryOutput.automaticTargets(listOf(showdownGame, dirt3, rally), emptySet(), null)) + } + + @Test fun automaticPutsBackAShowdownItSwitchedOnButNotOneTheUserDid() { + val compatdata = tmp.newFolder("steamapps", "compatdata") + val config = configFile(compatdata, "2848447563", "DiRT Showdown").apply { writeText(showdown) } + val game = TelemetryOutput.scan(listOf(compatdata)).single() + assertTrue(TelemetryOutput.set(game, true)) + val on = TelemetryOutput.scan(listOf(compatdata)) + assertEquals(on, TelemetryOutput.automaticRestores(on, emptySet(), null)) + assertTrue(TelemetryOutput.automaticRestores(on, setOf("2848447563/DiRT Showdown"), null).isEmpty()) + assertTrue(TelemetryOutput.automaticRestores(on, emptySet(), "2848447563").isEmpty()) + on.forEach { TelemetryOutput.set(it, false) } + assertEquals(showdown, config.readText()) + } + private fun configFile(compatdata: File, id: String, game: String): File = File(compatdata, "$id/pfx/drive_c/users/steamuser/Documents/My Games/$game/hardwaresettings/hardware_settings_config.xml") .apply { parentFile!!.mkdirs() }