mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 20:45:43 +00:00
fix(flatpak): give apps with host access the home folder and its ROMs mount
This commit is contained in:
1 parent
8a27ea841c
commit
fe55ec24c1
3 files changed
+47
-8
No files matched your search
@@ -69,7 +69,10 @@ screen under gamescope. Under gamescope it passes `--nosocket=wayland --socket=x
|
||||
`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
|
||||
launcher also starts a session bus when there is none. Flatpak's `host` permission skips `/root`,
|
||||
since a desktop's homes live under `/home`, but the session's home is `/root`. An app granted `host`
|
||||
and not `home` is therefore also given `home` in the same mode, which brings in the session's mounts
|
||||
there, such as `/root/ROMs`. On the Linux desktop, the apps' exported
|
||||
menu entries appear in Plasma's launcher. Games are wrapped through `droiddeck-gpu` like the
|
||||
rootfs's own, since the desktop composites in software.
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ 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
|
||||
socket=()
|
||||
options=()
|
||||
if [ -n "${DD_INSIDE:-}" ] || [ -n "${GAMESCOPE_WAYLAND_DISPLAY:-}" ]; then
|
||||
unset WAYLAND_DISPLAY
|
||||
export XDG_SESSION_TYPE=x11
|
||||
socket=(--nosocket=wayland --socket=x11)
|
||||
options=(--nosocket=wayland --socket=x11)
|
||||
fi
|
||||
app=
|
||||
for arg in "$@"; do
|
||||
@@ -20,8 +20,15 @@ gpu=("${BASH_SOURCE[0]%/*}/droiddeck-game-gpu")
|
||||
location=
|
||||
[ -n "$app" ] && location=$(flatpak info --show-location "$app" 2>/dev/null)
|
||||
[ -n "$location" ] && gpu+=(--for "$location/files")
|
||||
echo "== flatpak run ${socket[*]} $*"
|
||||
filesystems=
|
||||
[ -n "$location" ] && filesystems=$(flatpak info --show-permissions "$app" 2>/dev/null | sed -n 's/^filesystems=//p')
|
||||
case ";$filesystems" in
|
||||
*";home;"*|*";home:"*) ;;
|
||||
*";host:ro;"*) options+=(--filesystem=home:ro) ;;
|
||||
*";host;"*|*";host:"*) options+=(--filesystem=home) ;;
|
||||
esac
|
||||
echo "== flatpak run ${options[*]} $*"
|
||||
if [ -z "${DBUS_SESSION_BUS_ADDRESS:-}" ] && command -v dbus-run-session >/dev/null 2>&1; then
|
||||
exec "${gpu[@]}" -- dbus-run-session -- flatpak run "${socket[@]}" "$@"
|
||||
exec "${gpu[@]}" -- dbus-run-session -- flatpak run "${options[@]}" "$@"
|
||||
fi
|
||||
exec "${gpu[@]}" -- flatpak run "${socket[@]}" "$@"
|
||||
exec "${gpu[@]}" -- flatpak run "${options[@]}" "$@"
|
||||
@@ -30,9 +30,16 @@ class GameGpuLaunchersTest(unittest.TestCase):
|
||||
% (" ".join(KEYS), self.out))
|
||||
self.report.chmod(0o755)
|
||||
flatpak = self.tools / "flatpak"
|
||||
self.permissions = self.tmp / "permissions"
|
||||
self.args = self.tmp / "args"
|
||||
flatpak.write_text("#!/bin/sh\n"
|
||||
"if [ \"$1\" = info ]; then [ \"$3\" = org.example.App ] && echo %s; exit 0; fi\n"
|
||||
"exec %s\n" % (self.app, self.report))
|
||||
"if [ \"$1\" = info ]; then\n"
|
||||
" [ \"$3\" = org.example.App ] || exit 0\n"
|
||||
" if [ \"$2\" = --show-permissions ]; then cat %s 2>/dev/null; else echo %s; fi\n"
|
||||
" exit 0\n"
|
||||
"fi\n"
|
||||
"printf '%%s\\n' \"$@\" > %s\n"
|
||||
"exec %s\n" % (self.permissions, self.app, self.args, self.report))
|
||||
flatpak.chmod(0o755)
|
||||
|
||||
def chromium(self):
|
||||
@@ -100,6 +107,28 @@ class GameGpuLaunchersTest(unittest.TestCase):
|
||||
def test_a_flatpak_without_the_game_setting_is_unchanged(self):
|
||||
self.assertEqual("sysmem", self.flatpak({"TU_DEBUG": "sysmem"})["TU_DEBUG"])
|
||||
|
||||
def flatpak_filesystems(self, granted):
|
||||
self.permissions.write_text("[Context]\nshared=network;ipc;\nfilesystems=%s\n" % granted)
|
||||
self.flatpak()
|
||||
return [a for a in self.args.read_text().splitlines() if a.startswith("--filesystem=")]
|
||||
|
||||
def test_host_access_reaches_the_home_folder_and_its_mounts(self):
|
||||
self.assertEqual(["--filesystem=home:ro"],
|
||||
self.flatpak_filesystems("host:ro;xdg-run/gamescope-0:ro;xdg-desktop:create;"))
|
||||
self.assertEqual(["--filesystem=home"], self.flatpak_filesystems("xdg-desktop;host;"))
|
||||
self.assertEqual(["--filesystem=home"], self.flatpak_filesystems("host:create;"))
|
||||
|
||||
def test_apps_without_host_access_or_with_their_own_home_grant_are_unchanged(self):
|
||||
self.assertEqual([], self.flatpak_filesystems("home:ro;host;"))
|
||||
self.assertEqual([], self.flatpak_filesystems("host;home;"))
|
||||
self.assertEqual([], self.flatpak_filesystems("host-os:ro;host-etc;xdg-download;"))
|
||||
self.assertEqual([], self.flatpak_filesystems(""))
|
||||
self.permissions.unlink()
|
||||
self.flatpak()
|
||||
args = self.args.read_text().splitlines()
|
||||
self.assertEqual(["--command=app", "org.example.App"], args[-2:])
|
||||
self.assertFalse([a for a in args if a.startswith("--filesystem=")])
|
||||
|
||||
def test_a_snap_gets_the_game_setting_unless_it_is_chromium(self):
|
||||
try:
|
||||
snap_run = runpy.run_path(str(BIN / "droiddeck-snap-run"))
|
||||
|
||||
Reference in new issue
Block a user