fix(proton): an installed DroidDeck-Proton replaces a Proton Experimental default nobody picked, and added shortcuts follow it (#2266)

* fix(proton): an installed DroidDeck-Proton replaces a Proton Experimental default nobody picked, and added shortcuts follow the default

* test: an owned shortcut left on the previous default follows a default change
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-08 06:07:53 -05:00
1 parent 15baa296bb
commit 39469e6e8f
5 files changed
+136 -22

No files matched your search

@@ -1078,7 +1078,8 @@ class Helper:
wanted = COMPAT["requested_tool"](request, catalog)
newer = isinstance(request.get("seq"), int) and request["seq"] > int(state.get("applied", 0) or 0)
waiting = newer and wanted is not None and wanted not in self.known
default, state = COMPAT["choose_default"](top["selected"], state, request, live, apply_request=not waiting)
default, state = COMPAT["choose_default"](top["selected"], state, request, catalog, apply_request=not waiting,
listed=[t["name"] for t in live])
installed = COMPAT["installed_apps"](self.steam_root)
self.installed = installed
picks = COMPAT["valve_picks"](self.steam_root)
@@ -1137,7 +1138,7 @@ class Helper:
state.update(
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
native_choices=sorted(refused_native | {app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]}),
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True,
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True, written=default,
games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
state.pop("native", None)
if waiting:
@@ -355,8 +355,9 @@ def main():
"linux_tool": "droiddeck-direct"}
else:
protect = compat.adopt_extras(tools)
used = compat.register_default(cfg, apps=[str(int(g["appid"]) & 0xFFFFFFFF) for g in games if g.get("exe") and not g.get("native")] + [str(appid) for appid in set(routes.values())],
protect=protect, **own)
owned = [str(int(g["appid"]) & 0xFFFFFFFF) for g in games if g.get("exe") and not g.get("native")]
used = compat.register_default(cfg, apps=owned + [str(appid) for appid in set(routes.values())],
protect=protect, owned=owned, **own)
print("droiddeck-steam-shortcuts: mapped them to %s" % used)
except Exception as e:
print("droiddeck-steam-shortcuts: compat mapping skipped (%s)" % e)
@@ -1307,9 +1307,13 @@ def now_ms():
return int(time.time() * 1000)
def choose_default(steam_default, state, request, catalog, adopt_steam=True, apply_request=True, now=None):
def choose_default(steam_default, state, request, catalog, adopt_steam=True, apply_request=True, now=None, listed=None):
state = dict(state)
names = [t["name"] for t in catalog]
listed = names if listed is None else listed
if "written" not in state and state.get("source") == "steam":
state["source"] = "fallback"
hidden = state.get("default") in names and state.get("default") not in listed
seq = request.get("seq")
seq = seq if isinstance(seq, int) else 0
if apply_request and seq > int(state.get("applied", 0) or 0):
@@ -1321,11 +1325,12 @@ def choose_default(steam_default, state, request, catalog, adopt_steam=True, app
else:
print("steam-compatibility: the app asked for %s, which is not installed; kept %s" % (
request.get("name") or request.get("dir"), state.get("default") or TOOL))
elif adopt_steam and steam_default in names and steam_default != state.get("default"):
elif adopt_steam and steam_default in names and not hidden and steam_default not in (
state.get("default"), state.get("written", state.get("default") or TOOL)):
state.update(default=steam_default, seq=now or now_ms(), source="steam")
if state.get("default") not in names:
state["default"] = TOOL
return state["default"], state
if state.get("default") not in names and state.get("default") != TOOL:
state.update(default=TOOL, source="fallback")
return state["default"] if state["default"] in listed else TOOL, state
def mapping_block(tokens):
@@ -1482,7 +1487,7 @@ def live_helper_running(directory=None):
def register_default(config_path, apps=(), protect=(), default=None, catalog=None, directory=None, settle=False, picks=(),
linux_tool=FEX_TOOL):
linux_tool=FEX_TOOL, owned=None):
with locked(directory):
state = read_json(state_path("state.json", directory))
with open(config_path, encoding="utf-8", errors="replace") as f:
@@ -1497,18 +1502,24 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
dict(protect) if isinstance(protect, dict) else {name: name for name in protect})
names = [t["name"] for t in catalog]
newest, gone = own_proton_moves(state, catalog)
previous, applied, chosen = state.get("default"), state.get("applied"), state.get("seq")
previous = state.get("default")
if owned is not None:
auto = followers(state, current)
known = {app for app in state.get("owned", ()) if isinstance(app, str)} if isinstance(state.get("owned"), list) else set()
pinned = {app: current[app] for app in set(owned) - known
if current.get(app) in {TOOL, previous} | gone and app not in auto}
if pinned and isinstance(auto, dict):
state["auto"] = dict(auto, **pinned)
state["owned"] = sorted(set(owned), key=app_order)
if default is None:
if settle:
default, state = choose_default(current.get("0", ""), state, read_json(state_path("request.json", directory)), catalog)
else:
default = state.get("default") if state.get("default") in names else TOOL
if settle and newest and default == TOOL and state.get("applied") == applied and state.get("seq") == chosen and (
previous in gone or not state.get("own_proton")):
if settle and newest and default == TOOL and state.get("source") not in ("app", "steam"):
default = newest
state.update(default=newest, seq=now_ms(), source="update")
if settle and newest:
state["own_proton"] = True
state.pop("own_proton", None)
if newest:
replacements = {app: newest for app, name in current.items() if app != "0" and name in gone}
set_mappings(tokens, mapping, replacements)
@@ -1539,6 +1550,8 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
state.pop("native", None)
state["tools"] = catalog
state.setdefault("default", default)
if settle:
state["written"] = default
write_json(state_path("state.json", directory), state)
return default
+86 -7
View File
@@ -3,6 +3,7 @@ import runpy
import tempfile
import unittest
from pathlib import Path
from unittest import mock
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
@@ -11,6 +12,8 @@ OLD = {"name": "DroidDeck-Proton-11-11.2", "display": "DroidDeck-Proton 11-11.2"
NEW = {"name": "DroidDeck-Proton-11-11.4", "display": "DroidDeck-Proton 11-11.4", "dir": "DroidDeck-Proton 11-11.4", "valve": False}
VALVE = {"name": TOOL, "display": "Proton Experimental ARM64", "dir": "Proton - Experimental (ARM64)", "valve": True}
GE = {"name": "GE-Proton11-7", "display": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False}
GE10 = {"name": "GE-Proton10-3", "display": "GE-Proton10-3", "dir": "GE-Proton10-3", "valve": False}
NEWER = {"name": "DroidDeck-Proton-11-12.1", "display": "DroidDeck-Proton 11-12.1", "dir": "DroidDeck-Proton 11-12.1", "valve": False}
def config_text(entries):
@@ -19,15 +22,19 @@ def config_text(entries):
class DroidDeckProtonDefaultTest(unittest.TestCase):
def run_default(self, state, mapping, catalog, apps=(), request=None, settle=True):
def run_default(self, state, mapping, catalog, apps=(), request=None, settle=True, owned=None, games=None):
with tempfile.TemporaryDirectory() as tmp:
directory = Path(tmp)
(directory / "state.json").write_text(json.dumps(state))
if request is not None:
(directory / "request.json").write_text(json.dumps(request))
if games is not None:
(directory / "games.json").write_text(json.dumps({"version": 1, "games": games}))
config = directory / "config.vdf"
config.write_text(config_text(mapping))
default = COMPAT["register_default"](str(config), list(apps), catalog=catalog, directory=str(directory), settle=settle)
with mock.patch.dict(COMPAT["register_default"].__globals__, steam_running=lambda: False):
default = COMPAT["register_default"](str(config), list(apps), catalog=catalog, directory=str(directory),
settle=settle, owned=owned)
return default, COMPAT["read_config_mapping"](str(config)), json.loads((directory / "state.json").read_text())
def test_a_replacement_seen_while_steam_runs_still_moves_the_default_later(self):
@@ -50,8 +57,7 @@ class DroidDeckProtonDefaultTest(unittest.TestCase):
{"default": TOOL, "auto": {"42": TOOL}}, [("0", TOOL), ("42", TOOL), ("43", TOOL)], [VALVE, NEW], ["42", "43"])
self.assertEqual(default, NEW["name"])
self.assertEqual(mapping, {"0": NEW["name"], "42": NEW["name"], "43": TOOL})
self.assertEqual(state["default"], NEW["name"])
self.assertTrue(state["own_proton"])
self.assertEqual((state["default"], state["source"], state["written"]), (NEW["name"], "update", NEW["name"]))
def test_a_default_picked_after_the_switch_is_kept(self):
default, mapping, state = self.run_default(
@@ -59,8 +65,7 @@ class DroidDeckProtonDefaultTest(unittest.TestCase):
[("0", NEW["name"])], [VALVE, NEW], request={"seq": 2, "valve": True, "dir": VALVE["dir"]})
self.assertEqual(default, TOOL)
self.assertEqual(mapping, {"0": TOOL})
default, mapping, state = self.run_default(
{"default": TOOL, "own_proton": True, "tools": [VALVE, NEW]}, [("0", TOOL)], [VALVE, NEW])
default, mapping, state = self.run_default(state, [("0", TOOL)], [VALVE, NEW])
self.assertEqual(default, TOOL)
self.assertEqual(mapping, {"0": TOOL})
@@ -75,7 +80,7 @@ class DroidDeckProtonDefaultTest(unittest.TestCase):
def test_a_replaced_build_does_not_override_a_valve_default(self):
default, mapping, _ = self.run_default(
{"default": TOOL, "own_proton": True, "tools": [VALVE, OLD]}, [("0", TOOL), ("43", OLD["name"])], [VALVE, NEW], ["43"])
{"default": TOOL, "source": "app", "written": TOOL, "tools": [VALVE, OLD]}, [("0", TOOL), ("43", OLD["name"])], [VALVE, NEW], ["43"])
self.assertEqual(default, TOOL)
self.assertEqual(mapping, {"0": TOOL, "43": NEW["name"]})
@@ -85,6 +90,80 @@ class DroidDeckProtonDefaultTest(unittest.TestCase):
self.assertEqual(mapping, {"0": TOOL})
self.assertNotIn("own_proton", state)
def test_a_fresh_state_with_steam_on_proton_experimental_moves_to_the_newest_build(self):
default, mapping, state = self.run_default({}, [("0", TOOL)], [VALVE, OLD, NEW])
self.assertEqual((default, mapping), (NEW["name"], {"0": NEW["name"]}))
default, mapping, state = self.run_default(state, [("0", NEW["name"])], [VALVE, OLD, NEW])
self.assertEqual((default, state["source"]), (NEW["name"], "update"))
def test_a_default_adopted_from_steam_by_an_earlier_build_recovers(self):
default, mapping, state = self.run_default(
{"default": TOOL, "source": "steam", "seq": 5, "own_proton": True, "tools": [VALVE, NEW]}, [("0", TOOL)], [VALVE, NEW])
self.assertEqual((default, mapping, state["source"]), (NEW["name"], {"0": NEW["name"]}, "update"))
self.assertNotIn("own_proton", state)
def test_a_request_applied_without_a_change_still_moves_to_the_newest_build(self):
for request in ({"seq": 5, "valve": True, "dir": VALVE["dir"]}, {"seq": 5, "valve": False, "dir": GE["dir"]}):
default, mapping, state = self.run_default({"default": TOOL, "applied": 1}, [("0", TOOL)], [VALVE, NEW], request=request)
self.assertEqual((default, mapping, state["applied"]), (NEW["name"], {"0": NEW["name"]}, 5))
def test_a_default_that_is_not_installed_falls_back_without_counting_as_a_pick(self):
default, mapping, state = self.run_default(
{"default": GE["name"], "source": "app", "seq": 9, "written": GE["name"]}, [("0", GE["name"])], [VALVE])
self.assertEqual((default, mapping), (TOOL, {"0": TOOL}))
self.assertEqual((state["source"], state["seq"]), ("fallback", 9))
default, _, state = self.run_default(state, [("0", TOOL)], [VALVE, NEW])
self.assertEqual((default, state["source"]), (NEW["name"], "update"))
def test_proton_experimental_asked_for_in_the_app_stays(self):
default, mapping, state = self.run_default(
{"default": NEW["name"], "written": NEW["name"], "applied": 1}, [("0", NEW["name"])], [VALVE, NEW],
request={"seq": 2, "valve": True, "dir": VALVE["dir"]})
self.assertEqual((default, state["source"]), (TOOL, "app"))
for catalog in ([VALVE, NEW], [VALVE, NEW, NEWER], [VALVE, NEWER]):
default, mapping, state = self.run_default(state, [("0", TOOL)], catalog)
self.assertEqual((default, mapping, state["source"]), (TOOL, {"0": TOOL}, "app"))
def test_proton_experimental_picked_in_steam_stays(self):
default, mapping, state = self.run_default(
{"default": NEW["name"], "written": NEW["name"], "source": "update"}, [("0", TOOL)], [VALVE, NEW])
self.assertEqual((default, state["source"], state["written"]), (TOOL, "steam", TOOL))
for catalog in ([VALVE, NEW], [VALVE, NEW, NEWER]):
default, mapping, state = self.run_default(state, [("0", TOOL)], catalog)
self.assertEqual((default, mapping, state["source"]), (TOOL, {"0": TOOL}, "steam"))
def test_steam_echoing_the_written_default_is_not_a_pick(self):
default, _, state = self.run_default(
{"default": NEW["name"], "written": TOOL, "source": "update"}, [("0", TOOL)], [VALVE, NEW])
self.assertEqual((default, state["source"]), (NEW["name"], "update"))
def test_a_default_the_running_client_does_not_list_is_kept(self):
state = {"default": NEW["name"], "written": NEW["name"], "seq": 1, "source": "update"}
default, state = COMPAT["choose_default"](TOOL, state, {}, [VALVE, NEW], listed=[TOOL])
self.assertEqual((default, state["default"], state["source"], state["seq"]), (TOOL, NEW["name"], "update", 1))
default, state = COMPAT["choose_default"](GE["name"], dict(state, written=TOOL), {}, [VALVE, NEW, GE])
self.assertEqual((default, state["source"]), (GE["name"], "steam"))
def test_owned_shortcuts_follow_the_default_and_explicit_picks_stay(self):
owned = ["3000000001", "3000000002", "3000000003", "3000000004"]
catalog = [VALVE, NEW, GE, GE10]
default, mapping, state = self.run_default(
{"default": NEW["name"], "written": NEW["name"], "source": "update", "auto": {}},
[("0", NEW["name"]), ("3000000001", NEW["name"]), ("3000000002", TOOL), ("3000000003", GE["name"]),
("3000000004", NEW["name"]), ("42", GE["name"]), ("44", NEW["name"])],
catalog, ["42", "44"] + owned, settle=False, owned=owned, games={"44": {"valve": False, "dir": GE["dir"]}})
self.assertEqual(mapping, {"0": NEW["name"], "3000000001": NEW["name"], "3000000002": NEW["name"],
"3000000003": GE["name"], "3000000004": NEW["name"], "42": GE["name"], "44": GE["name"]})
mapping["3000000001"] = TOOL
default, mapping, state = self.run_default(state, sorted(mapping.items()), catalog, ["42", "44"] + owned,
settle=False, owned=owned)
self.assertEqual(mapping["3000000001"], TOOL)
default, mapping, state = self.run_default(state, sorted(mapping.items()), catalog, ["42", "44"] + owned,
request={"seq": 1, "valve": False, "dir": GE10["dir"]})
self.assertEqual(default, GE10["name"])
self.assertEqual(mapping, {"0": GE10["name"], "3000000001": TOOL, "3000000002": GE10["name"],
"3000000003": GE["name"], "3000000004": GE10["name"], "42": GE["name"], "44": GE["name"]})
def test_the_newest_build_is_found_by_version(self):
newest, gone = COMPAT["own_proton_moves"]({"tools": [OLD]}, [dict(NEW, name="a", dir="DroidDeck-Proton 11-9.10"), dict(NEW, name="b", dir="DroidDeck-Proton 11-11.1")])
self.assertEqual(newest, "b")
+20
View File
@@ -749,6 +749,26 @@ class ReconcileTest(unittest.TestCase):
self.assertIn(entry % ("10", COMPAT["FEX_TOOL"]), " ".join(config.read_text().split()))
self.assertEqual(self.games(), {})
def test_our_default_the_client_does_not_list_survives_to_the_next_start(self):
build = "DroidDeck-Proton 11-11.4"
(self.steam / "compatibilitytools.d" / build).mkdir(parents=True)
(self.steam / "compatibilitytools.d" / build / COMPAT["EXTRA_WRAPPER"]).write_text("")
(self.state / "state.json").write_text(json.dumps({"default": build, "written": build, "source": "update", "auto": {"10": build}}))
page = FakePage({"0": TOOL, "10": build}, [TOOL, TOOL_11])
state = self.reconcile(page)
self.assertEqual((state["default"], state["source"], state["written"]), (build, "update", TOOL))
self.assertEqual(page.sets, [("10", TOOL), ("11", TOOL)])
config = self.steam / "config/config.vdf"
config.parent.mkdir(parents=True)
vdf = '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }'
entry = '"%s" { "name" "%s" "config" "" "priority" "250" }'
config.write_text(vdf % "".join(entry % (app, page.mapping[app]) for app in ("0", "10", "11")))
with mock.patch.dict(COMPAT["register_default"].__globals__, steam_running=lambda: False):
default = COMPAT["register_default"](str(config), ["10", "11"], catalog=COMPAT["tool_catalog"](str(self.steam)),
directory=str(self.state), settle=True)
self.assertEqual(default, build)
self.assertEqual(COMPAT["read_config_mapping"](str(config)), {"0": build, "10": build, "11": build})
def test_file_mode_defers_to_the_live_helper(self):
(self.state / "live.pid").write_text("%d\n" % os.getpid())
self.assertTrue(COMPAT["live_helper_running"]())