mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 05:16:01 +00:00
fix(steam): the last change to a game's compatibility tool wins
A game's tool can be chosen in DroidDeck (per-game Proton) and in Steam's game properties. When they disagreed, DroidDeck always put its own choice back: the live helper within a second of the change, and again at every session start. Resetting the game's DroidDeck profile made it worse - it saved "use the default" (null), which was then forced onto the game. A DroidDeck choice is now applied once, and the client's later pick stands: a pick of one of DroidDeck's Protons becomes the DroidDeck choice too, any other pick (FEX, a Steam Linux Runtime, clearing the forced tool) ends it. "Use the default" and a profile reset are applied once and then dropped, so the game follows the default like one DroidDeck never touched. What was applied is kept in state.json (games_applied); choices an earlier build already applied count as applied. games.json is rewritten only if the app did not replace it meanwhile. An x86-only Proton picked in Steam is still replaced, since it cannot start on the phone.
This commit is contained in:
1 parent
22eac0831d
commit
663da2948c
3 files changed
+187
-10
No files matched your search
@@ -583,9 +583,8 @@ class Helper:
|
||||
picked = COMPAT["picked_apps"](state)
|
||||
runnable = {t["name"].lower() for t in live}
|
||||
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, 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"])
|
||||
asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
|
||||
apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
|
||||
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
|
||||
refused = set(apps) - set(current)
|
||||
refused_native = native_choices & refused
|
||||
@@ -597,7 +596,6 @@ class Helper:
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = prior_auto
|
||||
native_choices -= refused
|
||||
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
|
||||
current["0"] = top["selected"]
|
||||
native = COMPAT["native_targets"](self.steam_root, apps)
|
||||
raw_mapping = COMPAT["read_config_mapping"](
|
||||
@@ -619,6 +617,10 @@ class Helper:
|
||||
current[app] = ""
|
||||
elif not current.get(app):
|
||||
current.pop(app, None)
|
||||
# The client's pick of a tool the app chose for a game wins once the app's choice was applied.
|
||||
requests = COMPAT["settled_game_requests"](state, current, catalog)
|
||||
overrides = COMPAT["requested_games"](requests, catalog, [t["name"] for t in live])
|
||||
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
|
||||
changes, auto = COMPAT["plan_mapping"](
|
||||
current, installed, [t["name"] for t in live], default,
|
||||
COMPAT["followers"](state, current), native, picks, overrides,
|
||||
@@ -630,7 +632,8 @@ 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,
|
||||
games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
|
||||
state.pop("native", None)
|
||||
if waiting:
|
||||
state["pending"] = wanted
|
||||
|
||||
@@ -1113,10 +1113,99 @@ def requested_tool(request, catalog):
|
||||
|
||||
|
||||
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"]
|
||||
return read_game_requests(directory)[0]
|
||||
|
||||
|
||||
def read_game_requests(directory=None):
|
||||
"""The app's per-game Proton choices, and the file's text so a rewrite can tell the app wrote it since."""
|
||||
try:
|
||||
with open(state_path("games.json", directory), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
value = json.loads(text)
|
||||
except (OSError, ValueError):
|
||||
return {}, None
|
||||
if not isinstance(value, dict) or value.get("version") != 1 or not isinstance(value.get("games"), dict):
|
||||
return {}, text
|
||||
return value["games"], text
|
||||
|
||||
|
||||
def write_game_requests(requests, original, directory=None):
|
||||
"""Rewrites games.json unless the app replaced it after it was read; that newer choice wins."""
|
||||
path = state_path("games.json", directory)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
if f.read() != original:
|
||||
return False
|
||||
except OSError:
|
||||
if original is not None:
|
||||
return False
|
||||
return write_json(path, {"version": 1, "games": requests})
|
||||
|
||||
|
||||
def valid_game_request(app, request):
|
||||
return (isinstance(app, str) and re.fullmatch(r"[1-9][0-9]*", app) is not None and int(app) <= 0xFFFFFFFF and
|
||||
(request is None or isinstance(request, dict) and isinstance(request.get("dir"), str) and
|
||||
request["dir"] != "" and isinstance(request.get("valve"), bool)))
|
||||
|
||||
|
||||
def settle_game_requests(requests, state, current, catalog, missing_is_cleared=False):
|
||||
"""Whichever side changed a game's tool last wins. A choice the app makes is applied once; after
|
||||
that the client's own pick stands: a pick of one of our Protons becomes the app's choice too, any
|
||||
other pick (FEX, a Steam Linux Runtime, clearing the forced tool) ends the app's choice. "Use the
|
||||
default" (null, also what a profile reset writes) is applied once and then dropped, so the game
|
||||
follows the default like one the app never touched. Returns the new requests and whether they changed."""
|
||||
recorded = state.get("games_applied")
|
||||
if isinstance(recorded, dict):
|
||||
applied = dict(recorded)
|
||||
else:
|
||||
# Builds before this one kept no record but had already applied every choice they found; a
|
||||
# first start has applied nothing yet.
|
||||
applied = dict(requests) if "tools" in state else {}
|
||||
by_name = {t["name"]: t for t in catalog}
|
||||
out = dict(requests)
|
||||
for app, request in requests.items():
|
||||
if not valid_game_request(app, request) or app not in applied or applied[app] != request:
|
||||
continue
|
||||
if request is None:
|
||||
del out[app]
|
||||
continue
|
||||
wanted = requested_tool(request, catalog)
|
||||
if wanted is None:
|
||||
continue
|
||||
if app in current:
|
||||
picked = current[app]
|
||||
elif missing_is_cleared:
|
||||
picked = ""
|
||||
else:
|
||||
continue
|
||||
if picked == wanted:
|
||||
continue
|
||||
tool = by_name.get(picked)
|
||||
if tool and tool["dir"]:
|
||||
out[app] = {"valve": tool["valve"], "dir": tool["dir"]}
|
||||
else:
|
||||
del out[app]
|
||||
return out, out != requests
|
||||
|
||||
|
||||
def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
|
||||
"""Reads the app's choices, settles them against the client's picks and stores the result. When the
|
||||
app rewrote the file meanwhile, its newer choices are settled again; they are never overwritten."""
|
||||
for _ in range(2):
|
||||
requests, text = read_game_requests(directory)
|
||||
settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
|
||||
if not moved or write_game_requests(settled, text, directory):
|
||||
return settled
|
||||
return settled
|
||||
|
||||
|
||||
def applied_game_requests(requests, overrides, state):
|
||||
"""What the app asked for that is now in the mapping; a tool not installed yet stays unapplied."""
|
||||
recorded = state.get("games_applied")
|
||||
before = recorded if isinstance(recorded, dict) else {}
|
||||
return {app: request if overrides.get(app) is not DEFERRED_GAME_TOOL else before.get(app)
|
||||
for app, request in requests.items() if app in overrides and
|
||||
(overrides.get(app) is not DEFERRED_GAME_TOOL or app in before)}
|
||||
|
||||
|
||||
def requested_games(requests, catalog, runnable=None):
|
||||
@@ -1306,7 +1395,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)))
|
||||
overrides = requested_games(game_requests(directory), catalog)
|
||||
# With the client stopped, config.vdf is what it last kept: an app missing from it has no forced tool.
|
||||
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
|
||||
overrides = requested_games(requests, catalog)
|
||||
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
|
||||
native_choices = state.get("native_choices", ())
|
||||
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
|
||||
@@ -1325,6 +1416,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
|
||||
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
|
||||
state["picked"] = picked_after(current, changes)
|
||||
state["games_applied"] = applied_game_requests(requests, overrides, state)
|
||||
state.pop("native", None)
|
||||
state["tools"] = catalog
|
||||
state.setdefault("default", default)
|
||||
|
||||
Reference in new issue
Block a user