Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Flatpak support #82

Merged
merged 13 commits into from
Apr 17, 2024
21 changes: 17 additions & 4 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ MANDIR := $(DATADIR)/man

DESTDIR ?=
USERINSTALL ?= xfalse
FLATPAK ?= xfalse


.PHONY: all
ifeq ($(FLATPAK), xtrue)
all: version reaper umu umu-launcher
else
all: version reaper umu umu-docs umu-launcher
endif

.PHONY: install
ifeq ($(USERINSTALL), xtrue)
Expand Down Expand Up @@ -79,16 +84,25 @@ umu-dist-install:
install -Dm 644 umu/umu_dl_util.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)
install -Dm 644 umu/umu_log.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)
install -Dm 644 umu/umu_plugins.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)
install -Dm 755 umu/umu_run.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)
install -Dm 755 umu/umu_run.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)
install -Dm 644 umu/umu_util.py -t $(DESTDIR)$(DATADIR)/$(INSTALLDIR)

ifeq ($(FLATPAK), xtrue)
umu-install: version-install umu-dist-install umu-bin-install
else
umu-install: version-install umu-dist-install umu-docs-install umu-bin-install
endif

ifeq ($(FLATPAK), xtrue)
UMU_LAUNCHER_COMMAND = org.openwinecomponents.umu.launcher
else
UMU_LAUNCHER_COMMAND = $(DATADIR)/$(INSTALLDIR)/umu_run.py
endif

# umu-launcher is separate to allow control over installing the bin target
$(OBJDIR)/.build-umu-launcher: | $(OBJDIR)
$(info :: Building umu-launcher )
sed 's|##INSTALL_PATH##|$(DATADIR)/$(INSTALLDIR)|g' umu/umu-launcher/umu-run.in > $(OBJDIR)/umu-launcher-run
sed 's|##INSTALL_PATH##|$(UMU_LAUNCHER_COMMAND)|g' umu/umu-launcher/umu-run.in > $(OBJDIR)/umu-launcher-run
touch $(@)

.PHONY: umu-launcher
Expand All @@ -104,8 +118,7 @@ umu-launcher-dist-install:
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

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


$(OBJDIR)/.build-reaper: | $(OBJDIR)
Expand Down
18 changes: 11 additions & 7 deletions packaging/flatpak/org.openwinecomponents.umu.launcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ finish-args:
- --talk-name=org.kde.StatusNotifierWatcher
# Required for bwrap to work
- --talk-name=org.freedesktop.portal.Background
# --- Steam ---
# Pressure Vessel
# See https://github.com/flathub/com.valvesoftware.Steam/commit/0538256facdb0837c33232bc65a9195a8a5bc750
- --env=XDG_DATA_DIRS=/app/share:/usr/lib/extensions/vulkan/share:/usr/share:/usr/share/runtime/share:/run/host/user-share:/run/host/share:/usr/lib/pressure-vessel/overrides/share

add-extensions:
org.freedesktop.Platform.Compat.i386:
Expand Down Expand Up @@ -143,14 +147,14 @@ modules:
- name: umu-run
buildsystem: simple
build-commands:
- install -D umu-run-cli /app/bin/umu-run
- install -D umu-launcher.tar.gz /app/share/umu/umu-launcher.tar.gz
- |
git submodule update --init --recursive
./configure.sh --prefix=/app
make FLATPAK=xtrue install
sources:
- type: file
path: umu-run-cli
- type: file
url: https://github.com/Open-Wine-Components/umu-launcher/releases/download/0.1-RC3/umu-launcher.tar.gz
sha256: e25c4dd0636d04e7c8c534cf3c5bbdca5ae0d49f146ee8395306174700899952
- type: git
url: https://github.com/Open-Wine-Components/umu-launcher.git
branch: flatpak

- name: platform-bootstrap
buildsystem: simple
Expand Down
2 changes: 1 addition & 1 deletion umu/umu-launcher/umu-run.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env sh
##INSTALL_PATH##/umu_run.py "$@"
##INSTALL_PATH## "$@"

21 changes: 13 additions & 8 deletions umu/umu_consts.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from enum import Enum
from pathlib import Path
from os import environ


class Color(Enum):
Expand All @@ -13,16 +14,19 @@ 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

CONFIG = "umu_version.json"

UMU_LOCAL: Path = Path.home().joinpath(".local", "share", "umu")

UMU_CACHE: Path = Path.home().joinpath(".cache", "umu")

STEAM_COMPAT: Path = Path.home().joinpath(
".local", "share", "Steam", "compatibilitytools.d"
)
Expand All @@ -36,9 +40,10 @@ class Color(Enum):
"getnativepath",
}

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

class MODE(Enum):
"""Represent the permission to apply to a file."""
FLATPAK_PATH: Path = Path(environ.get("XDG_DATA_HOME"), "umu") if FLATPAK_ID else None

USER_RW = 0o0644
USER_RWX = 0o0755
UMU_LOCAL: Path = (
FLATPAK_PATH if FLATPAK_PATH else Path.home().joinpath(".local", "share", "umu")
)
31 changes: 31 additions & 0 deletions umu/umu_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,3 +195,34 @@ 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: 20 additions & 2 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,29 @@
from argparse import ArgumentParser, Namespace, RawTextHelpFormatter
from pathlib import Path
from typing import Dict, Any, List, Set, Union, Tuple
from umu_plugins import enable_steam_game_drive, set_env_toml, enable_reaper
from re import match
from subprocess import run
from umu_dl_util import get_umu_proton
from umu_consts import PROTON_VERBS, DEBUG_FORMAT, STEAM_COMPAT, UMU_LOCAL
from umu_util import setup_umu
from umu_log import log, console_handler, CustomFormatter
from logging import INFO, WARNING, DEBUG
from errno import ENETUNREACH
from threading import Thread
from socket import AF_INET, SOCK_DGRAM, socket
from pwd import getpwuid
from umu_consts import (
PROTON_VERBS,
DEBUG_FORMAT,
STEAM_COMPAT,
UMU_LOCAL,
FLATPAK_PATH,
FLATPAK_ID,
)
from umu_plugins import (
enable_steam_game_drive,
set_env_toml,
enable_reaper,
)


def parse_args() -> Union[Namespace, Tuple[str, List[str]]]: # noqa: D103
Expand Down Expand Up @@ -304,6 +315,13 @@ def main() -> int: # noqa: D103

log.debug("Arguments: %s", args)

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
)

# Setup the launcher and runtime files
# An internet connection is required for new setups
try:
Expand Down
2 changes: 1 addition & 1 deletion umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ def test_update_umu(self):
# Subtract one because a symbolic link is dynamically created
self.assertEqual(
num_share,
num_local - 1,
num_local,
"Expected .local/share/Steam/compatibilitytools.d/umu-launcher"
"and /usr/share/umu/umu-launcher to contain same files",
)
Expand Down
10 changes: 0 additions & 10 deletions umu/umu_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,6 @@ def _install_umu(
root.joinpath("umu-launcher"),
steam_compat.joinpath("umu-launcher"),
)
steam_compat.joinpath("umu-launcher", "umu-run").symlink_to(
"../../../umu/umu_run.py"
)

# Runtime platform
setup_runtime(json)
Expand Down Expand Up @@ -336,9 +333,6 @@ def _update_umu(
steam_compat.joinpath("umu-launcher"),
)

steam_compat.joinpath("umu-launcher", "umu-run").symlink_to(
"../../../umu/umu_run.py"
)
log.console(f"Restored umu-launcher to {val}")
elif steam_compat.joinpath("umu-launcher").is_dir() and val != runner:
# Update
Expand All @@ -350,10 +344,6 @@ def _update_umu(
steam_compat.joinpath("umu-launcher"),
)

steam_compat.joinpath("umu-launcher", "umu-run").symlink_to(
"../../../umu/umu_run.py"
)

json_local["umu"]["versions"]["runner"] = val

if thread:
Expand Down