Skip to content

Commit

Permalink
Update launcher and packaging (#95)
Browse files Browse the repository at this point in the history
* umu_consts: update logic

* umu_plugins: delete enable_flatpak function

- For now, execute the launcher within the Flatpak sandbox. Breaking out the sandbox via flatpak-spawn is discouraged and breaks Flatpak's security model. It may also require other Flatpak applications to make additional changes in their manifest, which they may not be supportive to do for this practice. Unless necessary or proven to be very problematic, execute within the Flatpak sandbox

* umu_util: only copy umu_version.json and reaper

- To run games, the only required files to be in the user's home directory is the runtime platform and the reaper executable. The launcher files will remain in their system path that's been configured in build time.

* Update Makefile to install umu-launcher in system path

- The directory /usr/share/steam/compatibilitytool.d is an official system path supported by Valve's Steam client to search for community-based tools and to use them as compatibility tools to run games. Instead of copying the umu-launcher directory to ~/.local/share/Steam/compatibilitytool.d we can install it in its system path. That way, there's less to copy/remove and the files there can be managed by the distribution's package manager

* umu_util: don't pass compatibilitytools.d path

- The system path compatibilitytools.d directory will be used instead

* umu_consts: delete enum

* umu_run: update debug message

* flatpak: limit access to ~/.local/share/Steam

- The launcher only needs this directory to write Proton. For now, just limit access to this directory instead of exposing user's entire ~/.local/share

* umu-launcher: hide umu-launcher compatibility tool

- For now, hide this tool in the Steam client until the umu runtime platform is released.

- Related to #4

* Update tests

* umu_plugins: remove enable_reaper

* umu_run: add reaper to command list

* umu_util: don't copy reaper

- Reaper can be executed directly from the system path. All we need in the home directory is the runtime platform

* umu_util: update launcher and runner

- While those files will not be copied anymore, we still need to update them in umu_version.json if we want the configuration files to be in sync

* Update tests

* umu_test: update tests

- Update the tests to account for the launcher files, umu-launcher and reaper not being copied to the home directory. Those files will remain in their system path defined at buid time, which makes the umu_version.json in ~/.local/share/umu and the runtime platform the only files in ~/.local/share/umu.
  • Loading branch information
R1kaB3rN authored Apr 25, 2024
1 parent 3db9762 commit ca897f2
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 622 deletions.
10 changes: 5 additions & 5 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ $(OBJDIR)/.build-umu-launcher: | $(OBJDIR)
umu-launcher: $(OBJDIR)/.build-umu-launcher

umu-launcher-bin-install: umu-launcher
install -d $(DESTDIR)$(DATADIR)/$(INSTALLDIR)/umu-launcher
install -Dm 755 $(OBJDIR)/$(<)-run $(DESTDIR)$(DATADIR)/$(INSTALLDIR)/umu-launcher/umu-run
install -d $(DESTDIR)$(DATADIR)/steam/compatibilitytools.d/umu-launcher
install -Dm 755 $(OBJDIR)/$(<)-run $(DESTDIR)$(DATADIR)/steam/compatibilitytools.d/umu-launcher/umu-run

umu-launcher-dist-install:
$(info :: Installing umu-launcher )
install -d $(DESTDIR)$(DATADIR)/$(INSTALLDIR)/umu-launcher
install -Dm 644 umu/umu-launcher/compatibilitytool.vdf -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)/umu-launcher
install -Dm 644 umu/umu-launcher/toolmanifest.vdf -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)/umu-launcher
install -d $(DESTDIR)$(DATADIR)/steam/compatibilitytools.d/umu-launcher
install -Dm 644 umu/umu-launcher/compatibilitytool.vdf -t $(DESTDIR)$(DATADIR)/steam/compatibilitytools.d/umu-launcher
install -Dm 644 umu/umu-launcher/toolmanifest.vdf -t $(DESTDIR)$(DATADIR)/steam/compatibilitytools.d/umu-launcher

umu-launcher-install: umu-launcher-dist-install umu-launcher-bin-install

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ finish-args:
- --filesystem=xdg-data/applications:rw
- --filesystem=~/.steam:rw
- --filesystem=~/Games:rw
- --filesystem=~/.local/share:rw
- --filesystem=~/.local/share/Steam:rw
- --filesystem=~/.var/app/com.valvesoftware.Steam:rw
- --filesystem=~/.var/app/org.openwinecomponents.umu.umu-launcher:rw
- --filesystem=xdg-documents
Expand Down
1 change: 1 addition & 0 deletions umu/umu-launcher/toolmanifest.vdf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"commandline" "/umu-run %verb%"
"version" "2"
"use_tool_subprocess_reaper" "1"
"unlisted" "1"
"compatmanager_layer_name" "umu-launcher"
}
13 changes: 2 additions & 11 deletions umu/umu_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ class Color(Enum):
DEBUG = "\u001b[35m"


class MODE(Enum):
"""Represent the permission to apply to a file."""

USER_RW = 0o0644
USER_RWX = 0o0755


SIMPLE_FORMAT = f"%(levelname)s: {Color.BOLD.value}%(message)s{Color.RESET.value}"

DEBUG_FORMAT = f"%(levelname)s [%(module)s.%(funcName)s:%(lineno)s]:{Color.BOLD.value}%(message)s{Color.RESET.value}" # noqa: E501
Expand All @@ -40,10 +33,8 @@ class MODE(Enum):
"getnativepath",
}

FLATPAK_ID = environ.get("FLATPAK_ID") if environ.get("FLATPAK_ID") else ""
FLATPAK_ID = environ.get("FLATPAK_ID") or ""

FLATPAK_PATH: Path = Path(environ.get("XDG_DATA_HOME"), "umu") if FLATPAK_ID else None

UMU_LOCAL: Path = (
FLATPAK_PATH if FLATPAK_PATH else Path.home().joinpath(".local", "share", "umu")
)
UMU_LOCAL: Path = FLATPAK_PATH or Path.home().joinpath(".local", "share", "umu")
44 changes: 0 additions & 44 deletions umu/umu_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,6 @@ def enable_steam_game_drive(env: Dict[str, str]) -> Dict[str, str]:
return env


def enable_reaper(env: Dict[str, str], command: List[str], local: Path) -> List[str]:
"""Enable Reaper to monitor and keep track of descendent processes."""
command.extend(
[
local.joinpath("reaper").as_posix(),
"UMU_ID=" + env["UMU_ID"],
"--",
]
)

return command


def enable_zenity(command: str, opts: List[str], msg: str) -> int:
"""Execute the command and pipe the output to Zenity.
Expand Down Expand Up @@ -195,34 +182,3 @@ def enable_zenity(command: str, opts: List[str], msg: str) -> int:
zenity_proc.stdin.close()

return zenity_proc.wait()


def enable_flatpak(
env: Dict[str, str], local: Path, command: List[str], verb: str, opts: List[str]
) -> List[str]:
"""Run umu in a Flatpak environment."""
bin: str = which("flatpak-spawn")

if not bin:
err: str = "flatpak-spawn not found\numu will fail to run the executable"
raise RuntimeError(err)

command.append(bin, "--host")
for key, val in env.items():
command.append(f"--env={key}={val}")

enable_reaper(env, command, local)

command.extend([local.joinpath("umu").as_posix(), "--verb", verb, "--"])
command.extend(
[
Path(env.get("PROTONPATH")).joinpath("proton").as_posix(),
verb,
env.get("EXE"),
]
)

if opts:
command.extend([*opts])

return command
22 changes: 14 additions & 8 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from umu_plugins import (
enable_steam_game_drive,
set_env_toml,
enable_reaper,
)


Expand Down Expand Up @@ -235,7 +234,11 @@ def set_env(


def build_command(
env: Dict[str, str], local: Path, command: List[str], opts: List[str] = None
env: Dict[str, str],
local: Path,
root: Path,
command: List[str],
opts: List[str] = None,
) -> List[str]:
"""Build the command to be executed."""
verb: str = env["PROTON_VERB"]
Expand All @@ -253,8 +256,13 @@ def build_command(
err: str = "The following file was not found in PROTONPATH: proton"
raise FileNotFoundError(err)

enable_reaper(env, command, local)

command.extend(
[
root.joinpath("reaper").as_posix(),
f"UMU_ID={env.get('UMU_ID')}",
"--",
]
)
command.extend([local.joinpath("umu").as_posix(), "--verb", verb, "--"])
command.extend(
[
Expand Down Expand Up @@ -322,9 +330,7 @@ def main() -> int: # noqa: D103
if FLATPAK_PATH and root == Path("/app/share/umu"):
log.debug("Flatpak environment detected")
log.debug("FLATPAK_ID: %s", FLATPAK_ID)
log.debug(
"The following path will be used to persist the runtime: %s", FLATPAK_PATH
)
log.debug("Persisting the runtime at: %s", FLATPAK_PATH)

# Setup the launcher and runtime files
# An internet connection is required for new setups
Expand Down Expand Up @@ -380,7 +386,7 @@ def main() -> int: # noqa: D103
executor.shutdown()

# Run
build_command(env, UMU_LOCAL, command, opts)
build_command(env, UMU_LOCAL, root, command, opts)
log.debug("%s", command)

return run(command, check=False).returncode
Expand Down
Loading

0 comments on commit ca897f2

Please sign in to comment.