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 8e16fb59c0..e5a65ca1dc 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionService.kt @@ -1630,13 +1630,22 @@ class SessionService : Service() { } private fun returnAfterGame(gameId: String, gen: Int, token: Int) { - if (token != gameExitWatchToken || gen != sessionGen || !SessionState.running || - SessionState.stopRequested || SessionState.mode != MODE_STEAM || !SessionPrefs.returnAfterGame(this)) return - val written = runCatching { File(LinuxRuntime.sessionRoot(this), "steam-stop").writeText("") } - .onFailure { Log.w(TAG, "could not ask the client to exit after game $gameId", it) }.isSuccess - if (!written) return - SessionEvents.record("steam.return_after_game", mapOf("gameId" to gameId)) - Log.i(TAG, "game $gameId closed: asking the client to exit and returning to the launcher") + mainHandler.postDelayed({ + if (token != gameExitWatchToken || gen != sessionGen || !SessionState.running || + SessionState.stopRequested || SessionState.mode != MODE_STEAM || + !SessionPrefs.returnAfterGame(this) || SessionState.gameId != gameId || + pendingSteamGameId != null || SteamGameProcess.running()) { + Log.i(TAG, "keeping Steam open after $gameId: another game is running or queued") + return@postDelayed + } + + val written = runCatching { File(LinuxRuntime.sessionRoot(this), "steam-stop").writeText("") } + .onFailure { Log.w(TAG, "could not ask the client to exit after game $gameId", it) }.isSuccess + if (!written) return@postDelayed + + SessionEvents.record("steam.return_after_game", mapOf("gameId" to gameId)) + Log.i(TAG, "game $gameId closed: asking the client to exit and returning to the launcher") + }, GAME_EXIT_CONFIRM_MS) } private fun steamGameRunning(gameId: String): Boolean = @@ -2484,6 +2493,7 @@ class SessionService : Service() { private const val GAME_URL_PREFIX = "steam://rungameid/" private const val GAME_START_TIMEOUT_MS = 20 * 60_000L private const val GAME_EXIT_GRACE_MS = 10_000L + private const val GAME_EXIT_CONFIRM_MS = 2_000L private const val GAME_EXIT_POLL_MS = 2_000L private const val NO_PAD_SWITCH = "Download/droiddeck-no-pad" private const val NO_UINPUT_SWITCH = "Download/droiddeck-no-uinput"