From 34640e83cbed0c4cc8275fe07ead3c747079f56c Mon Sep 17 00:00:00 2001 From: xXJsonDeruloXx Date: Tue, 29 Sep 2026 13:17:09 -0400 Subject: [PATCH] fix: add Flathub without a download, log store commands, keep Electron apps on X11 under gamescope --- .../launcher/runtime/BwrapSpawner.kt | 2 ++ .../launcher/runtime/FlatpakManager.kt | 15 +++++++++++++ docs/development/flatpak.md | 14 ++++++++---- .../usr/local/bin/bannerlator-flatpak-run | 11 ++++++---- .../usr/local/bin/bannerlator-flatpak-setup | 22 +++++++++++++++++-- 5 files changed, 54 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt index 6083f55d23..c34e325561 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/BwrapSpawner.kt @@ -271,6 +271,8 @@ object BwrapSpawner { val binds = ArrayList() val paths = libs.map { lib -> "$PRELOAD_DIR/${lib.substringAfterLast('/')}".also { binds.add(Bind(rootfs + lib, it)) } } env["LD_PRELOAD"] = (paths + listOfNotNull(env["LD_PRELOAD"]?.takeIf { it.isNotBlank() })).joinToString(":") + // Not through ZYPAK_LD_PRELOAD to Chromium's children: the session shim's stat hooks then + // hide the setuid bit zypak fakes on chrome-sandbox, and Chromium refuses to start. // The controllers: FAKE_EVDEV_DIR is /dev/input, the rings beside it in /dev. env["FAKE_EVDEV_DIR"]?.let { File(it).parent }?.let { dev -> binds.addAll(bindsFor(session, rootfs, dev, dev)) diff --git a/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt b/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt index 3f8ec9053c..c83102647b 100644 --- a/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt +++ b/app/src/main/java/com/droiddeck/launcher/runtime/FlatpakManager.kt @@ -96,6 +96,21 @@ object FlatpakManager { * [fakeRoot] is for the package tools, which refuse any uid but 0. */ private fun runGuest(context: Context, argv: List, fakeRoot: Boolean, onLine: (String) -> Unit): Int { + // Everything the command says, beside the session logs (Download/DroidDeck), so a store + // problem can be handed over like a session's: flatpak-setup.log, flatpak-install.log... + val log = try { + val name = "flatpak-" + (argv.getOrNull(2)?.takeIf { argv.getOrNull(1) == HELPER } ?: "setup") + ".log" + File(LinuxRuntime.debugLogDir().apply { mkdirs() }, name).printWriter() + } catch (e: Exception) { null } + log?.println("== ${java.util.Date()} ${argv.joinToString(" ")}") + try { + return runGuestLogged(context, argv, fakeRoot) { line -> log?.println(line); log?.flush(); onLine(line) } + } finally { + log?.close() + } + } + + private fun runGuestLogged(context: Context, argv: List, fakeRoot: Boolean, onLine: (String) -> Unit): Int { val root = LinuxRuntime.rootDir(context) LinuxRuntime.writeAccounts(context) SessionFiles.stage(context, root) diff --git a/docs/development/flatpak.md b/docs/development/flatpak.md index 1fb87095b0..07fc719522 100644 --- a/docs/development/flatpak.md +++ b/docs/development/flatpak.md @@ -13,8 +13,12 @@ would therefore reinstall about a hundred packages, Mesa among them, over the ru Turnip build, and run every hook in the image, mkinitcpio included. So pacman, with a database of its own under `/var/cache/droiddeck-flatpak`, only downloads the nine packages Flatpak adds to this image and checks their signatures against the Arch Linux ARM keyring. -The script then unpacks them without hooks and checks what the binaries link. Flathub is added -as a per-user remote. +The script then unpacks them without hooks and checks what the binaries link. Libraries that +the Desktop package normally brings (PyGObject, json-glib, fuse3 and others) are fetched too, +but only when their files are missing. Flathub is added as a per-user remote from a copy of +its `.flatpakrepo` carried in the script, so that step needs no network. Every store command +writes its output to `Download/DroidDeck/flatpak-.log`, next to the session logs. The +setup script also puts Flatpak's own error text in the failure message the app shows. ## bubblewrap without namespaces @@ -56,8 +60,10 @@ The spawner also adds what the rootfs gives its own programs: ## Running apps The front end starts an app as a run-mode session of `bannerlator-flatpak-run `, full -screen under gamescope. Under gamescope it passes `--nosocket=wayland --socket=x11`. Otherwise -Flatpak finds the app compositor's `wayland-0` and the window opens behind gamescope. The +screen under gamescope. Under gamescope it passes `--nosocket=wayland --socket=x11` and sets +`XDG_SESSION_TYPE=x11`. Otherwise Flatpak finds the app compositor's `wayland-0` and the window +opens behind gamescope. gamescope's own Wayland socket is no alternative: Chromium on Wayland +asks the render node it names for a DRM version, which KGSL cannot give, and aborts. The launcher also starts a session bus when there is none. On the Linux desktop, the apps' exported menu entries appear in the LXQt menu. While the desktop is composited by pixman, games are wrapped through `droiddeck-gpu` like the rootfs's own. diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run index d7ffb149b3..203769d13c 100644 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-run @@ -7,14 +7,17 @@ case ":${XDG_DATA_DIRS:-}:" in *"/flatpak/exports/share:"*) ;; *) export XDG_DATA_DIRS=$HOME/.local/share/flatpak/exports/share:${XDG_DATA_DIRS:-/usr/local/share:/usr/share} ;; esac -# gamescope manages X windows. Flatpak would hand an app the app's own Wayland socket instead (it -# finds wayland-0 in the runtime directory even with WAYLAND_DISPLAY unset), and the window would -# open behind gamescope - or not at all, with SDL told to use X11. So under gamescope - a program's -# session (BL_INSIDE), or droiddeck-gpu from the desktop (GAMESCOPE_WAYLAND_DISPLAY) - X11 only. +# Under gamescope - a program's session (BL_INSIDE), or droiddeck-gpu from the desktop +# (GAMESCOPE_WAYLAND_DISPLAY) - windows have to reach gamescope's X server. Flatpak would hand an +# app wayland-0 (it finds it in the runtime directory even with WAYLAND_DISPLAY unset) and the +# window would open behind gamescope. gamescope's own Wayland socket is no way out: Chromium on +# Wayland asks the render node it names for its DRM version, which KGSL cannot answer, and exits. +# The session is X11 as far as an app can tell; Electron picks its platform from that. # Its own flatpak options (--branch, --command, from a menu entry) come first, then the app id. socket=() if [ -n "${BL_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then unset WAYLAND_DISPLAY + export XDG_SESSION_TYPE=x11 socket=(--nosocket=wayland --socket=x11) fi echo "== flatpak run ${socket[*]} $*" diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-setup b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-setup index e0c38a774a..9020b38fe1 100644 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-setup +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-flatpak-setup @@ -98,6 +98,24 @@ python3 -c 'import gi; gi.require_version("Flatpak", "1.0"); from gi.repository step "Adding Flathub" export FLATPAK_BWRAP=/usr/local/bin/bannerlator-bwrap -flatpak remote-add --user --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo 2>&1 \ - || fail "could not add the Flathub remote" +# Flathub's descriptor - its URL and the key its commits are signed with - is carried here rather +# than fetched: adding the remote then needs no network, and a descriptor that did not arrive +# whole cannot be what failed. Flathub's own copy: https://dl.flathub.org/repo/flathub.flatpakrepo +cat > "$WORK/flathub.flatpakrepo" <<'REPO' +[Flatpak Repo] +Title=Flathub +Url=https://dl.flathub.org/repo/ +Homepage=https://flathub.org/ +Comment=Central repository of Flatpak applications +Description=Central repository of Flatpak applications +Icon=https://dl.flathub.org/repo/logo.svg +GPGKey=mQINBFlD2sABEADsiUZUOYBg1UdDaWkEdJYkTSZD68214m8Q1fbrP5AptaUfCl8KYKFMNoAJRBXn9FbE6q6VBzghHXj/rSnA8WPnkbaEWR7xltOqzB1yHpCQ1l8xSfH5N02DMUBSRtD/rOYsBKbaJcOgW0K21sX+BecMY/AI2yADvCJEjhVKrjR9yfRX+NQEhDcbXUFRGt9ZT+TI5yT4xcwbvvTu7aFUR/dH7+wjrQ7lzoGlZGFFrQXSs2WI0WaYHWDeCwymtohXryF8lcWQkhH8UhfNJVBJFgCY8Q6UHkZG0FxMu8xnIDBMjBmSZKwKQn0nwzwM2afskZEnmNP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udCF76meE+6N2u/T+RYZ7fP1QMEtNZNmYDOfA6sViuPDfQSHLNbauJBo/n1sRYAsL5mcG22UDchJrlKvmK3EOADCQg+myrm8006LltubNB4wWNzHDJ0Ls2JGzQZCd/xGyVmUiidCBUrD537WdknOYE4FD7P0cHaM9brKJ/M8LkEH0zUlo73bY4XagbnCqve6PvQb5G2Z55qhWphd6f4B6DGed86zJEa/RhS +REPO +if ! flatpak remote-list --user --columns=name 2>/dev/null | grep -qx flathub; then + out=$(flatpak remote-add --user --if-not-exists flathub "$WORK/flathub.flatpakrepo" 2>&1) + rc=$? + echo "$out" + # What Flatpak said goes up with the failure, so the app can show it rather than a guess. + [ $rc -eq 0 ] || fail "could not add the Flathub remote: $(echo "$out" | grep -v '^[[:space:]]*$' | tail -1)" +fi echo "== DONE $(flatpak --version)"