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
12 changes: 10 additions & 2 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,11 +84,14 @@ 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

# umu-launcher is separate to allow control over installing the bin target
$(OBJDIR)/.build-umu-launcher: | $(OBJDIR)
Expand Down
19 changes: 12 additions & 7 deletions packaging/flatpak/org.openwinecomponents.umu.launcher.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,13 @@ finish-args:
- --share=network
- --talk-name=org.freedesktop.Notifications
- --talk-name=org.kde.StatusNotifierWatcher
- --talk-name=org.freedesktop.Flatpak
# 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 +148,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 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: main
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't build since the changes are not merged in main, so will probably have to create another branch


- name: platform-bootstrap
buildsystem: simple
Expand Down
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
26 changes: 24 additions & 2 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,30 @@
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,
enable_flatpak,
)


def parse_args() -> Union[Namespace, Tuple[str, List[str]]]: # noqa: D103
Expand Down Expand Up @@ -239,6 +251,9 @@ def build_command(
err: str = "The following file was not found in PROTONPATH: proton"
raise FileNotFoundError(err)

if FLATPAK_PATH and Path(__file__).resolve().parent == Path("/app/share/umu"):
return enable_flatpak(env, local, command, env.get("PROTON_VERB"), opts)

enable_reaper(env, command, local)

command.extend([local.joinpath("umu").as_posix(), "--verb", verb, "--"])
Expand Down Expand Up @@ -304,6 +319,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