feat: add persistent per-game compatibility profiles (#449)

* feat(profiles): add persistent per-game compatibility profiles

* fix(profiles): show Windows component overrides

Include per-game Windows component selections in the resolved profile summary so the session overlay marks those games as custom and shows the selected components.

* fix(session): detect Proton games across runtime paths

* fix(profiles): select the active Gamescope game

* fix(profiles): improve per-game reset feedback

* fix(profiles): align session components with game overrides

* fix(session): prefer selected Steam game during refresh

* fix(session): resume profile following when reopening games

* chore: keep local dev testing outside the repository

* test(session): remove local dev package path

* fix(session): preserve profiles when refresh fails

* fix(session): reject empty game profile reset scope

* perf(session): cache drawer inventory by refresh revision

* fix(profiles): align game presets and profile reset behavior

* fix(profiles): preserve originals and normalize shortcut ids

* fix(profiles): keep editor scope stable after rebase

* fix(tests): host Compose tests in both build variants

* fix(profiles): recover interrupted component selection saves

---------

Co-authored-by: Kurt Himebauch <136133082+xXJSONDeruloXx@users.noreply.github.com>
This commit is contained in:
Juan MartíandKurt Himebauch authored and GitHub committed 2026-10-11 17:00:28 -04:00
1 parent 78fcb60fd5
commit 435beb7f19
46 files changed
+3501 -150

No files matched your search

@@ -453,6 +453,34 @@ def cdp_eval(agent_dir, expression, target=None, await_promise=True, timeout=15)
ws.close()
def steam_selection(agent_dir, timeout=5):
result = cdp_eval(
agent_dir,
"""(() => {
let node = document.activeElement;
while (node) {
for (const name of ["data-id", "data-appid"]) {
const value = node.getAttribute?.(name);
if (/^[1-9][0-9]{0,9}$/.test(value || "")) {
const appId = Number(value);
if (Number.isSafeInteger(appId) && appId <= 4294967295) return value;
}
}
node = node.parentElement;
}
return null;
})()""",
target="Steam Big Picture Mode",
timeout=timeout,
)
value = result.get("value")
if value is None:
return {"appId": None}
if not isinstance(value, str) or not value.isdigit() or not 0 < int(value) <= 4294967295:
raise AgentError("INVALID_SELECTION", "Steam returned an invalid selected app id")
return {"appId": int(value)}
# --- Game processes ------------------------------------------------------------------------------
def game_pids(app_id):
@@ -624,6 +652,8 @@ def handle(agent_dir, req):
raise AgentError("INVALID_REQUEST", "cdp eval needs an expression")
return cdp_eval(agent_dir, expression, req.get("target"), bool(req.get("awaitPromise", True)),
request_timeout(req, 15))
if kind == "steam-selection":
return steam_selection(agent_dir, request_timeout(req, 5))
if kind == "quit":
return quit_game(agent_dir, req.get("appId"), request_timeout(req, 15))
raise AgentError("UNKNOWN_REQUEST", "Unknown agent request '%s'" % kind)
@@ -168,7 +168,10 @@ def apply_config(env, config, app_id, fixes=None):
raise ValueError("invalid environment value")
# The app's texture filtering (Display page), as DXVK options appended after the profiles so
# a DXVK_CONFIG entry of the user's keeps its own.
dxvk = config.get("dxvkConfig")
game_dxvk = config.get("dxvkConfigGames", {})
if not isinstance(game_dxvk, dict):
raise ValueError("invalid game dxvk configuration")
dxvk = game_dxvk.get(app_id, config.get("dxvkConfig"))
if dxvk is not None:
if not isinstance(dxvk, str) or "\0" in dxvk or len(dxvk) > 8192:
raise ValueError("invalid dxvk configuration")
@@ -447,10 +447,15 @@ class Helper:
self.installed = installed
picks = COMPAT["valve_picks"](self.steam_root)
apps = sorted(set(installed) | set(picks) | set(state.get("auto", {})), key=COMPAT["app_order"])
overrides = COMPAT["requested_games"](
COMPAT["game_requests"](), catalog, [t["name"] for t in live])
apps = sorted(set(apps) | set(overrides), key=COMPAT["app_order"])
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
current["0"] = top["selected"]
native = COMPAT["native_targets"](self.steam_root, installed)
changes, auto = COMPAT["plan_mapping"](current, installed, [t["name"] for t in live], default, COMPAT["followers"](state, current), native, picks)
changes, auto = COMPAT["plan_mapping"](
current, installed, [t["name"] for t in live], default,
COMPAT["followers"](state, current), native, picks, overrides)
for app, tool in sorted(changes.items(), key=lambda item: COMPAT["app_order"](item[0])):
page.compat("set(%d, %s)" % (int(app), json.dumps(tool)))
say("%s -> %s" % ("default" if app == "0" else "app %s" % app, tool))
@@ -489,7 +494,7 @@ class Helper:
if self.page.ws in ready:
due = any(called(e, BINDING) for e in self.drain())
if (watcher in ready or watcher.fileno() < 0) and watcher.changed():
due = self.installed != COMPAT["installed_apps"](self.steam_root) or self.request_waiting()
due = True
if due:
time.sleep(0.3)
if watcher.fileno() >= 0 and select.select([watcher], [], [], 0)[0]:
@@ -519,7 +524,8 @@ def main():
say("no devtools port for this session; the client's mapping is kept through config.vdf")
return 0
os.makedirs(COMPAT["COMPAT_DIR"], exist_ok=True)
watcher = Watcher([COMPAT["state_path"]("request.json")] + [os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json")] +
[os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
# The client has its own SteamOS manager when started as SteamOS (droiddeck-session's Deck mode).
steamos = os.environ.get("BL_STEAMDECK") == "1" and os.environ.get("BL_STEAM_UI") != "desktop"
helper = Helper(steam_root, port, steamos)
@@ -92,10 +92,12 @@ TOOL_MANIFEST_VDF = """"manifest"
# relies on compatdata/0 itself. The launch-time check below is the protection instead.
# The Components page's choices, enforced in the one place every game launch passes: the app keeps
# desired.tsv (tool dir, Proton build, component, file, sha256, source copy) and an unpacked copy of
# each package in use. A file that no longer matches - whatever changed it - is put back before
# Proton starts. Only for the Proton build the choice was made for: after a Steam update the build
# differs and the Proton's own new files are left alone until the user chooses again.
# desired.tsv (scope, tool dir, Proton build, component, file, sha256, source copy) and an unpacked
# copy of each package in use. A game's rows replace General rows for that component. A `-` source
# removes a managed file absent from the selected package, so one game's package cannot leak into
# the next game. A file that no longer matches - whatever changed it - is put back before Proton
# starts. Only the matching Proton build is changed; after a Steam update the build differs and the
# Proton's own new files are left alone until the user chooses again.
# A store game (GOG, Epic, Amazon) is started through the launcher .bat DroidDeck wrote beside it.
# An Epic game needs a fresh sign-in code, which only the app can mint: droiddeck-store-launch asks
# for it and the app writes it into the game's folder, so a launch from the client's own Play
@@ -149,21 +151,56 @@ bl_components() {
[ "${verb:-}" = waitforexitandrun ] || return 0
case "${STEAM_COMPAT_DATA_PATH:-}" in ''|*/compatdata/0|*/compatdata/0/|*/compatdata/0-*) return 0 ;; esac
[ -f "$cm_list" ] || return 0
cm_app=${STEAM_COMPAT_DATA_PATH%/}
cm_app=${STEAM_COMPAT_DATA_PATH}
while [[ "$cm_app" == */ ]]; do cm_app=${cm_app%/}; done
cm_app=${cm_app##*/}
if [[ "$cm_app" =~ ^(-?)([0-9]+)$ ]]; then
cm_sign=${BASH_REMATCH[1]}
cm_digits=${BASH_REMATCH[2]}
while [[ ${#cm_digits} -gt 1 && "$cm_digits" == 0* ]]; do cm_digits=${cm_digits#0}; done
if [[ ${#cm_digits} -le 10 ]]; then
cm_app=$((10#$cm_digits))
[ "$cm_sign" = "-" ] && cm_app=$((-cm_app))
if (( cm_app >= -2147483648 && cm_app <= 4294967295 && cm_app != 0 )); then
(( cm_app < 0 )) && cm_app=$((cm_app + 4294967296))
else
cm_app=""
fi
else
cm_app=""
fi
else
cm_app=""
fi
if [ -z "$cm_app" ]; then
echo "droiddeck-proton: components: invalid game prefix, left as it is" >&2
return 0
fi
cm_tool=${base##*/}
cm_build=$(awk 'NR == 1 { print $2 }' "$base/version" 2>/dev/null)
cm_fixed=0
cm_checked=0
cm_selected=$(awk -F '\\t' -v app="$cm_app" -v tool="$cm_tool" -v build="$cm_build" '
$2 == tool && $3 == build {
rows[++count] = $0
scopes[count] = $1
comps[count] = $4
if ($1 == app) specific[$4] = 1
}
END {
for (i = 1; i <= count; i++)
if (scopes[i] == app || (scopes[i] == "*" && !specific[comps[i]])) print rows[i]
}
' "$cm_list")
# One sha256sum for every file: each program started here pays a dozen traced library lookups
# under the game's search path before it does anything.
local cm_rows=() cm_files=() row h p
local -A cm_sums=()
while IFS=$'\\t' read -r t want comp rel sum src; do
[ "$t" = "$cm_tool" ] && [ "$want" = "$cm_build" ] || continue
while IFS=$'\\t' read -r scope t want comp rel sum src; do
[ -n "$scope" ] || continue
cm_rows+=("$comp"$'\\t'"$rel"$'\\t'"$sum"$'\\t'"$src")
[ -f "$base/$rel" ] && cm_files+=("$base/$rel")
done < "$cm_list"
[ "$src" != "-" ] && [ -f "$base/$rel" ] && cm_files+=("$base/$rel")
done <<< "$cm_selected"
if [ ${#cm_files[@]} -gt 0 ]; then
while read -r h p; do cm_sums["$p"]=$h; done < <(sha256sum -- "${cm_files[@]}" 2>/dev/null)
fi
@@ -171,6 +208,10 @@ bl_components() {
IFS=$'\\t' read -r comp rel sum src <<< "$row"
cm_checked=$((cm_checked + 1))
f="$base/$rel"
if [ "$src" = "-" ]; then
if [ -e "$f" ]; then rm -f "$f" && cm_fixed=$((cm_fixed + 1)); fi
continue
fi
if [ -f "$f" ] && [ "${cm_sums[$f]:-}" = "$sum" ]; then continue; fi
if [ ! -f "$src" ]; then
echo "droiddeck-proton: components: $comp source missing ($src), left as it is" >&2
@@ -985,16 +1026,30 @@ def app_order(app):
return (len(app), app)
def plan_mapping(current, installed, runnable, default, auto, native=None, picks=()):
DEFERRED_GAME_TOOL = object()
def plan_mapping(current, installed, runnable, default, auto, native=None, picks=(), overrides=None):
runnable = {n.lower() for n in runnable}
installed = set(installed)
picks = set(picks)
native = native or {}
overrides = overrides or {}
changes, kept = {}, {}
if current.get("0", "") != default:
changes["0"] = default
for app in sorted((set(current) | installed | picks | set(auto)) - {"0"}, key=app_order):
for app in sorted((set(current) | installed | picks | set(auto) | set(overrides)) - {"0"}, key=app_order):
name = current.get(app, "")
if app in overrides:
target = overrides[app]
if target is DEFERRED_GAME_TOOL:
continue
target = target or default
if name != target:
changes[app] = target
if overrides[app] is None:
kept[app] = target
continue
mine = auto.get(app)
target = native.get(app, default)
stale = unrunnable(name, runnable) or (app in native and linux_runtime_tool(name))
@@ -1053,6 +1108,34 @@ def requested_tool(request, catalog):
return None
def game_requests(directory=None):
value = read_json(state_path("games.json", directory))
if value.get("version") != 1 or not isinstance(value.get("games"), dict):
return {}
return value["games"]
def requested_games(requests, catalog, runnable=None):
"""App id -> requested tool, None for inherit, or DEFERRED_GAME_TOOL while unavailable."""
runnable = None if runnable is None else set(runnable)
resolved = {}
for app, request in requests.items():
if not isinstance(app, str) or not re.fullmatch(r"[1-9][0-9]*", app) or int(app) > 0xFFFFFFFF:
continue
if request is None:
resolved[app] = None
continue
if (not isinstance(request, dict) or not isinstance(request.get("dir"), str) or
not request["dir"] or not isinstance(request.get("valve"), bool)):
continue
tool = requested_tool(request, catalog)
if tool is None or runnable is not None and tool not in runnable:
resolved[app] = DEFERRED_GAME_TOOL
else:
resolved[app] = tool
return resolved
def now_ms():
import time
return int(time.time() * 1000)
@@ -1174,7 +1257,9 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
else:
default = state.get("default") if state.get("default") in names else TOOL
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
changes, auto = plan_mapping(current, apps, names, default, followers(state, current), native_targets(steam_root, apps), picks)
overrides = requested_games(game_requests(directory), catalog)
changes, auto = plan_mapping(
current, apps, names, default, followers(state, current), native_targets(steam_root, apps), picks, overrides)
for app, tool in changes.items():
set_mapping(tokens, mapping, app, tool)
text = serialize(tokens)