Wait for Steam shortcut overviews before cold launches (#758)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-14 00:55:04 -04:00
1 parent 0988cdc43a
commit 0c3444afbc
4 files changed
+208 -3

No files matched your search

@@ -477,6 +477,55 @@ def steam_selection(agent_dir, timeout=5):
return {"appId": int(value)}
def steam_shortcut_app_id(game_id):
"""Return the 32-bit app id in Steam's shortcut CGameID form, or None for other ids.
DroidDeck's shortcut IDs are `(appid << 32) | 0x02000000`. The URL still needs that full
CGameID for RunGame; the app-details API separately needs the unsigned 32-bit app id.
"""
if not isinstance(game_id, str) or not game_id.isascii() or not game_id.isdigit():
return None
try:
game_id_value = int(game_id)
except ValueError:
return None
if str(game_id_value) != game_id or not 0 < game_id_value <= 0xFFFFFFFFFFFFFFFF:
return None
if game_id_value <= 0xFFFFFFFF or game_id_value & 0xFFFFFFFF != 0x02000000:
return None
app_id = game_id_value >> 32
return app_id if 0 < app_id <= 0xFFFFFFFF else None
def wait_for_steam_shortcut_overview(agent_dir, game_id, timeout=45):
"""Wait until Steam can map a shortcut CGameID to its 32-bit app overview."""
app_id = steam_shortcut_app_id(game_id)
if app_id is None:
return {"supported": False, "ready": False}
timeout = request_timeout({"timeout": timeout}, 45)
deadline = time.monotonic() + timeout
expression = """(() => {
const store = globalThis.appStore;
if (typeof store?.GetAppOverviewByGameID !== 'function') return null;
const overview = store.GetAppOverviewByGameID(%s);
return overview == null ? null : String(overview.appid);
})()""" % json.dumps(game_id)
while True:
remaining = deadline - time.monotonic()
if remaining <= 0:
break
try:
result = cdp_eval(agent_dir, expression, await_promise=False,
timeout=min(5, max(0.25, remaining)))
if result.get("value") == str(app_id):
return {"supported": True, "ready": True, "appId": app_id}
except AgentError as error:
if error.code not in ("NO_DEVTOOLS", "DEVTOOLS_UNREACHABLE", "NO_TARGET", "TIMEOUT"):
raise
time.sleep(min(0.25, max(0, deadline - time.monotonic())))
raise AgentError("STEAM_OVERVIEW_TIMEOUT", "Steam did not load shortcut app overview %d" % app_id)
def game_pids(app_id):
"""Our processes started for this Steam app (Steam sets SteamAppId / SteamGameId in their
@@ -740,6 +789,21 @@ def main(argv):
if not base:
print("BL_LAUNCH_DIR is not set", file=sys.stderr)
return 2
if argv and argv[0] == "--wait-steam-shortcut-overview":
if len(argv) not in (2, 3):
print("usage: droiddeck-agent --wait-steam-shortcut-overview <cgameid> [timeout-seconds]", file=sys.stderr)
return 2
timeout = argv[2] if len(argv) == 3 else 45
try:
prepared = wait_for_steam_shortcut_overview(Path(base) / "agent", argv[1], timeout)
except (AgentError, OSError, ValueError) as error:
print("droiddeck-agent: shortcut overview was not ready: %s" % error, file=sys.stderr)
return 1
if not prepared["supported"]:
print("droiddeck-agent: id is not a DroidDeck shortcut CGameID")
return 3
print("droiddeck-agent: Steam overview is ready for shortcut app %d" % prepared["appId"])
return 0
serve(Path(base) / "agent", focus="--no-focus" not in argv)
return 0
@@ -571,13 +571,28 @@ case $mode in
if [ -n "$_bl_held" ]; then
set -- "${_bl_rest[@]}"
(
_bl_launch_ready=
_bl_end=$((SECONDS + 120))
until [ "$(xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p')" = 769 ] || [ "$SECONDS" -ge "$_bl_end" ]; do
sleep 1
done
sleep 4
echo "== steam: interface up; launching the requested game $_bl_held"
printf '%s\n' "$_bl_held" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
if /usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$_bl_held" 45; then
echo "== steam: shortcut overview ready; launching the requested game $_bl_held"
_bl_launch_ready=1
else
_bl_overview_status=$?
if [ "$_bl_overview_status" -eq 3 ]; then
echo "== steam: not a shortcut CGameID; keeping the existing launch path"
sleep 4
_bl_launch_ready=1
else
echo "== steam: expected shortcut overview did not become ready; holding the launch URL"
fi
fi
if [ "$_bl_launch_ready" = 1 ]; then
echo "== steam: interface up; launching the requested game $_bl_held"
printf '%s\n' "$_bl_held" > "$BL_LAUNCH_DIR/steam-game.tmp" && mv -f "$BL_LAUNCH_DIR/steam-game.tmp" "$BL_LAUNCH_DIR/steam-game"
fi
) &
fi
fi