Apply Game cores changed during a session to the next game launch

The game cores list reached the guest only in the session environment,
so a change made while the session ran was ignored until the next
session, and a launch kept the old cores. The app now publishes the
current choice to the guest with the other game settings, and the launch
wrapper reads it at each launch, falling back to the session value when
the file is missing.
This commit is contained in:
maxjivi05 committed 2026-11-26 22:35:21 -05:00
1 parent e0296a1176
commit 2a97ecf163
5 files changed
+84

No files matched your search

@@ -13,6 +13,7 @@ object GameEnvironmentStore {
private const val TAG = "GameEnvironmentStore"
private const val SETTINGS = "game-environment.json"
private const val GUEST_FILE = "root/.config/droiddeck/game-environment.json"
private const val GAME_CORES_FILE = "root/.config/droiddeck/game-cores"
const val DXVK_CONFIG = "dxvkConfig"
const val DXVK_CONFIG_GAMES = "dxvkConfigGames"
const val GAME_DEBUG_LOGS = "gameDebugLogs"
@@ -138,6 +139,10 @@ object GameEnvironmentStore {
gameDebugLogsOverride ?: SessionPrefs.gameDebugLogsEffective(context),
)
write(File(LinuxRuntime.rootDir(context), GUEST_FILE), json.toString())
write(
File(LinuxRuntime.rootDir(context), GAME_CORES_FILE),
com.droiddeck.launcher.core.CpuCores.restrictionOrEmpty(SessionPrefs.gameCpus(context)) + "\n",
)
}
private fun write(file: File, text: String) {
@@ -959,6 +959,8 @@ object SessionPrefs {
fun setGameCpus(context: Context, list: String) {
prefs(context).edit().putString("gameCpus", list).apply()
runCatching { GameEnvironmentStore.publish(context) }
.onFailure { android.util.Log.e("GameEnvironment", "Could not update game environment", it) }
}
fun noXalia(context: Context): Boolean = prefs(context).getBoolean("noXalia", true)
@@ -36,9 +36,21 @@ class GameEnvironmentStoreTest {
context.getSharedPreferences("session", Context.MODE_PRIVATE).edit()
.remove("logs")
.remove("gameDebugLogsEnabled")
.remove("gameCpus")
.commit()
}
@Test fun gameCoresChangedInSettingsReachTheGuestAtOnce() {
val live = File(LinuxRuntime.rootDir(context), "root/.config/droiddeck/game-cores")
val all = com.droiddeck.launcher.core.CpuCores.all
SessionPrefs.setGameCpus(context, all.last().toString())
assertEquals("${all.last()}\n", live.readText())
SessionPrefs.setGameCpus(context, com.droiddeck.launcher.core.CpuCores.format(all.toSet()))
assertEquals("\n", live.readText())
}
@Test fun gameDebugLogsAreOffByDefault() {
assertFalse(SessionPrefs.gameDebugLogsEnabled(context))
@@ -227,6 +227,14 @@ dd_components() {
DD_GAME_CPUS_SETUP = """
dd_game_cpus() {
local live="${HOME:-/root}/.config/droiddeck/game-cores" cpus
if [ -f "$live" ] && cpus=$(<"$live") 2>/dev/null; then
case $cpus in *[!0-9,-]*) cpus=${DD_GAME_CPUS:-} ;; esac
if [ -z "$cpus" ] && [ -n "${DD_CLIENT_CPUS:-}" ]; then
cpus=$(nproc --all 2>/dev/null) && cpus=0-$((cpus - 1)) || cpus=
fi
if [ -n "$cpus" ]; then export DD_GAME_CPUS=$cpus; else unset DD_GAME_CPUS; fi
fi
[ -n "${DD_GAME_CPUS:-}" ] || return 0
command -v taskset >/dev/null 2>&1 || return 0
DD_TASKSET="taskset -c $DD_GAME_CPUS"
+57
View File
@@ -0,0 +1,57 @@
import os
from pathlib import Path
import runpy
import subprocess
import tempfile
import unittest
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
class LiveGameCpusTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
base = Path(self.temp.name)
self.home = base / "home"
(self.home / ".config/droiddeck").mkdir(parents=True)
tools = base / "tools"
tools.mkdir()
for name, body in (("taskset", "exit 0"), ("nproc", "echo 8")):
tool = tools / name
tool.write_text("#!/bin/sh\n" + body + "\n")
tool.chmod(0o755)
self.path = str(tools) + os.pathsep + os.environ.get("PATH", "")
def run_setup(self, live=None, **extra):
if live is not None:
(self.home / ".config/droiddeck/game-cores").write_text(live)
script = COMPAT["DD_GAME_CPUS_SETUP"] + '\ndd_game_cpus\necho "taskset=${DD_TASKSET:-}"\necho "cpus=${DD_GAME_CPUS-unset}"\n'
env = {key: value for key, value in os.environ.items() if not key.startswith("DD_")}
env.update(HOME=str(self.home), PATH=self.path, **extra)
result = subprocess.run(["bash", "-c", script], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
def test_a_change_made_during_the_session_wins_over_the_session_value(self):
self.assertEqual(self.run_setup("6,7\n", DD_GAME_CPUS="3,4,5,6,7"),
["taskset=taskset -c 6,7", "cpus=6,7"])
def test_every_core_chosen_during_the_session_drops_the_session_pin(self):
self.assertEqual(self.run_setup("\n", DD_GAME_CPUS="3,4,5,6,7"), ["taskset=", "cpus=unset"])
def test_every_core_with_a_pinned_client_still_frees_the_game_from_the_client_cores(self):
self.assertEqual(self.run_setup("\n", DD_GAME_CPUS="0-7", DD_CLIENT_CPUS="0"),
["taskset=taskset -c 0-7", "cpus=0-7"])
def test_without_the_live_file_the_session_value_is_used(self):
self.assertEqual(self.run_setup(DD_GAME_CPUS="3,4,5,6,7"),
["taskset=taskset -c 3,4,5,6,7", "cpus=3,4,5,6,7"])
self.assertEqual(self.run_setup(), ["taskset=", "cpus=unset"])
def test_an_unreadable_value_keeps_the_session_value(self):
self.assertEqual(self.run_setup("3;rm\n", DD_GAME_CPUS="4,5"), ["taskset=taskset -c 4,5", "cpus=4,5"])
if __name__ == "__main__":
unittest.main()