feat: Epic Games Launcher for Linux (#928)

* feat: Epic Games Launcher for Linux

Install Epic's official Linux launcher (EGLv2) from Epic's CDN with Valve's
Steam Runtime 4 and run it under FEX, signed in with the linked Epic account.
Epic games launch through a hidden launcher instance so they get the
launcher's own arguments, with the exchange-code launch as the fallback, and
DroidDeck installs show up in the launcher as installed.

In the launcher, touch scrolls like a phone app and the gamepad drives the UI:
D-pad and left stick move the selection, A opens, B goes back, the right stick
and triggers scroll proportionally, X opens the options menu, Y the keyboard
and LB/RB switch tabs.

* feat: Epic Games Launcher for Linux

Install Epic's official Linux launcher (EGLv2) from Epic's CDN with Valve's
Steam Runtime 4 and run it under FEX, signed in with the linked Epic account.
Epic games launch through a hidden launcher instance so they get the
launcher's own arguments, with the exchange-code launch as the fallback, and
DroidDeck installs show up in the launcher as installed.

In the launcher, touch scrolls like a phone app and the gamepad drives the UI:
D-pad and left stick move the selection, A opens, B goes back, the right stick
and triggers scroll proportionally, X opens the options menu, Y the keyboard
and LB/RB switch tabs.

* Route Epic games through Steam, import launcher installs, offer the second library

- Every Epic launch goes Steam -> Epic Games Launcher -> game; Play inside the open launcher hands the game to Steam
- Games installed from inside the launcher get a Games-tab entry and launch through Steam; the launcher installs to the last Stores target
- Stores install picker offers the Steam second library, with side-by-side choices
- uruntime xattr-only failures no longer fail the launcher unpack (app-extract)

* Hand launcher Play and Steam links to Steam, wait for FEX on first run

Play on a game the launcher just installed is matched to its install
record and handed to Steam. Steam games listed in the launcher open
steam://rungameid links, which now start the game in a Steam session.
Opening the launcher before Steam has downloaded FEX asks Steam for it
and starts Steam instead of failing with no-fex.

* Address review: FEX check, play-in-Steam action, touch route thread, scroll scale

fexReady needs a FEX binary in Steam's FEX tool, not just its folder.
The play-in-Steam action stays until the link is handled, so Run Steam
at startup can't start a session first. The pad touch route reads the
mouse mode without side effects off the main thread and posts the pad
update there. Vertical scroll uses the output height. A status-2 unpack
counts only when AppRun is there. The xdg-open command is tested
end to end for Steam links.

* Open the launcher through Steam, recover dropped shortcuts, sign out of both

The Epic Games Launcher now runs as its own Steam shortcut, so opening
it starts Steam, which opens the launcher, and Play inside it goes to
the running Steam.

Steam dropped a running shortcut from its library when the game exited
after a sleep/wake replay or a server re-logon, and launching it then
waited forever at ShowInterstitials. login1 only replays sleep/wake
when Steam is asleep. The session restarts Steam when a requested
shortcut is missing, and when a game exits with its shortcut gone and
nothing else runs.

Resuming after a long pause no longer reports failure while traced
processes are still waking, so "Steam is paused" goes away on the first
tap.

Signing out of the launcher signs DroidDeck's Epic store out, and
signing out in DroidDeck restarts the launcher signed out and clears
the Epic web cookies.

* Address review: one session-switch poll, Epic setup can't block a session

A new switch confirmation replaces the pending poll instead of adding a
second one that could start the session again. Epic library sync and
install-folder setup at session start are each guarded, so a bad
preference no longer stops the guest from launching.

* Uninstall the Epic Games Launcher from the Games tab

An Uninstall button next to Launch asks first, closes a running
session, and removes the launcher and its runtime. The launcher's
sign-in and install records stay, so its games keep their Games-tab
entries and a reinstall comes back signed in. Its Steam shortcut goes
away on the next Steam start.

* Address review: uninstall only after the session has ended

The launcher's files are removed only once the session is not running
and its phase has ended; a shutdown still in progress after the wait
reports failure instead. The confirmation reads the session state from
the front-end state.

* Find FEX that Steam installed on the second library

Steam's tools on a second library live in DroidDeck's private copy,
which the session binds over the library. The launcher's FEX check
only looked on the shared storage, so with FEX there it always asked
Steam for FEX and only Steam opened. It now checks the private copy
too.

* Start games without Steam, per-game Settings menu with Wine sync

"Start without Steam" now really leaves the Steam client out: the game
runs in its own Proton/FEX through droiddeck-proton-run in a run
session, and the Epic Games Launcher opens on its own with its games
playing in it. Run sessions for these games are not pinned to the big
cores and get DirectAudio and the added-games list like Steam.

The Games tab card is now "Settings", titled "<game> Settings": Start
without Steam, FEX preset, Wine sync (ntsync, fsync, esync, wineserver
or the app default) and Default, which puts everything changed for the
game back to the app's settings. The app-wide Wine sync choice is shown
in the Steam settings Session tab.

* Address review: uninstall guard, routed games, shortcut matching

Opening or reinstalling the Epic Games Launcher waits while it is being
uninstalled. Added games that are Steam installs keep their Start
without Steam setting under their Steam app id and start as that Steam
game. Live shortcut lookups wait for Steam's library to load and match
a same-name shortcut by its executable, so no duplicate is added. The
session treats the open launcher as itself even when it could not tell
its Steam app id.

* Address review: drop a queued launcher switch when it is uninstalled

A confirmed switch to the Epic Games Launcher that is still waiting for
the old session to end is cancelled when the launcher is uninstalled,
and never starts while the uninstall runs. The launcher id test sets
its environment for its own runs only.
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-10-17 14:40:39 -04:00
1 parent 83eda433c8
commit 97f976ef6c
107 files changed
+8860 -371

No files matched your search

+59
View File
@@ -516,6 +516,65 @@ class ProtonRunTest(Temp):
self.assertEqual(env["SteamAppId"], "413150")
self.assertTrue((self.root / "steamapps/compatdata/413150").is_dir())
def run_main(self, argv):
calls, dirs = [], []
with mock.patch.dict(os.environ, {"STEAM_COMPAT_CLIENT_INSTALL_PATH": str(self.root)}), \
mock.patch.object(RUN["os"], "execve", lambda *a: calls.append(a)), \
mock.patch.object(RUN["os"], "chdir", dirs.append), mock.patch.dict(RUN, {"say": lambda message: None}):
code = RUN["main"](argv)
return code, calls, dirs
def test_without_steam_a_steam_game_starts_its_default_windows_launch(self):
info = {"common": {"type": "Game", "oslist": "windows,linux"}, "config": {"launch": {
"0": {"executable": "Bin\\Game.exe", "arguments": "-dx11 \"-name=Two Words\"", "workingdir": "bin",
"type": "default", "config": {"oslist": "windows"}},
"1": {"executable": "game.sh", "type": "default", "config": {"oslist": "linux"}},
"2": {"executable": "Beta.exe", "type": "default", "config": {"oslist": "windows", "betakey": "beta"}},
"3": {"executable": "Tools\\Editor.exe", "type": "option1"},
}}}
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: info}))
program = self.game("413150", "Some Game", "bin/game.exe")
self.game("413150", "Some Game", "Tools/Editor.exe")
code, calls, dirs = self.run_main(["--app", "413150", "--options", "-windowed"])
self.assertIsNone(code)
entry, argv, env = calls[0]
self.assertEqual(argv[1:], ["waitforexitandrun", str(program), "-dx11", "-name=Two Words", "-windowed"])
self.assertEqual((env["SteamAppId"], env["STEAM_COMPAT_DATA_PATH"]),
("413150", str(self.root / "steamapps/compatdata/413150")))
self.assertEqual(dirs, [str(program.parent)])
def test_without_steam_a_game_steam_cannot_start_is_refused(self):
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: STARDEW}))
self.assertEqual(self.run_main(["--app", "413150"])[0], 2)
self.assertEqual(self.run_main(["--app", "3384071994"])[0], 2)
self.assertEqual(self.run_main(["--app", "0"])[0], 2)
self.assertEqual(self.run_main(["--app", "game"])[0], 2)
linux = {"common": {"type": "Game"}, "config": {"launch": {"0": {"executable": "run.sh", "config": {"oslist": "linux"}}}}}
self.write("Steam/appcache/appinfo.vdf", appinfo({70: linux}))
self.game("70", "Linux Game", "run.sh")
self.assertEqual(self.run_main(["--app", "70"])[0], 2)
def test_without_steam_a_shortcut_keeps_its_prefix_folder_and_launch_options(self):
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
start = self.tmp / "Games/Epic/Game/Binaries"
start.mkdir()
code, calls, dirs = self.run_main(["--app", "2733369024", "--dir", str(start), "--options",
"PROTON_LOG=1 %command% -epicportal", "--", str(bat)])
self.assertIsNone(code)
entry, argv, env = calls[0]
self.assertEqual(argv[1:], ["waitforexitandrun", str(bat), "-epicportal"])
self.assertEqual((env["STEAM_COMPAT_DATA_PATH"], env["SteamAppId"], env["SteamGameId"], env["PROTON_LOG"]),
(str(self.root / "steamapps/compatdata/2733369024"), "0", str(2733369024 << 32 | 0x02000000), "1"))
self.assertTrue((self.root / "steamapps/compatdata/2733369024").is_dir())
self.assertEqual(dirs, [str(start)])
def test_launch_options_split_like_steam_does(self):
split = RUN["split_options"]
self.assertEqual(split(""), ({}, []))
self.assertEqual(split("-windowed -w 1280"), ({}, ["-windowed", "-w", "1280"]))
self.assertEqual(split("A=1 B=\"x y\" gamemoderun %command% -dx12"), ({"A": "1", "B": "x y"}, ["-dx12"]))
self.assertEqual(split("\"unterminated -x"), ({}, ["\"unterminated", "-x"]))
if __name__ == "__main__":
unittest.main()
+47
View File
@@ -291,6 +291,53 @@ class AgentTest(unittest.TestCase):
self.assertFalse(result["supported"])
evaluate.assert_not_called()
def test_shortcut_state_tells_a_lost_shortcut_from_a_loading_library(self):
game_id = str((3333273269 << 32) | 0x02000000)
self.assertEqual("not-shortcut", agent.steam_shortcut_state(self.dir, "413150"))
for values, wanted, calls in ((["loading", "ready"], "ready", 2), (["loading", "missing"], "missing", 3),
([None], "loading", 3)):
clock = [0.0]
replies = [{"value": v} for v in values] + [{"value": values[-1]}] * 10
with self.subTest(values=values), patch.object(agent, "cdp_eval", side_effect=replies) as evaluate, \
patch.object(agent.time, "monotonic", side_effect=lambda: clock[0]), \
patch.object(agent.time, "sleep", side_effect=lambda delay: clock.__setitem__(0, clock[0] + delay)):
self.assertEqual(wanted, agent.steam_shortcut_state(self.dir, game_id, timeout=1))
self.assertEqual(calls, evaluate.call_count)
self.assertIn("GetAppOverviewByGameID(%s)" % json.dumps(game_id), evaluate.call_args_list[0].args[1])
def test_shortcut_state_waits_out_an_unreachable_client_but_not_other_errors(self):
game_id = str((3333273269 << 32) | 0x02000000)
clock = [0.0]
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("NO_DEVTOOLS", "down")), \
patch.object(agent.time, "monotonic", side_effect=lambda: clock[0]), \
patch.object(agent.time, "sleep", side_effect=lambda delay: clock.__setitem__(0, clock[0] + delay)):
self.assertEqual("loading", agent.steam_shortcut_state(self.dir, game_id, timeout=1))
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("CDP_EXCEPTION", "boom")):
with self.assertRaises(agent.AgentError):
agent.steam_shortcut_state(self.dir, game_id, timeout=1)
def test_shortcut_state_command_exits_with_the_state(self):
game_id = str((3333273269 << 32) | 0x02000000)
launch = self.dir.parent
with patch.dict(os.environ, {"BL_LAUNCH_DIR": str(launch)}):
for state, code in (("ready", 0), ("missing", 4), ("not-shortcut", 3), ("loading", 1)):
with self.subTest(state=state), patch.object(agent, "steam_shortcut_state", return_value=state) as ask:
self.assertEqual(code, agent.main(["--steam-shortcut-state", game_id, "2"]))
self.assertEqual((launch / "agent", game_id, "2"), ask.call_args.args)
with patch.object(agent, "steam_shortcut_state", side_effect=agent.AgentError("CDP_EXCEPTION", "boom")):
self.assertEqual(1, agent.main(["--steam-shortcut-state", game_id]))
self.assertEqual(2, agent.main(["--steam-shortcut-state"]))
def test_asleep_command_reports_steams_own_sleep_state(self):
with patch.dict(os.environ, {"BL_LAUNCH_DIR": str(self.dir.parent)}):
for value, code in (("yes", 0), ("no", 5), ("unknown", 1), (None, 1)):
with self.subTest(value=value), patch.object(agent, "cdp_eval", return_value={"value": value}) as ask:
self.assertEqual(code, agent.main(["--steam-asleep"]))
self.assertIn("m_bSuspending", ask.call_args.args[1])
self.assertFalse(ask.call_args.kwargs["await_promise"])
with patch.object(agent, "cdp_eval", side_effect=agent.AgentError("NO_DEVTOOLS", "down")):
self.assertEqual(1, agent.main(["--steam-asleep"]))
def test_cdp_exception(self):
server = FakeDevTools({"result": {"result": {"type": "object"}, "exceptionDetails": {
"text": "Uncaught", "exception": {"description": "ReferenceError: SteamClient is not defined"}}}})
File diff suppressed because it is too large. Load diff
+56
View File
@@ -317,6 +317,35 @@ class ExtractTest(FexTestCase):
self.assertTrue((self.home / ".config/droiddeck/fex-wanted").is_file())
self.assertFalse(json.loads((self.home / ".local/share/droiddeck-fex/status.json").read_text())["ready"])
def test_uruntime_that_only_drops_extended_attributes_still_unpacks(self):
tool = self.uruntime(
"mkdir -p AppDir && touch AppDir/AppRun\n"
"echo 'Failed to exec memfd: EACCES: Permission denied. Trying tmpfile in /tmp...' >&2\n"
"echo 'write_xattr: could not write xattr security.selinux for file ./AppDir/.DirIcon because you are not superuser!' >&2\n"
"echo 'Further error messages of this type are suppressed!' >&2\n"
"exit 2\n")
with mock.patch.dict(G, {"URUNTIME": tool, "fex_install": lambda: None, "steam_running": lambda: False}):
status, said = self.quiet(FEX["extract"], "image.AppImage")
self.assertEqual(status, 0)
self.assertIn("could not keep the image's extended attributes", said)
self.assertTrue(Path("squashfs-root/AppRun").is_file())
def test_an_attribute_only_failure_without_apprun_is_not_taken_as_unpacked(self):
tool = self.uruntime(
"mkdir -p AppDir\n"
"echo 'write_xattr: could not write xattr security.selinux for file ./AppDir/.DirIcon because you are not superuser!' >&2\n"
"exit 2\n")
with mock.patch.dict(G, {"URUNTIME": tool, "fex_install": lambda: None, "steam_running": lambda: False, "prepare": lambda: None}):
status, said = self.quiet(FEX["extract"], "image.AppImage")
self.assertIn("uruntime could not extract it (status 2)", said)
self.assertNotIn("could not keep the image's extended attributes", said)
self.assertFalse(os.path.lexists("squashfs-root/AppRun"))
def test_other_uruntime_errors_are_not_taken_as_unpacked(self):
self.assertFalse(FEX["only_xattrs_failed"]("write_xattr: could not write xattr\nwrite_file: failed to create file x\n"))
self.assertFalse(FEX["only_xattrs_failed"](""))
self.assertTrue(FEX["only_xattrs_failed"]("proot error: execveat() failed\nwrite_xattr: could not write xattr\n"))
def test_an_arm64_image_does_not_ask_for_fex(self):
self.write(self.image, elf(183) + b"payload", 0o755)
tool = self.uruntime("mkdir -p squashfs-root\n")
@@ -335,6 +364,33 @@ class ExtractTest(FexTestCase):
self.assertIn("no AppImage runtime for ARM64, no FEX yet and no unsquashfs", said)
self.assertFalse(os.path.lexists("squashfs-root"))
def test_unsquashfs_fallback_disables_unwritable_xattrs(self):
tool = self.uruntime("exit 1\n")
commands = []
def call(argv, **kwargs):
commands.append(argv)
if argv[0] == tool:
return 1
(self.work / "squashfs-root").mkdir()
(self.work / "squashfs-root/AppRun").touch()
return 0
with mock.patch.dict(G, {
"URUNTIME": tool,
"prepare": lambda: None,
"fex_install": lambda: None,
"steam_running": lambda: False,
"want_fex": lambda: None,
}), mock.patch("shutil.which", return_value="/usr/bin/unsquashfs"), \
mock.patch("subprocess.call", side_effect=call):
status, said = self.quiet(FEX["extract"], "image.AppImage")
self.assertEqual(status, 0)
self.assertIn("uruntime could not extract it (status 1)", said)
self.assertEqual(commands[-1][0], "/usr/bin/unsquashfs")
self.assertIn("-no-xattrs", commands[-1])
self.assertTrue(Path("squashfs-root/AppRun").is_file())
class LaunchTest(FexTestCase):
def test_the_guest_environment(self):
+6 -22
View File
@@ -90,6 +90,12 @@ class GameEnvironmentTest(unittest.TestCase):
self.assertEqual(env["REMOVE"], "inherited")
self.assertEqual(MODULE["apply_config"](env, config, "43")["CUSTOM"], "shared")
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"}
config = {"version": 1, "games": {"42": {"BL_SYNC": "0", "BL_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "FEX_TSOENABLED": "1"}}}
chosen = MODULE["apply_config"](env, MODULE["sync_config"](config, "42"), "42")
self.assertEqual(chosen, {"BL_SYNC": "0", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "OTHER": "kept"})
def test_component_profiles_override_general_and_restore_it_for_the_next_game(self):
with tempfile.TemporaryDirectory() as tmp:
root = Path(tmp)
@@ -947,28 +953,6 @@ if __name__ == "__main__":
unittest.main()
class StartWithoutSteamTest(unittest.TestCase):
def test_start_without_steam_uses_umu_or_runinprefix_and_only_when_asked(self):
with tempfile.TemporaryDirectory() as tmp:
ge = Path(tmp) / "ge/proton"
ge.parent.mkdir()
ge.write_text('if "UMU_ID" in os.environ:\n argv = [wine, "c:\\\\windows\\\\system32\\\\umu.exe"]\n')
valve = Path(tmp) / "valve/proton"
valve.parent.mkdir()
valve.write_text('argv = [wine, "c:\\\\windows\\\\system32\\\\steam.exe"]\n')
start = MODULE["start_without_steam"]
game = [str(ge), "waitforexitandrun", "/games/Game.exe", "-windowed"]
self.assertEqual(start(game, {}, "3384071994"), (game, {}))
on = {"DROIDDECK_NO_STEAM": "1"}
self.assertEqual(start(game, on, "3384071994"), (game, dict(on, UMU_ID="0")))
self.assertEqual(start(game, on, "570940")[1]["UMU_ID"], "570940")
self.assertEqual(start(game, dict(on, UMU_ID="umu-1"), "570940")[1]["UMU_ID"], "umu-1")
plain = [str(valve)] + game[1:]
self.assertEqual(start(plain, on, "570940"), ([str(valve), "runinprefix", "/games/Game.exe", "-windowed"], on))
for other in ([str(ge), "run", "/x.exe"], [str(ge), "waitforexitandrun"], [str(valve), "getcompatpath", "/x"]):
self.assertEqual(start(other, on, "570940"), (other, on))
class ForceSsbsTest(unittest.TestCase):
def test_libssbs_is_preloaded_only_when_asked_and_only_into_arm64_proton(self):
with tempfile.TemporaryDirectory() as tmp:
+58 -1
View File
@@ -23,6 +23,7 @@ IFACE = NAME + ".Manager"
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
class SleepHandshakeTest(unittest.TestCase):
ARGS = []
AGENT_EXIT = None
def setUp(self):
self.directory = tempfile.TemporaryDirectory()
@@ -37,7 +38,16 @@ class SleepHandshakeTest(unittest.TestCase):
lambda bus, sender, path, interface, name, body: self.signals.append(body.unpack()[0]))
env = dict(os.environ, BL_LAUNCH_DIR=str(self.dir),
DBUS_SYSTEM_BUS_ADDRESS=os.environ["DBUS_SESSION_BUS_ADDRESS"])
self.process = subprocess.Popen(["/usr/bin/python3", str(SCRIPT), *self.ARGS], env=env,
script = SCRIPT
if self.AGENT_EXIT is not None:
bin_dir = self.dir / "bin"
bin_dir.mkdir()
script = bin_dir / SCRIPT.name
script.write_text(SCRIPT.read_text())
agent = bin_dir / "droiddeck-agent"
agent.write_text("#!/bin/sh\necho \"$@\" >> \"%s\"\nexit %d\n" % (self.dir / "agent-calls", self.AGENT_EXIT))
agent.chmod(0o755)
self.process = subprocess.Popen(["/usr/bin/python3", str(script), *self.ARGS], env=env,
stdout=subprocess.DEVNULL)
self.wait_for(lambda: (self.dir / "steam-sleep-ready").exists())
@@ -220,6 +230,53 @@ class SleepHandshakeTest(unittest.TestCase):
self.call(IFACE, "PowerOff", GLib.Variant("(b)", (True,)))
class FakeAgentCase(unittest.TestCase):
ARGS = []
setUp = SleepHandshakeTest.setUp
tearDown = SleepHandshakeTest.tearDown
wait_for = SleepHandshakeTest.wait_for
call = SleepHandshakeTest.call
suspend = SleepHandshakeTest.suspend
state = SleepHandshakeTest.state
request_wake = SleepHandshakeTest.request_wake
def asked(self):
path = self.dir / "agent-calls"
return path.read_text().split() if path.exists() else []
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
class AwakeSteamTest(FakeAgentCase):
AGENT_EXIT = 5
def test_resuming_an_awake_steam_sends_no_sleep_wake_pair(self):
self.request_wake()
self.wait_for(lambda: self.asked())
deadline = time.monotonic() + 1.5
while time.monotonic() < deadline:
self.wait_for(lambda: True)
time.sleep(0.05)
self.assertEqual([], self.signals)
self.assertEqual(["--steam-asleep"], self.asked())
def test_a_pending_sleep_still_wakes_without_asking_steam(self):
token = self.suspend()
self.state(token, "paused")
self.request_wake()
self.wait_for(lambda: self.signals == [True, False])
self.assertEqual([], self.asked())
@unittest.skipUnless(Gio and os.environ.get("DBUS_SESSION_BUS_ADDRESS"), "requires dbus-run-session and PyGObject")
class AsleepSteamTest(FakeAgentCase):
AGENT_EXIT = 0
def test_resuming_a_sleeping_steam_replays_the_pair(self):
self.request_wake()
self.wait_for(lambda: self.signals == [True, False])
self.assertEqual(["--steam-asleep"], self.asked())
class WithNetworkManagerTest(SleepHandshakeTest):
ARGS = ["--with-netmanager"]
+1
View File
@@ -65,6 +65,7 @@ static void send_toplevel_configure(struct surface *s) { (void)s; resizes++; }
#define pointer_event(...) ((void)0)
#define pointer_button(...) ((void)0)
#define scroll_event(...) ((void)0)
#define axis_event(...) ((void)0)
#define pointer_delta(...) ((void)0)
#define deliver_touch(m) ((void)0)
#define deliver_pointer(m) (pointers++)
+74
View File
@@ -0,0 +1,74 @@
import os
import re
import shutil
import signal
import subprocess
import tempfile
import time
import unittest
from pathlib import Path
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
def run_program_function():
match = re.search(r"^ run_program\(\) \{\n.*?^ \}\n", SESSION.read_text(), re.M | re.S)
return match.group(0)
class RunStatusTest(unittest.TestCase):
def setUp(self):
self.dir = Path(tempfile.mkdtemp())
self.addCleanup(shutil.rmtree, self.dir, True)
def run_with(self, command, launch_dir=True):
env = dict(os.environ)
env.pop("BL_LAUNCH_DIR", None)
if launch_dir:
env["BL_LAUNCH_DIR"] = str(self.dir)
return subprocess.run(["bash", "-c", run_program_function() + "run_program " + command + "; echo unreachable"],
env=env, capture_output=True, text=True, timeout=30)
def test_the_program_status_is_kept_for_the_app(self):
run = self.run_with("sh -c 'exit 7'")
self.assertEqual(7, run.returncode)
self.assertNotIn("unreachable", run.stdout)
self.assertEqual("7\n", (self.dir / "run-status").read_text())
self.assertFalse((self.dir / "run-status.tmp").exists())
def test_a_clean_exit_is_recorded_as_zero(self):
self.assertEqual(0, self.run_with("true").returncode)
self.assertEqual("0\n", (self.dir / "run-status").read_text())
def test_nothing_is_written_without_a_launch_dir(self):
self.assertEqual(3, self.run_with("sh -c 'exit 3'", launch_dir=False).returncode)
self.assertEqual([], os.listdir(self.dir))
def signalled(self, sig, program):
env = dict(os.environ, BL_LAUNCH_DIR=str(self.dir))
ready = self.dir / "ready"
proc = subprocess.Popen(["bash", "-c", run_program_function() + "run_program " + program],
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
self.addCleanup(proc.kill)
deadline = time.monotonic() + 10
while not ready.exists() and time.monotonic() < deadline:
time.sleep(0.05)
self.assertTrue(ready.exists())
proc.send_signal(sig)
return proc.wait(timeout=10)
def test_a_stop_signal_reaches_the_program(self):
program = ("python3 -c 'import signal, sys, time; signal.signal(signal.SIGTERM, lambda *a: sys.exit(9)); "
"open(sys.argv[1], \"w\").close(); time.sleep(30)' %s" % (self.dir / "ready"))
self.assertEqual(9, self.signalled(signal.SIGTERM, program))
self.assertEqual("9\n", (self.dir / "run-status").read_text())
def test_an_interrupt_reaches_the_program(self):
program = ("python3 -c 'import sys, time; open(sys.argv[1], \"w\").close(); time.sleep(30)' %s"
% (self.dir / "ready"))
self.assertEqual(130, self.signalled(signal.SIGINT, program))
self.assertEqual("130\n", (self.dir / "run-status").read_text())
if __name__ == "__main__":
unittest.main()
+16 -9
View File
@@ -8,15 +8,8 @@ import unittest
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
SOURCE = SESSION.read_text()
END = SOURCE.index(
' if [ -s "$HOME/.bl-autolaunch" ]; then',
SOURCE.index(" _bl_launch_ready="),
)
START = SOURCE.rfind(
' if [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ]; then',
0,
END,
)
START = SOURCE.index(" steam_hold_launch() {")
END = SOURCE.index(' if [ -s "$HOME/.bl-autolaunch" ]; then', START)
assert START >= 0
LAUNCH_BLOCK = textwrap.dedent(SOURCE[START:END])
@@ -103,6 +96,20 @@ class SteamColdLaunchTest(unittest.TestCase):
self.assertEqual("1", self.agent_count.read_text().strip())
self.assertFalse(self.sleep_args.exists())
def test_a_restart_for_a_game_waits_for_its_overview_too(self):
game_id = str((3551182975 << 32) | 0x02000000)
loop = SOURCE[SOURCE.index(' if [ -s "$HOME/.bl-restart-game" ]; then'):SOURCE.index(' if [ -f "$HOME/.bl-restart-once" ]; then')]
self.assertIn('steam_hold_launch "$_bl_again" &', loop)
self.assertNotIn("set -- \"steam://rungameid/", loop)
script = self.block + '\nsteam_hold_launch "%s"\n' % game_id
env = dict(os.environ, HOME=str(self.root), BL_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="1 0")
result = subprocess.run(["bash", "-c", script, "restart"], env=env, text=True, capture_output=True, timeout=10, check=True)
self.assertEqual(game_id, (self.launch_dir / "steam-game").read_text().strip(), result.stdout)
self.assertEqual(["--wait-steam-shortcut-overview", game_id, "45"], self.agent_args.read_text().splitlines())
def test_non_game_steam_urls_remain_on_the_original_startup_arguments(self):
url = "steam://open/library"
result = self.run_launch(url, 0)
+11
View File
@@ -84,6 +84,17 @@ class ImportsTest(unittest.TestCase):
imports.watch(str(self.steam), str(listing))
identify.assert_not_called()
def test_native_programs_stay_shortcuts_and_are_never_looked_up(self):
self.snapshot()
game = dict(self.game, native=True)
self.assertEqual(([game], {}), imports.route(self.steam, self.acct, [game]))
self.assertFalse((self.steam / 'steamapps/appmanifest_42.acf').exists())
listing = self.root / 'games.json'
listing.write_text(json.dumps([game]))
with patch.object(imports, 'identify') as identify:
imports.watch(str(self.steam), str(listing))
identify.assert_not_called()
def test_migrates_only_unchanged_legacy_import_manifests(self):
self.snapshot()
imports.route(self.steam, self.acct, [self.game])
+174
View File
@@ -0,0 +1,174 @@
import os
from pathlib import Path
import subprocess
import tempfile
import textwrap
import unittest
SESSION = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-session"
SOURCE = SESSION.read_text()
START = SOURCE.index(" steam_other_game_running() {")
END = SOURCE.index(" steam_bring_forward() {", START)
FUNCTIONS = textwrap.dedent(SOURCE[START:END])
GAME = str((3333273269 << 32) | 0x02000000)
class SteamShortcutRecoveryTest(unittest.TestCase):
def setUp(self):
self.temp = tempfile.TemporaryDirectory()
self.addCleanup(self.temp.cleanup)
self.root = Path(self.temp.name)
self.launch = self.root / "session"
self.launch.mkdir()
self.bin = self.root / "bin"
self.bin.mkdir()
steam = self.root / "steam/steamrtarm64"
steam.mkdir(parents=True)
self.steam_log = self.root / "steam-args"
(steam / "steam").write_text("#!/bin/sh\nprintf '%s\\n' \"$*\" >> \"$STEAM_LOG\"\n")
(steam / "steam").chmod(0o755)
self.agent = self.bin / "droiddeck-agent"
self.agent.write_text(
"#!/bin/sh\n"
"n=$(cat \"$AGENT_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$AGENT_COUNT\"\n"
"i=0; last=0\n"
"for s in $AGENT_STATES; do i=$((i + 1)); last=$s; [ \"$i\" -eq \"$n\" ] && exit \"$s\"; done\n"
"exit \"$last\"\n")
self.agent.chmod(0o755)
def launch_game(self, states, focusable="769", extra=None):
xprop = self.bin / "xprop"
xprop.write_text("#!/bin/sh\necho 'GAMESCOPE_FOCUSABLE_APPS(CARDINAL) = %s'\n" % focusable)
xprop.chmod(0o755)
script = "nap() { :; }\nsteam_root=%s\n%s\nsteam_launch_game %s\n" % (
self.root / "steam", FUNCTIONS.replace("/usr/local/bin/droiddeck-agent", str(self.agent)), GAME)
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch),
PATH=str(self.bin) + os.pathsep + os.environ["PATH"], STEAM_LOG=str(self.steam_log),
AGENT_COUNT=str(self.root / "agent-count"), AGENT_STATES=states, **(extra or {}))
result = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=10)
self.assertEqual(0, result.returncode, result.stderr)
steam = self.steam_log.read_text().splitlines() if self.steam_log.exists() else []
restart = self.root / ".bl-restart-game"
return steam, restart.read_text().strip() if restart.exists() else None, result.stdout
def test_a_shortcut_that_stays_known_launches_once(self):
steam, restart, _ = self.launch_game("0")
self.assertEqual(["steam://rungameid/" + GAME], steam)
self.assertIsNone(restart)
self.assertEqual("9", (self.root / "agent-count").read_text().strip())
def test_a_shortcut_dropped_while_launching_restarts_steam_for_it(self):
steam, restart, out = self.launch_game("0 0 4")
self.assertEqual(["steam://rungameid/" + GAME, "-shutdown"], steam)
self.assertEqual(GAME, restart)
self.assertIn("dropped shortcut", out)
def test_a_shortcut_already_lost_restarts_steam_without_launching(self):
steam, restart, out = self.launch_game("4")
self.assertEqual(["-shutdown"], steam)
self.assertEqual(GAME, restart)
self.assertIn("lost shortcut", out)
def test_steam_is_restarted_only_once_for_the_same_game(self):
steam, restart, _ = self.launch_game("4")
self.assertEqual(GAME, restart)
(self.root / ".bl-restart-game").unlink()
self.steam_log.unlink()
(self.root / "agent-count").unlink()
steam, restart, out = self.launch_game("4")
self.assertEqual(["steam://rungameid/" + GAME], steam)
self.assertIsNone(restart)
self.assertIn("already restarted", out)
def test_a_ready_shortcut_allows_a_later_restart_again(self):
self.launch_game("4")
(self.root / ".bl-restart-game").unlink()
(self.root / "agent-count").unlink()
self.launch_game("0")
self.assertFalse((self.root / ".bl-restarted-for").exists())
def test_a_running_game_is_never_cut_off_by_a_restart(self):
steam, restart, _ = self.launch_game("0 4", focusable="769,3703311242")
self.assertEqual(["steam://rungameid/" + GAME], steam)
self.assertIsNone(restart)
steam, restart, _ = self.launch_game("4", focusable="769,3703311242")
self.assertIsNone(restart)
def test_the_open_launcher_does_not_count_as_a_running_game(self):
(self.launch / "epic-open").write_text("2702387189\n")
steam, restart, _ = self.launch_game("0 4", focusable="769,2702387189")
self.assertEqual(GAME, restart)
def test_the_launcher_without_its_steam_id_still_does_not_count_as_a_running_game(self):
(self.launch / "epic-open").write_text("1\n")
launcher = {"BL_EPIC_APP_ID": "2702387189"}
steam, restart, _ = self.launch_game("0 4", focusable="769,2702387189", extra=launcher)
self.assertEqual(GAME, restart)
for marker in (".bl-restart-game", ".bl-restarted-for", "agent-count"):
(self.root / marker).unlink(missing_ok=True)
steam, restart, _ = self.launch_game("4", focusable="769,2702387189,3703311242", extra=launcher)
self.assertIsNone(restart)
def test_steam_games_are_launched_without_watching(self):
steam, restart, _ = self.launch_game("3")
self.assertEqual(["steam://rungameid/" + GAME], steam)
self.assertIsNone(restart)
self.assertEqual("1", (self.root / "agent-count").read_text().strip())
def check_exits(self, listings, states, beats):
pgrep = self.bin / "pgrep"
pgrep.write_text(
"#!/bin/bash\n"
"n=$(cat \"$PGREP_COUNT\" 2>/dev/null || echo 0); n=$((n + 1)); echo $n > \"$PGREP_COUNT\"\n"
"IFS='|' read -r -a runs <<< \"$PGREP_RUNS\"\n"
"line=${runs[$((n - 1))]:-}\n"
"[ -n \"$line\" ] || exit 1\n"
"printf '%s\\n' \"$line\"\n")
pgrep.chmod(0o755)
script = "steam_root=%s\n%s\ndeclare -A _bl_ran=()\n_bl_exited=\n%s" % (
self.root / "steam", FUNCTIONS.replace("/usr/local/bin/droiddeck-agent", str(self.agent)),
"steam_check_exits\n" * beats)
env = dict(os.environ, HOME=str(self.root), BL_LAUNCH_DIR=str(self.launch),
PATH=str(self.bin) + os.pathsep + os.environ["PATH"], STEAM_LOG=str(self.steam_log),
AGENT_COUNT=str(self.root / "agent-count"), AGENT_STATES=states,
PGREP_COUNT=str(self.root / "pgrep-count"), PGREP_RUNS="|".join(listings))
result = subprocess.run(["bash", "-c", script], env=env, text=True, capture_output=True, timeout=10)
self.assertEqual(0, result.returncode, result.stderr)
steam = self.steam_log.read_text().splitlines() if self.steam_log.exists() else []
agent = self.root / "agent-count"
return steam, (self.root / ".bl-restart-lost").exists(), int(agent.read_text()) if agent.exists() else 0, result.stdout
RUNNING = "41 /root/.local/share/Steam/steamrtarm64/reaper SteamLaunch AppId=3333273269 -- /x/.droiddeck-launch.bat"
def test_a_shortcut_dropped_when_its_game_exits_restarts_steam_once_nothing_runs(self):
steam, marker, asked, out = self.check_exits([self.RUNNING, "", "", ""], "4", 3)
self.assertEqual(["-shutdown"], steam)
self.assertTrue(marker)
self.assertEqual(1, asked)
self.assertIn("3333273269", out)
def test_a_shortcut_still_listed_after_its_game_exits_is_left_alone(self):
steam, marker, asked, _ = self.check_exits([self.RUNNING, "", "", ""], "0", 4)
self.assertEqual([], steam)
self.assertFalse(marker)
self.assertEqual(1, asked)
def test_the_check_waits_a_quiet_beat_after_the_exit(self):
steam, _, asked, _ = self.check_exits([self.RUNNING, ""], "4", 2)
self.assertEqual([], steam)
self.assertEqual(0, asked)
def test_a_game_started_meanwhile_is_never_cut_off(self):
steam, marker, _, _ = self.check_exits([self.RUNNING, "", "", self.RUNNING], "4", 3)
self.assertEqual([], steam)
self.assertFalse(marker)
def test_steam_games_are_not_checked(self):
game = "41 /root/.local/share/Steam/steamrtarm64/reaper SteamLaunch AppId=1245620 -- /x/eldenring.exe"
steam, _, asked, _ = self.check_exits([game, "", "", ""], "4", 3)
self.assertEqual([], steam)
self.assertEqual(0, asked)
if __name__ == "__main__":
unittest.main()
+12
View File
@@ -147,6 +147,18 @@ class ShortcutsTest(unittest.TestCase):
self.assertEqual({'1': 'Favorites', '0': shortcuts.TAG}, entry['tags'])
self.assertEqual({'0': shortcuts.TAG}, shortcuts.merge(shortcuts.shortcut(self.game()), dict(shortcuts.shortcut(self.game()), tags={}), None, 0)[0]['tags'])
def test_a_copy_the_running_client_added_of_an_added_game_is_dropped(self):
self.run_writer(self.game())
path = self.config / 'shortcuts.vdf'
data = shortcuts.parse(path.read_bytes())['shortcuts']
live = dict(shortcuts.shortcut(self.game(appid=0x91234567)), tags={})
own = dict(shortcuts.shortcut(self.game(exe='Other.exe', appid=0x92345678)), tags={})
renamed = dict(shortcuts.shortcut(self.game(appid=0x93456789, name='My copy')), tags={})
data.update({'7': live, '8': own, '9': renamed})
path.write_bytes(shortcuts.write({'shortcuts': data}))
entries = self.run_writer(self.game())
self.assertEqual({APPID, 0x92345678, 0x93456789}, set(entries))
def test_a_damaged_record_is_started_over(self):
self.run_writer(self.game())
(self.config / shortcuts.RECORD).write_text('{not json')
+1 -1
View File
@@ -241,7 +241,7 @@ class CloudHooks(unittest.TestCase):
self.assertIn('bl_run ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertNotIn('exec ${BL_TASKSET:-} /usr/local/bin/droiddeck-game-env', sh)
self.assertIn('[ $? -eq 10 ] && BL_STORE_EXIT=1', compat.BL_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited "${BL_STORE_ARGS[@]}"', compat.BL_STORE_SETUP)
self.assertIn('droiddeck-store-launch --exited --code "$rc" "${BL_STORE_ARGS[@]}"', compat.BL_STORE_SETUP)
self.assertIn('exec "$@"', compat.BL_STORE_SETUP)