mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0c6aed9fac |
No files matched your search
@@ -992,11 +992,22 @@ def steam_clear_pending_interstitial(agent_dir, app_id):
|
||||
if (typeof apps?.GetActiveGameActions !== 'function' || typeof apps.ContinueGameAction !== 'function') return false;
|
||||
const active = await apps.GetActiveGameActions() || [];
|
||||
for (const action of active) {
|
||||
const appid = String(action?.strAppID ?? action?.gameid ?? action?.nAppID ?? '');
|
||||
if (appid === %s && action?.strTaskName === 'ShowInterstitials') {
|
||||
apps.ContinueGameAction(action.nGameActionID, appid, 'ShowInterstitials');
|
||||
return true;
|
||||
const gameid = String(action?.strAppID ?? action?.gameid ?? action?.nAppID ?? '');
|
||||
if (!/^[0-9]+$/.test(gameid)) continue;
|
||||
const numericId = BigInt(gameid);
|
||||
const appid = String(numericId > 0xffffffffn ? numericId >> 32n : numericId);
|
||||
if (appid !== %s || action?.strActionName !== 'LaunchApp' || action?.bWaitingForUI !== true) continue;
|
||||
const task = action.strTaskName;
|
||||
let response;
|
||||
if (task === 'ShowLaunchOption') {
|
||||
response = String(Number.isInteger(action.nLaunchOption) && action.nLaunchOption >= 0 ? action.nLaunchOption : 0);
|
||||
} else if (task === 'ShowInterstitials' || task === 'CreatingProcess') {
|
||||
response = task;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
apps.ContinueGameAction(action.nGameActionID, response);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
})()""" % json.dumps(app_id)
|
||||
|
||||
@@ -1308,9 +1308,9 @@ case $mode in
|
||||
done < <(xprop -spy -root "${atoms[@]}" 2>/dev/null)
|
||||
) &
|
||||
steam_hold_launch() {
|
||||
local game=$1 shortcut= waited=0 status=0
|
||||
local game=$1 appid=$1 shortcut= waited=0 status=0
|
||||
_dd_focused() { xprop -root GAMESCOPE_FOCUSED_APP 2>/dev/null | sed -n 's/.*= *//p'; }
|
||||
_dd_starting() { pgrep -f "reaper SteamLaunch AppId=$(((game >> 32) & 0xffffffff))( |$)" >/dev/null 2>&1; }
|
||||
_dd_starting() { pgrep -f "reaper SteamLaunch AppId=$appid( |$)" >/dev/null 2>&1; }
|
||||
_dd_hand_off() {
|
||||
printf '%s\n' "$game" > "$DD_LAUNCH_DIR/steam-game.tmp" && mv -f "$DD_LAUNCH_DIR/steam-game.tmp" "$DD_LAUNCH_DIR/steam-game"
|
||||
}
|
||||
@@ -1318,7 +1318,10 @@ case $mode in
|
||||
until [ "$(_dd_focused)" = 769 ] || [ "$SECONDS" -ge "$_dd_end" ]; do
|
||||
sleep 1
|
||||
done
|
||||
[ "${#game}" -gt 10 ] && shortcut=1
|
||||
if [ "${#game}" -gt 10 ]; then
|
||||
shortcut=1
|
||||
appid=$(((game >> 32) & 0xffffffff))
|
||||
fi
|
||||
_dd_ready_end=$((SECONDS + 30))
|
||||
while [ "$waited" -lt 30 ] && [ "$((_dd_ready_end - SECONDS))" -gt 0 ]; do
|
||||
timeout "$((_dd_ready_end - SECONDS))" /usr/local/bin/droiddeck-agent --steam-ready >/dev/null 2>&1 && break
|
||||
@@ -1329,30 +1332,36 @@ case $mode in
|
||||
waited=0
|
||||
echo "== steam: interface up; launching the requested game $game"
|
||||
_dd_hand_off
|
||||
[ -n "$shortcut" ] || return 0
|
||||
while [ "$(_dd_focused)" = 769 ] && [ "$waited" -lt 20 ]; do
|
||||
while [ "$(_dd_focused)" = 769 ] && [ "$waited" -lt 120 ]; do
|
||||
if /usr/local/bin/droiddeck-agent --steam-clear-pending-interstitial "$appid" >/dev/null 2>&1; then
|
||||
echo "== steam: continued a pending launch step for $game"
|
||||
fi
|
||||
sleep 1
|
||||
waited=$((waited + 1))
|
||||
if [ -n "$shortcut" ] && [ "$waited" -eq 20 ]; then
|
||||
if _dd_starting; then
|
||||
echo "== steam: the requested game is already starting; not launching again"
|
||||
return 0
|
||||
fi
|
||||
echo "== steam: the game is not in front after about 20 s; waiting for the shortcut overview"
|
||||
/usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$game" 45 || status=$?
|
||||
if [ "$status" -eq 3 ]; then
|
||||
echo "== steam: not a shortcut CGameID; not launching again"
|
||||
elif _dd_starting; then
|
||||
echo "== steam: the requested game started while waiting; not launching again"
|
||||
return 0
|
||||
elif [ "$(_dd_focused)" = 769 ]; then
|
||||
echo "== steam: clearing the pending launch interstitial for $game (overview status $status)"
|
||||
if ! /usr/local/bin/droiddeck-agent --steam-clear-pending-interstitial "$appid" >/dev/null 2>&1; then
|
||||
echo "== steam: launching the requested game again $game"
|
||||
_dd_hand_off
|
||||
fi
|
||||
else
|
||||
echo "== steam: the game took focus while waiting; not launching again"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
[ "$(_dd_focused)" = 769 ] || return 0
|
||||
if _dd_starting; then
|
||||
echo "== steam: the requested game is already starting; not launching again"
|
||||
return 0
|
||||
fi
|
||||
echo "== steam: the game is not in front after about 20 s; waiting for the shortcut overview"
|
||||
/usr/local/bin/droiddeck-agent --wait-steam-shortcut-overview "$game" 45 || status=$?
|
||||
if [ "$status" -eq 3 ]; then
|
||||
echo "== steam: not a shortcut CGameID; not launching again"
|
||||
elif _dd_starting; then
|
||||
echo "== steam: the requested game started while waiting; not launching again"
|
||||
elif [ "$(_dd_focused)" = 769 ]; then
|
||||
echo "== steam: clearing the pending launch interstitial for $game (overview status $status)"
|
||||
/usr/local/bin/droiddeck-agent --steam-clear-pending-interstitial "$(((game >> 32) & 0xffffffff))" >/dev/null 2>&1 && return 0
|
||||
echo "== steam: launching the requested game again $game"
|
||||
_dd_hand_off
|
||||
else
|
||||
echo "== steam: the game took focus while waiting; not launching again"
|
||||
fi
|
||||
}
|
||||
if [ -n "${DD_LAUNCH_DIR:-}" ] && [ -z "${DD_DESKTOP:-}" ]; then
|
||||
_dd_held=
|
||||
|
||||
@@ -532,6 +532,44 @@ class AgentTest(unittest.TestCase):
|
||||
with self.assertRaises(agent.AgentError):
|
||||
agent.steam_clear_pending_interstitial(self.dir, "0")
|
||||
|
||||
@unittest.skipUnless(shutil.which("node"), "node is not installed")
|
||||
def test_pending_launch_responses_match_the_waiting_task(self):
|
||||
with patch.object(agent, "cdp_eval", return_value={"value": False}) as evaluate:
|
||||
agent.steam_clear_pending_interstitial(self.dir, "413150")
|
||||
expression = evaluate.call_args.args[1]
|
||||
cases = [
|
||||
({"strTaskName": "ShowInterstitials"}, [[7, "ShowInterstitials"]]),
|
||||
({"strTaskName": "ShowInterstitials", "gameid": str((413150 << 32) | 0x02000000)}, [[7, "ShowInterstitials"]]),
|
||||
({"strTaskName": "ShowInterstitials", "gameid": "invalid"}, []),
|
||||
({"strTaskName": "CreatingProcess"}, [[7, "CreatingProcess"]]),
|
||||
({"strTaskName": "ShowLaunchOption", "nLaunchOption": 2}, [[7, "2"]]),
|
||||
({"strTaskName": "ShowLaunchOption", "nLaunchOption": -1}, [[7, "0"]]),
|
||||
({"strTaskName": "ShowLaunchOption", "nLaunchOption": 0}, [[7, "0"]]),
|
||||
({"strTaskName": "SynchronizingCloud"}, []),
|
||||
({"strTaskName": "ShowEula"}, []),
|
||||
({"strTaskName": "DownloadingDepots"}, []),
|
||||
({"strTaskName": "ShowInterstitials", "bWaitingForUI": False}, []),
|
||||
({"strTaskName": "ShowInterstitials", "strActionName": "VerifyApp"}, []),
|
||||
({"strTaskName": "ShowInterstitials", "gameid": "123"}, []),
|
||||
]
|
||||
for changes, expected in cases:
|
||||
action = dict(nGameActionID=7, gameid="413150", strActionName="LaunchApp", bWaitingForUI=True)
|
||||
action.update(changes)
|
||||
harness = """
|
||||
const calls = [];
|
||||
globalThis.SteamClient = {Apps: {
|
||||
GetActiveGameActions: async () => %s,
|
||||
ContinueGameAction: (...args) => calls.push(args)
|
||||
}};
|
||||
(async () => {
|
||||
const result = await %s;
|
||||
process.stdout.write(JSON.stringify({result, calls}));
|
||||
})().catch(error => { console.error(error); process.exit(1); });
|
||||
""" % (json.dumps([action]), expression)
|
||||
with self.subTest(changes=changes):
|
||||
result = subprocess.run(["node", "-e", harness], text=True, capture_output=True, check=True, timeout=5)
|
||||
self.assertEqual({"result": bool(expected), "calls": expected}, json.loads(result.stdout))
|
||||
|
||||
def test_asleep_command_reports_steams_own_sleep_state(self):
|
||||
with patch.dict(os.environ, {"DD_LAUNCH_DIR": str(self.dir.parent)}):
|
||||
for value, code in (("yes", 0), ("no", 5), ("unknown", 1), (None, 1)):
|
||||
|
||||
@@ -32,6 +32,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
xprop.write_text(
|
||||
"#!/bin/sh\n"
|
||||
"n=$(cat \"$FOCUS_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$FOCUS_COUNT\"\n"
|
||||
"[ ! -f \"$HOME/overview-focus\" ] || { echo \"GAMESCOPE_FOCUSED_APP(CARDINAL) = $(cat \"$HOME/overview-focus\")\"; exit; }\n"
|
||||
"i=0; last=769\n"
|
||||
"for f in $FOCUS; do i=$((i + 1)); last=$f; [ \"$i\" -eq \"$n\" ] && break; done\n"
|
||||
"echo \"GAMESCOPE_FOCUSED_APP(CARDINAL) = $last\"\n")
|
||||
@@ -42,6 +43,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
"printf '%s\n' \"$@\" > \"$AGENT_ARGS\"\n"
|
||||
"n=$(cat \"$AGENT_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$AGENT_COUNT\"\n"
|
||||
"[ \"$1\" = --steam-ready ] && exit \"${READY_STATUS:-0}\"\n"
|
||||
"if [ \"$1\" = --wait-steam-shortcut-overview ] && [ -n \"$OVERVIEW_FOCUS\" ]; then echo \"$OVERVIEW_FOCUS\" > \"$HOME/overview-focus\"; fi\n"
|
||||
"exit \"$AGENT_STATUS\"\n")
|
||||
agent.chmod(0o755)
|
||||
sleep = self.bin / "sleep"
|
||||
@@ -56,13 +58,13 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
pgrep.chmod(0o755)
|
||||
self.block = LAUNCH_BLOCK.replace("/usr/local/bin/droiddeck-agent", str(agent))
|
||||
|
||||
def run_launch(self, target, focus="769", helper_status=0, running_after=999, ready_status=0):
|
||||
def run_launch(self, target, focus="769", helper_status=0, running_after=999, ready_status=0, overview_focus=""):
|
||||
env = dict(os.environ, HOME=str(self.root), DD_LAUNCH_DIR=str(self.launch_dir),
|
||||
PATH=str(self.bin) + os.pathsep + os.environ["PATH"],
|
||||
AGENT_ARGS=str(self.agent_args), SLEEP_ARGS=str(self.sleep_args),
|
||||
AGENT_COUNT=str(self.agent_count), AGENT_STATUS=str(helper_status),
|
||||
FOCUS=focus, FOCUS_COUNT=str(self.focus_count), RUNNING_AFTER=str(running_after),
|
||||
READY_STATUS=str(ready_status))
|
||||
READY_STATUS=str(ready_status), OVERVIEW_FOCUS=overview_focus)
|
||||
script = self.block + "\nprintf 'ARG:%s\n' \"$@\"\nwait\n"
|
||||
url = target if target.startswith("steam://") else "steam://rungameid/" + target
|
||||
result = subprocess.run(["bash", "-c", script, "cold-launch", url],
|
||||
@@ -85,7 +87,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("clearing the pending launch interstitial", result.stdout)
|
||||
self.assertEqual(["--steam-clear-pending-interstitial", "3551182975"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual(["1"] * 20, self.sleep_args.read_text().split())
|
||||
self.assertEqual(["1"] * 120, self.sleep_args.read_text().split())
|
||||
|
||||
def test_a_timed_out_overview_still_gets_one_more_hand_off(self):
|
||||
result = self.run_launch(SHORTCUT, focus="769", helper_status=1)
|
||||
@@ -97,7 +99,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
result = self.run_launch("413150", ready_status=1)
|
||||
self.assertEqual("413150", (self.launch_dir / "steam-game").read_text().strip())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertEqual(["1"] * 30, self.sleep_args.read_text().split())
|
||||
self.assertEqual(["1"] * 150, self.sleep_args.read_text().split())
|
||||
|
||||
def test_a_focus_change_does_not_end_the_readiness_wait(self):
|
||||
result = self.run_launch("413150", focus="769 4242", ready_status=1)
|
||||
@@ -107,7 +109,7 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
def test_a_game_still_starting_without_a_window_is_not_launched_twice(self):
|
||||
result = self.run_launch(SHORTCUT, running_after=1)
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertIn("--steam-ready", self.agent_args.read_text())
|
||||
self.assertEqual(["--steam-clear-pending-interstitial", "3551182975"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual(["-f", "reaper SteamLaunch AppId=3551182975( |$)"],
|
||||
(self.root / "pgrep-args").read_text().splitlines())
|
||||
self.assertIn("already starting", result.stdout)
|
||||
@@ -119,18 +121,24 @@ class SteamColdLaunchTest(unittest.TestCase):
|
||||
self.assertIn("started while waiting", result.stdout)
|
||||
|
||||
def test_a_game_that_takes_focus_during_the_overview_wait_is_not_started_twice(self):
|
||||
focus = " ".join(["769"] * 23) + " 4242"
|
||||
result = self.run_launch(SHORTCUT, focus=focus, helper_status=0)
|
||||
result = self.run_launch(SHORTCUT, helper_status=0, overview_focus="4242")
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertNotIn("clearing the pending launch interstitial", result.stdout)
|
||||
self.assertNotIn("launching the requested game again", result.stdout)
|
||||
|
||||
def test_native_app_id_keeps_the_short_delay_and_is_handed_over_once(self):
|
||||
def test_native_app_id_recovers_pending_steps_without_relaunching(self):
|
||||
result = self.run_launch("413150")
|
||||
self.assertEqual("413150", (self.launch_dir / "steam-game").read_text().strip())
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertFalse(self.sleep_args.exists())
|
||||
self.assertIn("--steam-ready", self.agent_args.read_text())
|
||||
self.assertEqual(["1"] * 120, self.sleep_args.read_text().split())
|
||||
self.assertEqual(["--steam-clear-pending-interstitial", "413150"], self.agent_args.read_text().splitlines())
|
||||
self.assertEqual(121, int(self.agent_count.read_text()))
|
||||
|
||||
def test_native_app_recovery_does_not_stop_for_an_install_script_or_repeat_a_failed_launch(self):
|
||||
result = self.run_launch("413150", helper_status=1, running_after=1)
|
||||
self.assertEqual(1, len(self.hand_offs(result)), result.stdout)
|
||||
self.assertEqual(121, int(self.agent_count.read_text()))
|
||||
self.assertEqual(["--steam-clear-pending-interstitial", "413150"], self.agent_args.read_text().splitlines())
|
||||
|
||||
def test_a_restart_for_a_game_uses_the_same_hand_off(self):
|
||||
loop = SOURCE[SOURCE.index(' if [ -s "$HOME/.dd-restart-game" ]; then'):SOURCE.index(' if [ -f "$HOME/.dd-restart-once" ]; then')]
|
||||
|
||||
Reference in new issue
Block a user