From 2938c63d2c97066a8dba09fd7dca1e90002592a4 Mon Sep 17 00:00:00 2001 From: EnzoDLofi Date: Tue, 10 Nov 2026 19:02:13 -0400 Subject: [PATCH] Fix per-game screen effects tracking --- .../com/droiddeck/launcher/SessionActivity.kt | 19 +++++++--- .../launcher/session/SessionService.kt | 5 +-- .../launcher/session/SteamGameProcess.kt | 35 ++++++++++++++++--- .../launcher/session/SteamGameProcessTest.kt | 24 ++++++++----- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt index 4961e23f5a..40dadaa12d 100644 --- a/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/droiddeck/launcher/SessionActivity.kt @@ -983,8 +983,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde isFocusableInTouchMode = true defaultFocusHighlightEnabled = false setContent { - val effectsEditorProfileId = androidx.compose.runtime.remember(drawerOpen) { - if (drawerOpen) currentScreenEffectsProfileId() else null + val activeEffectsProfileId = currentScreenEffectsProfileId() + val effectsEditorProfileId = if (drawerOpen) activeEffectsProfileId else null + androidx.compose.runtime.LaunchedEffect(effectsEditorProfileId) { + if (effectsEditorProfileId != null && + SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity) == effectsEditorProfileId) { + effects = SessionPrefs.screenEffects(this@SessionActivity, effectsEditorProfileId) + } } val uiPointer = appUiOwnsPointer() androidx.compose.runtime.SideEffect { @@ -3758,8 +3763,14 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde }, menu = { DroidDeckTheme { - val effectsEditorProfileId = androidx.compose.runtime.remember(drawerOpen, drawerPinned) { - if (drawerOpen || drawerPinned) currentScreenEffectsProfileId() else null + val activeEffectsProfileId = currentScreenEffectsProfileId() + val effectsEditorProfileId = + if (drawerOpen || drawerPinned) activeEffectsProfileId else null + androidx.compose.runtime.LaunchedEffect(effectsEditorProfileId) { + if (effectsEditorProfileId != null && + SessionPrefs.activeScreenEffectsProfileId(this@SessionActivity) == effectsEditorProfileId) { + effects = SessionPrefs.screenEffects(this@SessionActivity, effectsEditorProfileId) + } } SessionMenu(docked = true, effectsEditorProfileId = effectsEditorProfileId) } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt index 6a3b0d12db..aeb83a1fde 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1595,7 +1595,7 @@ class SessionService : Service() { var goneSince = 0L while (token == gameExitWatchToken && gen == sessionGen && SessionState.running && !SessionState.stopRequested) { val now = android.os.SystemClock.elapsedRealtime() - if (steamGameRunning()) { + if (steamGameRunning(gameId)) { if (!seen) Log.i(TAG, "game $gameId started; tracking its exit") seen = true goneSince = 0L @@ -1637,7 +1637,8 @@ class SessionService : Service() { Log.i(TAG, "game $gameId closed: asking the client to exit and returning to the launcher") } - private fun steamGameRunning(): Boolean = SteamGameProcess.running() + private fun steamGameRunning(gameId: String): Boolean = + SteamGameProcess.running(gameId) private fun resumeSession(panelVisible: Boolean = true) { if (SessionState.suspended) SessionState.resumeRequested = true diff --git a/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt b/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt index 891fb57ca8..aebc817087 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SteamGameProcess.kt @@ -3,16 +3,41 @@ package com.droiddeck.launcher.session import java.io.File object SteamGameProcess { + // Compatibilidade com telas que precisam detectar qualquer jogo Steam. fun matches(cmdline: ByteArray): Boolean { + val args = String(cmdline).split('\u0000') + return args.indices.any { i -> + args[i] == "waitforexitandrun" || + (args[i] == "SteamLaunch" && + args.getOrNull(i + 1)?.startsWith("AppId=") == true) + } + } + + fun running(): Boolean = + File("/proc").listFiles()?.any { p -> + p.name.all(Char::isDigit) && + runCatching { File(p, "cmdline").readBytes() } + .getOrNull()?.let(::matches) == true + } == true + fun matches(cmdline: ByteArray, gameId: String): Boolean { + if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return false val args = String(cmdline).split('\u0000') for (i in args.indices) { - if (args[i] == "waitforexitandrun") return true - if (args[i] == "SteamLaunch" && args.getOrNull(i + 1)?.startsWith("AppId=") == true) return true + if (args[i] == "SteamLaunch") { + val appId = args.getOrNull(i + 1) + ?.takeIf { it.startsWith("AppId=") } + ?.removePrefix("AppId=") + if (appId == gameId) return true + } + if (args[i] == "-applaunch" && args.getOrNull(i + 1) == gameId) return true } return false } - fun running(proc: File = File("/proc")): Boolean = proc.listFiles()?.any { p -> - p.name.all(Char::isDigit) && runCatching { File(p, "cmdline").readBytes() }.getOrNull()?.let(::matches) == true - } == true + fun running(gameId: String, proc: File = File("/proc")): Boolean = + proc.listFiles()?.any { p -> + p.name.all(Char::isDigit) && + runCatching { File(p, "cmdline").readBytes() } + .getOrNull()?.let { matches(it, gameId) } == true + } == true } diff --git a/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt index 7a1723b95f..354b84c04e 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SteamGameProcessTest.kt @@ -13,17 +13,21 @@ class SteamGameProcessTest { private fun cmdline(vararg args: String) = args.joinToString("\u0000", postfix = "\u0000").toByteArray() @Test fun theSessionsOwnSearchesAreNotAGame() { - assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]"))) - assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch"))) - assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch AppId=976310( |$)"))) - assertFalse(SteamGameProcess.matches(cmdline("sh", "-c", "pgrep -f 'proton waitforexitandrun'"))) - assertFalse(SteamGameProcess.matches(cmdline("/usr/bin/steam", "steam://rungameid/976310"))) + assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("pgrep", "-f", "reaper SteamLaunch AppId=976310( |$)"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("sh", "-c", "pgrep -f 'proton waitforexitandrun'"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("/usr/bin/steam", "steam://rungameid/976310"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("reaper", "SteamLaunch", "AppId=976310"), "")) + assertFalse(SteamGameProcess.matches(cmdline("reaper", "SteamLaunch", "AppId=976310"), "abc")) } @Test fun steamsReaperAndProtonAreAGame() { assertTrue(SteamGameProcess.matches(cmdline("/root/.local/share/Steam/steamrtarm64/reaper", "SteamLaunch", "AppId=976310", "--", - "/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe"))) - assertTrue(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe"))) + "/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe"), "976310")) + assertFalse(SteamGameProcess.matches(cmdline("/root/.local/share/Steam/steamrtarm64/reaper", "SteamLaunch", "AppId=976310", "--", + "/root/.local/share/Steam/compatibilitytools.d/droiddeck-proton-arm64/proton", "waitforexitandrun", "MK11.exe"), "123")) + assertFalse(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe"), "976310")) } @Test fun runningLooksAtEveryProcess() { @@ -31,8 +35,10 @@ class SteamGameProcessTest { fun process(pid: String, vararg args: String) = File(proc, pid).apply { mkdirs() }.resolve("cmdline").writeBytes(cmdline(*args)) process("100", "pgrep", "-a", "-f", "SteamLaunch AppId=[0-9]") process("self", "reaper", "SteamLaunch", "AppId=1") - assertFalse(SteamGameProcess.running(proc)) + assertFalse(SteamGameProcess.running("976310", proc)) + assertTrue(SteamGameProcess.running("1", proc)) process("200", "reaper", "SteamLaunch", "AppId=976310", "--", "proton", "waitforexitandrun", "MK11.exe") - assertTrue(SteamGameProcess.running(proc)) + assertTrue(SteamGameProcess.running("976310", proc)) + assertFalse(SteamGameProcess.running("123", proc)) } }