fix(session): launching the running game again resumes it instead of asking Steam twice (#2940)

* fix(session): launching the running game again resumes it instead of asking Steam twice

A front end that resumes a suspended player by launching the same game again
(Cocoon 3.07 does) made DroidDeck queue the game for Steam a second time,
and Steam answered with "An error occurred while launching this game: Game
already running" over the game.

queueSteamGame now resumes the session and returns when the requested game is
the current one and its process is running. A different game, or one that has
exited, still goes to Steam as before.

* fix(session): a relaunch during a pending freeze resumes too, and both game ID forms count as the same game
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-20 11:40:17 -05:00
1 parent d0022a35f9
commit 83dc5f37e9
3 files changed
+25

No files matched your search

@@ -1613,6 +1613,11 @@ class SessionService : Service() {
return
}
val accepted = gameId!!
if (pendingSteamGameId == null && SteamGameProcess.alreadyRunning(accepted, SessionState.gameId)) {
Log.i(TAG, "game $accepted is already running; resuming it instead of launching it again")
if (SessionState.suspended || SessionState.suspending) resumeSession()
return
}
if (!pendingSteamPreviousGamePending) {
pendingSteamPreviousGameId = SessionState.gameId
pendingSteamPreviousGamePending = true
@@ -61,4 +61,11 @@ object SteamGameProcess {
runCatching { File(p, "cmdline").readBytes() }
.getOrNull()?.let { matches(it, gameId) } == true
} == true
// A front end that resumes a player by launching the same game again would otherwise have Steam
// start it a second time, which Steam answers with "Game already running".
fun alreadyRunning(requested: String, current: String?, proc: File = File("/proc")): Boolean {
val appId = steamAppIdForGameId(requested) ?: return false
return appId == steamAppIdForGameId(current.orEmpty()) && running(requested, proc)
}
}
@@ -88,4 +88,17 @@ class SteamGameProcessTest {
process("301", "reaper", "SteamLaunch", "AppId=351710", "--", "proton", "waitforexitandrun", "game.exe")
assertTrue(SteamGameProcess.running("351710", proc))
}
@Test fun onlyTheRunningCurrentGameCountsAsAlreadyRunning() {
val proc = tmp.newFolder("proc-relaunch")
File(proc, "200").apply { mkdirs() }.resolve("cmdline")
.writeBytes(cmdline("reaper", "SteamLaunch", "AppId=584400", "--", "proton", "waitforexitandrun", "SonicMania.exe"))
assertTrue(SteamGameProcess.alreadyRunning("584400", "584400", proc))
assertFalse(SteamGameProcess.alreadyRunning("584400", "311340", proc))
assertFalse(SteamGameProcess.alreadyRunning("311340", "311340", proc))
assertFalse(SteamGameProcess.alreadyRunning("584400", null, proc))
val shortcutId = ((584400uL shl 32) or 0x02000000uL).toString()
assertTrue(SteamGameProcess.alreadyRunning(shortcutId, "584400", proc))
assertTrue(SteamGameProcess.alreadyRunning("584400", shortcutId, proc))
}
}