mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
Fix Steam game exit detection and return
This commit is contained in:
1 parent
9eca06d92e
commit
7dc9d342e3
3 files changed
+56
-5
No files matched your search
@@ -1633,8 +1633,13 @@ class SessionService : Service() {
|
|||||||
if (token != gameExitWatchToken || gen != sessionGen || !SessionState.running ||
|
if (token != gameExitWatchToken || gen != sessionGen || !SessionState.running ||
|
||||||
SessionState.stopRequested || SessionState.mode != MODE_STEAM ||
|
SessionState.stopRequested || SessionState.mode != MODE_STEAM ||
|
||||||
!SessionPrefs.returnAfterGame(this) || SessionState.gameId != gameId ||
|
!SessionPrefs.returnAfterGame(this) || SessionState.gameId != gameId ||
|
||||||
pendingSteamGameId != null || SteamGameProcess.running()) {
|
pendingSteamGameId != null) {
|
||||||
Log.i(TAG, "keeping Steam open after $gameId: another game is running or queued")
|
return@postDelayed
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SteamGameProcess.running()) {
|
||||||
|
Log.i(TAG, "another Steam game is still running after $gameId; checking again")
|
||||||
|
returnAfterGame(gameId, gen, token)
|
||||||
return@postDelayed
|
return@postDelayed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,39 @@ object SteamGameProcess {
|
|||||||
runCatching { File(p, "cmdline").readBytes() }
|
runCatching { File(p, "cmdline").readBytes() }
|
||||||
.getOrNull()?.let(::matches) == true
|
.getOrNull()?.let(::matches) == true
|
||||||
} == true
|
} == true
|
||||||
|
private fun steamAppIdForGameId(gameId: String): String? {
|
||||||
|
if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return null
|
||||||
|
|
||||||
|
val numericId = gameId.toULongOrNull() ?: return null
|
||||||
|
val appId = if (numericId > UInt.MAX_VALUE.toULong()) {
|
||||||
|
numericId shr 32
|
||||||
|
} else {
|
||||||
|
numericId
|
||||||
|
}
|
||||||
|
|
||||||
|
return appId.takeIf { it != 0uL }?.toString()
|
||||||
|
}
|
||||||
|
|
||||||
fun matches(cmdline: ByteArray, gameId: String): Boolean {
|
fun matches(cmdline: ByteArray, gameId: String): Boolean {
|
||||||
if (gameId.isEmpty() || !gameId.all(Char::isDigit)) return false
|
val expectedAppId = steamAppIdForGameId(gameId) ?: return false
|
||||||
val args = String(cmdline).split('\u0000')
|
val args = String(cmdline).split('\u0000')
|
||||||
|
|
||||||
for (i in args.indices) {
|
for (i in args.indices) {
|
||||||
if (args[i] == "SteamLaunch") {
|
if (args[i] == "SteamLaunch") {
|
||||||
val appId = args.getOrNull(i + 1)
|
val appId = args.getOrNull(i + 1)
|
||||||
?.takeIf { it.startsWith("AppId=") }
|
?.takeIf { it.startsWith("AppId=") }
|
||||||
?.removePrefix("AppId=")
|
?.removePrefix("AppId=")
|
||||||
if (appId == gameId) return true
|
|
||||||
|
if (appId == expectedAppId) return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if (args[i] == "-applaunch" &&
|
||||||
|
args.getOrNull(i + 1) == expectedAppId
|
||||||
|
) {
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
if (args[i] == "-applaunch" && args.getOrNull(i + 1) == gameId) return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,31 @@ class SteamGameProcessTest {
|
|||||||
assertFalse(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe"), "976310"))
|
assertFalse(SteamGameProcess.matches(cmdline("python3", "/proton", "waitforexitandrun", "game.exe"), "976310"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test fun shortcutCGameIdsMatchTheir32BitSteamAppId() {
|
||||||
|
val cgameId = ((976310L shl 32) or 0x02000000L).toString()
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
SteamGameProcess.matches(
|
||||||
|
cmdline("reaper", "SteamLaunch", "AppId=976310", "--", "proton", "waitforexitandrun", "game.exe"),
|
||||||
|
cgameId,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertTrue(
|
||||||
|
SteamGameProcess.matches(
|
||||||
|
cmdline("steam", "-applaunch", "976310"),
|
||||||
|
cgameId,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
assertFalse(
|
||||||
|
SteamGameProcess.matches(
|
||||||
|
cmdline("reaper", "SteamLaunch", "AppId=123", "--", "proton", "waitforexitandrun", "game.exe"),
|
||||||
|
cgameId,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@Test fun runningLooksAtEveryProcess() {
|
@Test fun runningLooksAtEveryProcess() {
|
||||||
val proc = tmp.newFolder("proc")
|
val proc = tmp.newFolder("proc")
|
||||||
fun process(pid: String, vararg args: String) = File(proc, pid).apply { mkdirs() }.resolve("cmdline").writeBytes(cmdline(*args))
|
fun process(pid: String, vararg args: String) = File(proc, pid).apply { mkdirs() }.resolve("cmdline").writeBytes(cmdline(*args))
|
||||||
|
|||||||
Reference in new issue
Block a user