Keep the shortcut settings changed in Steam (#393)

Steam saves a shortcut's Properties to shortcuts.vdf as soon as they
change and keeps its appid. The session rewrote every added game's entry
from the app's list before and after each client run, keeping only the
launch options, so a Target or Start In set in Steam, a new name or icon,
the hidden and overlay switches, the last played time and Steam's sort
name were all put back at the next exit.

droiddeck-steam-shortcuts now merges instead: an entry keeps every field
Steam has, and the app's exe is written only where the app changed it.
What the app last asked for and what Steam then had are recorded beside
shortcuts.vdf (.droiddeck-shortcuts.json). A Target changed in Steam to a
file inside the game's folder becomes the exe chosen in Steam > Settings >
Games, and a later pick there replaces it in Steam, so both show the same
exe. The appid now stays with the folder, so changing the exe no longer
turns the game into a new one with a new prefix, playtime and launch
options. A game whose folder is missing is set aside with its settings
and comes back with them. The exit-time merge runs before Steam's logs
are copied.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-07 09:32:15 -04:00
1 parent 6ee8866599
commit 2a0512d19d
7 files changed
+466 -37

No files matched your search

@@ -839,13 +839,13 @@ BUSCONF
-cef-use-gl=angle -cef-use-angle=vulkan "$@"
rc=$?
echo "== steam exited rc=$rc"
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
fi
collect_steam_logs
if [ -f "$HOME/.config/droiddeck/fex-wanted" ] && [ -x /usr/local/bin/droiddeck-fex ]; then
/usr/local/bin/droiddeck-fex status >/dev/null 2>&1 || true
fi
if [ -n "${BL_ADDED_GAMES:-}" ] && [ -f "$BL_ADDED_GAMES" ]; then
droiddeck-steam-shortcuts "$steam_root" "$BL_ADDED_GAMES" || true
fi
if [ -f "$HOME/.bl-stop-requested" ]; then
rm -f "$HOME/.bl-stop-requested" "$HOME/.bl-restart-once"
break
@@ -120,6 +120,114 @@ def shortcut(game, launch_options=""):
}
RECORD = ".droiddeck-shortcuts.json"
AWAY_LIMIT = 256
FIELDS = ("AppName", "Exe", "StartDir", "icon")
def unquoted(value):
return value.strip().strip('"') if isinstance(value, str) else ""
def read_record(path):
try:
with open(path, encoding="utf-8") as f:
record = json.load(f)
except (OSError, ValueError):
record = {}
if not isinstance(record, dict):
record = {}
games, away = record.get("games"), record.get("away")
return {
"games": {k: v for k, v in games.items() if isinstance(v, dict)} if isinstance(games, dict) else {},
"away": {k: v for k, v in away.items() if isinstance(v, dict) and isinstance(v.get("entry"), dict)} if isinstance(away, dict) else {},
}
def merge(fresh, current, state, seen):
state = state if isinstance(state, dict) else {}
rev = state.get("rev") if isinstance(state.get("rev"), int) else 0
if current is None:
return fresh, rev
base = state.get("app") if isinstance(state.get("app"), dict) else {field: current.get(field) for field in FIELDS}
before = state.get("steam") if isinstance(state.get("steam"), dict) else {"Exe": current.get("Exe")}
if unquoted(current.get("Exe")) != unquoted(before.get("Exe")):
rev += 1
entry = dict(current)
entry["appid"] = fresh["appid"]
exe = unquoted(fresh["Exe"])
if exe != unquoted(current.get("Exe")) and (exe != unquoted(base.get("Exe")) or seen == rev):
entry["Exe"], entry["StartDir"] = fresh["Exe"], fresh["StartDir"]
for field in ("AppName", "icon"):
if current.get(field) == base.get(field):
entry[field] = fresh[field]
tags = dict(current["tags"]) if isinstance(current.get("tags"), dict) else {}
if TAG not in tags.values():
slot = 0
while str(slot) in tags:
slot += 1
tags[str(slot)] = TAG
entry["tags"] = tags
for key, value in fresh.items():
entry.setdefault(key, value)
return entry, rev
def reconcile(existing, wanted, seen, record):
games, away = record["games"], dict(record["away"])
kept, ours, placed = [], [], {}
for value in existing.values():
if not isinstance(value, dict):
continue
tags = value.get("tags")
if not isinstance(tags, dict) or TAG not in tags.values():
kept.append(value)
continue
appid = value.get("appid")
if not isinstance(appid, int) or appid in placed:
continue
key = str(appid & 0xFFFFFFFF)
fresh = wanted.get(appid)
if fresh is None:
away.pop(key, None)
away[key] = {"entry": value, "state": games.get(key)}
continue
entry, rev = merge(fresh, value, games.get(key), seen.get(appid, 0))
placed[appid] = (len(ours), rev)
ours.append(entry)
for appid, fresh in wanted.items():
if appid in placed:
continue
key = str(appid & 0xFFFFFFFF)
stashed = away.get(key)
if stashed:
entry, rev = merge(fresh, stashed["entry"], stashed.get("state"), seen.get(appid, 0))
else:
entry, rev = merge(fresh, None, games.get(key), seen.get(appid, 0))
placed[appid] = (len(ours), rev)
ours.append(entry)
for appid in placed:
away.pop(str(appid & 0xFFFFFFFF), None)
while len(away) > AWAY_LIMIT:
away.pop(next(iter(away)))
state = {}
for appid, (index, rev) in placed.items():
entry = ours[index]
state[str(appid & 0xFFFFFFFF)] = {
"app": {field: wanted[appid][field] for field in FIELDS},
"steam": {"Exe": entry.get("Exe", ""), "StartDir": entry.get("StartDir", "")},
"rev": rev,
}
return kept, ours, {"games": state, "away": away}
def save_record(path, record):
tmp = path + ".droiddeck"
with open(tmp, "w", encoding="utf-8") as f:
json.dump(record, f)
os.replace(tmp, path)
ART_MANIFEST = ".droiddeck-art.json"
# listing key -> the client's grid file suffix: <appid>p = portrait capsule, <appid> = header,
# <appid>_hero, <appid>_logo.
@@ -208,27 +316,21 @@ def main():
routing = importlib.util.module_from_spec(spec)
loader.exec_module(routing)
games, routes = routing.route(steam_root, acct, games)
# Steam saves Big Picture's per-shortcut launch options in shortcuts.vdf. Keep them when
# refreshing our entries, keyed by the appid that stays stable across session starts.
managed = {
v.get("appid"): v for v in existing.values()
if isinstance(v, dict) and TAG in (v.get("tags") or {}).values()
}
kept = [v for v in existing.values() if isinstance(v, dict) and TAG not in (v.get("tags") or {}).values()]
ours = []
wanted, seen = {}, {}
for game in games:
if not game.get("exe") or not game.get("name"):
continue
entry = shortcut(game)
previous = managed.get(entry["appid"])
if previous and isinstance(previous.get("LaunchOptions"), str):
entry["LaunchOptions"] = previous["LaunchOptions"]
ours.append(entry)
if game.get("exe") and game.get("name"):
entry = shortcut(game)
if entry["appid"] not in wanted:
wanted[entry["appid"]] = entry
seen[entry["appid"]] = game["seen"] if isinstance(game.get("seen"), int) else 0
record_path = os.path.join(config, RECORD)
kept, ours, record = reconcile(existing, wanted, seen, read_record(record_path))
entries = {str(i): v for i, v in enumerate(kept + ours)}
tmp = path + ".droiddeck"
with open(tmp, "wb") as f:
f.write(write({"shortcuts": entries}))
os.replace(tmp, path)
save_record(record_path, record)
print("droiddeck-steam-shortcuts: %d added game(s) written, %d of the client's own kept" % (len(ours), len(kept)))
install_art(acct, [g for g in games if g.get("exe") and g.get("name")])
# Each added game runs under the ARM64 Proton: the compat registrar's own mapping writer.