Files
DroidDeck/tools/linuxfs/overlay/usr/local/bin/droiddeck-login1
T
MaxsTechReview 2fe4d5303c 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.
2026-10-17 14:40:39 -04:00

271 lines
9.8 KiB
Python
Executable File

#!/usr/bin/python3
"""Steam's login1 sleep notifications, backed by DroidDeck's session pause.
Android owns device power. Suspend here pauses the guest through SessionService;
the app's Resume action thaws it and completes PrepareForSleep(false). Steam
must see this service before startup or it can stay black after its idle timer.
"""
import importlib.machinery
import importlib.util
import os
from pathlib import Path
import re
import subprocess
import sys
import threading
import uuid
import gi
gi.require_version("Gio", "2.0")
from gi.repository import Gio, GLib
NAME = "org.freedesktop.login1"
ROOT = "/org/freedesktop/login1"
INTERFACE = NAME + ".Manager"
UPOWER = "org.freedesktop.UPower"
UPOWER_ROOT = "/org/freedesktop/UPower"
NATIVE_PREPARE_MS = 1500
AGENT = Path(__file__).resolve().with_name("droiddeck-agent")
ASLEEP_WAIT = 6
INTROSPECTION = """
<node>
<interface name="org.freedesktop.login1.Manager">
<method name="Suspend"><arg type="b" direction="in"/></method>
<method name="SuspendWithFlags"><arg type="t" direction="in"/></method>
<method name="CanSuspend"><arg type="s" direction="out"/></method>
<property name="PreparingForSleep" type="b" access="read"/>
<signal name="PrepareForSleep"><arg type="b"/></signal>
</interface>
</node>
"""
UPOWER_INTROSPECTION = """
<node>
<interface name="org.freedesktop.UPower">
<method name="Suspend"/>
</interface>
</node>
"""
class LoginManager:
def __init__(self, bus, directory):
self.bus = bus
self.directory = Path(directory)
self.request = self.directory / "steam-sleep"
self.state = self.directory / "steam-sleep-state"
self.wake = self.directory / "steam-wake"
self.native_request = self.directory / "steam-native-sleep"
self.native_ready = self.directory / "steam-native-ready"
self.pending = None
self.timeout = None
self.preparation = None
info = Gio.DBusNodeInfo.new_for_xml(INTROSPECTION).interfaces[0]
self.registration = bus.register_object(ROOT, info, self.method, self.property, None)
upower_info = Gio.DBusNodeInfo.new_for_xml(UPOWER_INTROSPECTION).interfaces[0]
self.upower_registration = bus.register_object(UPOWER_ROOT, upower_info, self.method, None, None)
self.monitor = Gio.File.new_for_path(str(self.directory)).monitor_directory(Gio.FileMonitorFlags.NONE, None)
self.monitor.connect("changed", self.changed)
def property(self, connection, sender, path, interface, name):
if name == "PreparingForSleep":
return GLib.Variant("b", self.pending is not None)
return None
def notify(self, sleeping):
self.bus.emit_signal(None, ROOT, INTERFACE, "PrepareForSleep", GLib.Variant("(b)", (sleeping,)))
self.bus.emit_signal(None, ROOT, "org.freedesktop.DBus.Properties", "PropertiesChanged",
GLib.Variant("(sa{sv}as)", (INTERFACE, {
"PreparingForSleep": GLib.Variant("b", sleeping),
}, [])))
print("== login1: " + ("pausing the session" if sleeping else "session resumed"), flush=True)
def method(self, connection, sender, path, interface, name, args, reply):
if name == "CanSuspend":
reply.return_value(GLib.Variant("(s)", ("yes",)))
elif name in ("Suspend", "SuspendWithFlags"):
print("== login1: %s.%s asked by %s" % (interface.rsplit(".", 1)[-1], name, sender), flush=True)
if self.pending:
reply.return_dbus_error(NAME + ".OperationInProgress", "The session is already pausing")
return
self.pending = uuid.uuid4().hex
self.notify(True)
reply.return_value(None)
self.bus.flush(None, self.publish_after_flush, self.pending)
def publish_after_flush(self, connection, result, token):
try:
connection.flush_finish(result)
except GLib.Error as error:
print("== login1: cannot complete suspend handshake: " + str(error), file=sys.stderr)
self.resume()
return
if self.pending == token:
self.publish(self.request)
def publish(self, request):
self.check_state()
if self.pending is None:
return False
try:
staged = request.with_suffix(".tmp")
staged.write_text(self.pending + "\n")
staged.replace(request)
self.timeout = GLib.timeout_add_seconds(5, self.check_ack)
except OSError as error:
print("== login1: cannot request pause: " + str(error), file=sys.stderr)
self.resume()
return False
def prepare_native(self):
try:
token = self.native_request.read_text().strip()
self.native_request.unlink(missing_ok=True)
except OSError:
return
if not re.fullmatch(r"[a-f0-9]{32}", token) or self.pending is not None:
return
if self.read_state() == token + ":awake":
return
self.pending = token
self.notify(True)
self.bus.flush(None, self.prepare_after_flush, token)
def prepare_after_flush(self, connection, result, token):
try:
connection.flush_finish(result)
except GLib.Error as error:
print("== login1: cannot prepare native sleep: " + str(error), file=sys.stderr)
self.resume()
return
self.check_state()
if self.pending == token:
self.preparation = GLib.timeout_add(NATIVE_PREPARE_MS, self.finish_preparation, token)
def finish_preparation(self, token):
self.preparation = None
if self.pending == token:
self.publish(self.native_ready)
return False
def changed(self, monitor, file, other, event):
if file.get_basename() == self.native_request.name or (other and other.get_basename() == self.native_request.name):
self.prepare_native()
if file.get_basename() == self.wake.name or (other and other.get_basename() == self.wake.name):
if self.wake.exists():
self.wake.unlink(missing_ok=True)
self.woken()
if file.get_basename() == self.state.name or (other and other.get_basename() == self.state.name):
self.check_state()
def read_state(self):
try:
return self.state.read_text().strip()
except OSError:
return ""
def check_state(self):
if self.pending and self.read_state() == self.pending + ":awake":
self.resume()
def check_ack(self):
self.timeout = None
if self.pending and self.read_state() != self.pending + ":paused":
self.request.unlink(missing_ok=True)
self.native_ready.unlink(missing_ok=True)
self.resume()
return False
def woken(self):
if self.pending is not None:
self.resume(force=True)
return
threading.Thread(target=lambda: GLib.idle_add(self.replay_unless_awake, steam_asleep()), daemon=True).start()
def replay_unless_awake(self, asleep):
if asleep is False and self.pending is None:
print("== login1: Steam is awake; no sleep/wake replay", flush=True)
return False
self.resume(force=True)
return False
def resume(self, force=False):
if self.pending is None:
if force:
self.notify(True)
self.bus.flush(None, self.finish_recovery, None)
return
self.pending = None
if self.preparation is not None:
GLib.source_remove(self.preparation)
self.preparation = None
if self.timeout is not None:
GLib.source_remove(self.timeout)
self.timeout = None
self.notify(False)
def finish_recovery(self, connection, result, _data):
try:
connection.flush_finish(result)
except GLib.Error as error:
print("== login1: cannot flush wake recovery: " + str(error), file=sys.stderr)
if self.pending is None:
self.notify(False)
def steam_asleep():
try:
code = subprocess.run([str(AGENT), "--steam-asleep"], stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL, timeout=ASLEEP_WAIT).returncode
except (OSError, subprocess.SubprocessError):
return None
return {0: True, 5: False}.get(code)
def load_netmanager():
path = Path(__file__).resolve().with_name("droiddeck-netmanager")
loader = importlib.machinery.SourceFileLoader("droiddeck_netmanager", str(path))
spec = importlib.util.spec_from_loader(loader.name, loader)
module = importlib.util.module_from_spec(spec)
loader.exec_module(module)
return module
def main():
directory = os.environ.get("BL_LAUNCH_DIR")
if not directory or not Path(directory).is_dir():
sys.exit("droiddeck-login1: no DroidDeck session directory")
ready = Path(directory) / "steam-sleep-ready"
ready.unlink(missing_ok=True)
loop = GLib.MainLoop()
manager = []
acquired_names = set()
def connected(bus, name):
if not manager:
manager.append(LoginManager(bus, directory))
def acquired(bus, name):
acquired_names.add(name)
if acquired_names == {NAME, UPOWER}:
ready.write_text("ready\n")
def lost(bus, name):
ready.unlink(missing_ok=True)
loop.quit()
owners = [Gio.bus_own_name(Gio.BusType.SYSTEM, name, Gio.BusNameOwnerFlags.NONE, connected, acquired, lost)
for name in (NAME, UPOWER)]
if "--with-netmanager" in sys.argv[1:]:
owners.append(load_netmanager().own(loop))
try:
loop.run()
finally:
ready.unlink(missing_ok=True)
for owner in owners:
Gio.bus_unown_name(owner)
if __name__ == "__main__":
main()