feat(dual-screen): Send dashboard data Automatic, on by default

Automatic keeps the data output on for every game the In-game stats page
finds. The session applies it whenever the focused game changes (session
start, a game starting, a game closing) on devices with a second screen,
skipping the running game. Games the user switches off by hand stay off;
switching Automatic off puts every game DroidDeck changed back to its own
setting. Both settings are cleared by Reset settings.
This commit is contained in:
The412Banner committed 2026-10-31 19:49:47 +00:00
1 parent f896d7fa75
commit 63ad5a722f
7 files changed
+98 -14

No files matched your search

@@ -937,6 +937,9 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
gestureGame = nextGame
refreshGestureConfig()
}
if (secondScreenDisplays.isNotEmpty()) kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) {
runCatching { com.droiddeck.launcher.session.TelemetryOutput.applyAutomatic(this@SessionActivity, nextGame) }
}
}
LaunchedEffect(drawerOpen, pcKeyboardOpen, achievementsOpen, gestureSettingsOpen, pipUi, SessionState.suspended) {
if (drawerOpen || pcKeyboardOpen || achievementsOpen || gestureSettingsOpen || pipUi || SessionState.suspended) {
@@ -106,6 +106,20 @@ object SessionPrefs {
prefs(context).edit().putString("bottomPage", page).apply()
}
/** In-game stats "Send dashboard data" Automatic: on unless the user switched it off. */
fun telemetryAuto(context: Context): Boolean = prefs(context).getBoolean("telemetryAuto", true)
fun setTelemetryAuto(context: Context, on: Boolean) {
prefs(context).edit().putBoolean("telemetryAuto", on).apply()
}
/** Games the user switched off by hand, as TelemetryOutput keys; Automatic leaves them alone. */
fun telemetryOff(context: Context): Set<String> = prefs(context).getStringSet("telemetryOff", null)?.toSet().orEmpty()
fun setTelemetryOff(context: Context, keys: Set<String>) {
prefs(context).edit().putStringSet("telemetryOff", keys.toSet()).apply()
}
fun dualScreenLauncher(context: Context): Boolean = prefs(context).getBoolean("dualScreenLauncher", true)
fun setDualScreenLauncher(context: Context, on: Boolean) {
@@ -26,7 +26,7 @@ object SettingsReset {
"upscaler", "upscaleSharpness", "screenEffects", "textureAnisotropy", "textureLodBias",
"steamDownloadsInBackground", "steam_offline", "bootMovie", "bootMovieSound", "bootMovieVolume", "bootMovieSeconds",
"bootMovieApplyNext", "bootMovieSteamSeen",
"questDefaultsV1",
"questDefaultsV1", "telemetryAuto", "telemetryOff",
)
internal val SESSION_PREFIXES = listOf(
@@ -1,5 +1,7 @@
package com.droiddeck.launcher.session
import android.content.Context
import com.droiddeck.launcher.frontend.Library
import java.io.File
/**
@@ -60,6 +62,21 @@ 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. */
fun applyAutomatic(context: Context, running: String?) {
if (!SessionPrefs.telemetryAuto(context)) return
automaticTargets(scan(Library.compatdataDirs(context)), SessionPrefs.telemetryOff(context), running).forEach { set(it, true) }
}
internal fun key(game: Game) = "${game.prefixId}/${game.name}"
internal fun automaticTargets(games: List<Game>, off: Set<String>, running: String?): List<Game> =
games.filter { !it.on && key(it) !in off && !isRunning(it.prefixId, running) }
/** Games DroidDeck changed, which go back to their own setting when Automatic is switched off. */
internal fun restoreTargets(games: List<Game>, running: String?): List<Game> =
games.filter { File(it.file.path + ORIGINAL_SUFFIX).isFile && !isRunning(it.prefixId, running) }
/** Whether [running] (the focused Steam app id, or another key for non-Steam programs) may be the game in [prefixId]. */
internal fun isRunning(prefixId: String, running: String?): Boolean {
val id = running?.toLongOrNull() ?: return running != null
@@ -44,6 +44,7 @@ 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.session.SessionPrefs
import com.droiddeck.launcher.session.SessionState
import com.droiddeck.launcher.session.Telemetry
import com.droiddeck.launcher.session.TelemetryOutput
@@ -89,6 +90,7 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null }
var running by remember { mutableStateOf<String?>(null) }
var outputFailed by remember { mutableStateOf<String?>(null) }
var rescan by remember { mutableIntStateOf(0) }
var auto by remember { mutableStateOf(SessionPrefs.telemetryAuto(context)) }
val latest = remember { AtomicReference<Pair<Long, Telemetry>?>(null) }
var race by remember { mutableStateOf<Telemetry?>(null) }
var fpsNow by remember { mutableStateOf<Float?>(null) }
@@ -208,23 +210,30 @@ fun BottomTelemetryPage(fps: () -> Float?, runningGame: () -> String? = { null }
fontSize = 14.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(horizontal = 4.dp))
}
if (outputs.isNotEmpty() || menuGames.isNotEmpty()) TelemetryCard(stringResource(R.string.bottom_telemetry_send_title)) {
if (outputs.isNotEmpty()) SwitchRow(stringResource(R.string.bottom_telemetry_send_auto), stringResource(R.string.bottom_telemetry_send_auto_hint), auto, true) { want ->
scope.launch {
withContext(Dispatchers.IO) {
SessionPrefs.setTelemetryAuto(context, want)
if (want) TelemetryOutput.applyAutomatic(context, running)
else TelemetryOutput.restoreTargets(outputs, running).forEach { TelemetryOutput.set(it, false) }
}
auto = want
rescan++
}
}
for (game in outputs) {
val locked = TelemetryOutput.isRunning(game.prefixId, running)
Row(
Modifier.fillMaxWidth().toggleable(game.on, enabled = !locked, role = Role.Switch) { want ->
scope.launch {
val ok = withContext(Dispatchers.IO) { TelemetryOutput.set(game, want) }
outputFailed = if (ok) null else game.name
rescan++
SwitchRow(game.name, if (locked) stringResource(R.string.bottom_telemetry_send_close, game.name) else null, game.on, !locked) { want ->
scope.launch {
val ok = withContext(Dispatchers.IO) {
val key = TelemetryOutput.key(game)
val off = SessionPrefs.telemetryOff(context)
SessionPrefs.setTelemetryOff(context, if (want) off - key else off + key)
TelemetryOutput.set(game, want)
}
}.padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Column(Modifier.weight(1f).padding(end = 12.dp)) {
Text(game.name, fontSize = 15.sp, color = colors.onBackground, maxLines = 1, overflow = TextOverflow.Ellipsis)
if (locked) Text(stringResource(R.string.bottom_telemetry_send_close, game.name), fontSize = 12.sp, color = colors.onSurfaceVariant)
outputFailed = if (ok) null else game.name
rescan++
}
Switch(game.on, null, enabled = !locked)
}
}
for (game in menuGames) {
@@ -268,6 +277,21 @@ private fun DeviceRow(fps: Float?, s: HudMetrics.Snapshot?) {
}
}
@Composable
private fun SwitchRow(title: String, hint: String?, checked: Boolean, enabled: Boolean, onChange: (Boolean) -> Unit) {
val colors = MaterialTheme.colorScheme
Row(
Modifier.fillMaxWidth().toggleable(checked, enabled = enabled, role = Role.Switch, onValueChange = onChange).padding(vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Column(Modifier.weight(1f).padding(end = 12.dp)) {
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)
}
}
@Composable
private fun TelemetryTile(label: String, value: String, modifier: Modifier) {
val colors = MaterialTheme.colorScheme
+2
View File
@@ -1892,6 +1892,8 @@
<string name="bottom_notifications_clear">Clear</string>
<string name="bottom_page_screenshots">Screenshots</string>
<string name="bottom_telemetry_send_title">Send dashboard data</string>
<string name="bottom_telemetry_send_auto">Automatic</string>
<string name="bottom_telemetry_send_auto_hint">Turns it on for every game listed here, including games found later. Games you switch off stay off.</string>
<string name="bottom_telemetry_send_note">This changes the game\'s own data output setting. It takes effect the next time the game starts; turning it off puts the old setting back.</string>
<string name="bottom_telemetry_send_close">Close %1$s to change this.</string>
<string name="bottom_telemetry_send_failed">Could not change the settings of %1$s.</string>
@@ -77,6 +77,30 @@ class TelemetryOutputTest {
assertTrue(TelemetryOutput.isRunning("2848447563", "program:/games/x.exe"))
}
@Test fun automaticSkipsGamesThatAreOnSwitchedOffOrRunning() {
val f = File("x")
val showdownGame = TelemetryOutput.Game("DiRT Showdown", "2848447563", 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"))
assertEquals("690790/DiRT Rally 2.0", TelemetryOutput.key(rally))
}
@Test fun switchingAutomaticOffRestoresOnlyGamesDroidDeckChanged() {
val compatdata = tmp.newFolder("steamapps", "compatdata")
val changed = configFile(compatdata, "2848447563", "DiRT Showdown").apply { writeText(showdown) }
val own = configFile(compatdata, "690790", "DiRT Rally 2.0")
.apply { writeText("<x><udp enabled=\"true\" ip=\"127.0.0.1\" port=\"20777\" /></x>") }
assertTrue(TelemetryOutput.set(TelemetryOutput.scan(listOf(compatdata)).first { it.name == "DiRT Showdown" }, true))
val targets = TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), null)
assertEquals(listOf(changed), targets.map { it.file })
assertTrue(own.isFile)
assertTrue(TelemetryOutput.restoreTargets(TelemetryOutput.scan(listOf(compatdata)), "2848447563").isEmpty())
}
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() }