From e8d7d9eb15466a88e755aafc7ddda5029ef83524 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:37:13 +0900 Subject: [PATCH 1/9] change: abstract flatpak ps command --- dzgui/init/proc.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py index 0c1a2a06..7717f077 100644 --- a/dzgui/init/proc.py +++ b/dzgui/init/proc.py @@ -30,16 +30,19 @@ def is_steam_running(cmd: str) -> bool: def is_sandboxed() -> bool: return bool(os.environ.get("FLATPAK_ID")) +def get_flatpak_output() -> list[str]: + proc = subprocess.check_output( + [FLATPAK_CMD, "ps", "--columns=application"], text=True + ) + lines = proc.splitlines() + return lines def is_flatpak_steam_running() -> bool: if is_sandboxed(): return True if has_cmd(FLATPAK_CMD) is False: return False - proc = subprocess.check_output( - [FLATPAK_CMD, "ps", "--columns=application"], text=True - ) - lines = proc.splitlines() + lines = get_flatpak_output() if FLATPAK_APPID in lines: return True return False From 77682cacd459e2aa47cbb26ae3df95a8922ad694 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 12 Nov 2026 11:37:49 +0900 Subject: [PATCH 2/9] change: refactor test for readability --- tests/test_process_detection.py | 139 +++++++++++++++++--------------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/tests/test_process_detection.py b/tests/test_process_detection.py index f57ced35..097790d4 100644 --- a/tests/test_process_detection.py +++ b/tests/test_process_detection.py @@ -1,80 +1,93 @@ import pytest -import unittest -from unittest.mock import patch -from typing import Any +from typing import Literal, TYPE_CHECKING from dzgui.const.constants import ( FLATPAK_APPID, FLATPAK_ROOT_PATH, - FLATPAK_RUN_CMD, - FLATPAK_SANDBOX, ) from dzgui.init import proc +if TYPE_CHECKING: + from _pytest.monkeypatch import MonkeyPatch + pytestmark = pytest.mark.flatpak -class TestSteamDetection(unittest.TestCase): - def test_flatpak_detection_with_multiple_running_apps(self) -> None: - def flatpak_output(args: Any, *, text: str) -> str: - # Default 'flatpak ps' includes instance, PID, app and runtime columns. - if args == ["flatpak", "ps", "--columns=application"]: - return f"com.spotify.Client\n{FLATPAK_APPID}\n{FLATPAK_APPID}\n" - return f"3904921611\t1257689\t{FLATPAK_APPID}\torg.freedesktop.Platform\n" +def mock_has_cmd(cmd: str) -> Literal[True]: + return True - with ( - patch.object(proc, "has_cmd", return_value=True), - patch.object(proc.subprocess, "check_output", side_effect=flatpak_output), - ): - for client in (FLATPAK_RUN_CMD, FLATPAK_SANDBOX): - with self.subTest(client=client): - self.assertTrue(proc.is_steam_running(client)) - def test_flatpak_not_running(self) -> None: - with patch.object(proc, "has_cmd", return_value=True): - for output in ("", "com.spotify.Client\n", f"{FLATPAK_APPID}Helper\n"): - with ( - self.subTest(output=output), - patch.object(proc.subprocess, "check_output", return_value=output), - ): - self.assertFalse(proc.is_flatpak_steam_running()) +def mock_has_not_cmd(cmd: str) -> Literal[False]: + return False - def test_flatpak_not_installed(self) -> None: - with ( - patch.object(proc, "has_cmd", return_value=False), - patch.object(proc.subprocess, "check_output") as check_output, - ): - self.assertFalse(proc.is_flatpak_steam_running()) - check_output.assert_not_called() - def test_native_steam(self) -> None: - with patch.object(proc, "has_cmd", return_value=True): - for output, expected in ( - ( - [ - [FLATPAK_ROOT_PATH], - "/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper", - ], - True, - ), - ([[FLATPAK_ROOT_PATH]], False), - ([[FLATPAK_ROOT_PATH], ["steam-runtime-launcher-service"]], False), - ([["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"]], True), - ( - [ - ["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"], - "steam-runtime-launcher-service", - ], - True, - ), - ): - with ( - self.subTest(running=output), - patch.object(proc, "get_steam_procs", return_value=output), - ): - self.assertEqual(proc.is_native_steam_running(), expected) +def mock_get_flatpak_output() -> list[str]: + lines = ["Application", "com.freedesktop.Platform", f"{FLATPAK_APPID}"] + return lines - def test_invalid_client(self) -> None: - with self.assertRaises(TypeError): - proc.is_steam_running("invalid-client") + +@pytest.mark.parametrize( + "output, expected", + [ + ( + [ + [f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"], + ["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"], + ], + True, + ), + ( + [ + [f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"], + ["steam-runtime-launcher-service"], + ], + False, + ), + ([[f"/home/user/{FLATPAK_ROOT_PATH}/.local/share/Steam"]], False), + ([["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"]], True), + ( + [ + ["/home/user/.local/share/Steam/ubuntu12_64/steamwebhelper"], + ["steam-runtime-launcher-service"], + ], + True, + ), + ], +) +def test_native_steam_running( + monkeypatch: "MonkeyPatch", output: list[list[str]], expected: bool +) -> None: + def mock_get_steam_procs() -> list[list[str]]: + return output + + monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_cmd) + monkeypatch.setattr("dzgui.init.proc.get_steam_procs", mock_get_steam_procs) + assert proc.is_native_steam_running() == expected + + +def test_flatpak_running(monkeypatch: "MonkeyPatch") -> None: + monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_cmd) + monkeypatch.setattr("dzgui.init.proc.get_flatpak_output", mock_get_flatpak_output) + assert proc.is_flatpak_steam_running() + + +def test_flatpak_sandboxed(monkeypatch: "MonkeyPatch") -> None: + monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd) + monkeypatch.setenv("FLATPAK_ID", FLATPAK_APPID) + assert proc.is_flatpak_steam_running() + + +def test_flatpak_not_installed(monkeypatch: "MonkeyPatch") -> None: + monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd) + assert not proc.is_flatpak_steam_running() + + +def test_steam_not_installed(monkeypatch: "MonkeyPatch") -> None: + monkeypatch.setattr("dzgui.init.proc.has_cmd", mock_has_not_cmd) + assert not proc.is_native_steam_running() + + +def test_invalid_client() -> None: + with pytest.raises(TypeError): + proc.is_steam_running("invalid-client") From d2208787b4b2ddc17e6111009ecf1075562430da Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 12 Nov 2026 12:01:59 +0900 Subject: [PATCH 3/9] chore: clear typehinting errors in build scripts --- scripts/parse_toml.py | 3 ++- scripts/prebuild.py | 6 +++--- scripts/release.py | 4 ++-- scripts/scrot.py | 14 ++++++++++---- scripts/untracked.py | 17 +++++++---------- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/scripts/parse_toml.py b/scripts/parse_toml.py index e4b52109..612f832d 100644 --- a/scripts/parse_toml.py +++ b/scripts/parse_toml.py @@ -1,8 +1,9 @@ import tomllib from shared import get_git_root +from typing import Any -def get_entrypoint() -> None: +def get_entrypoint() -> Any: root = get_git_root() p = root.joinpath("pyproject.toml") with open(p, "rb") as f: diff --git a/scripts/prebuild.py b/scripts/prebuild.py index 143bc564..cdf97f2c 100644 --- a/scripts/prebuild.py +++ b/scripts/prebuild.py @@ -52,7 +52,7 @@ def untar(file: str, glob: str, renamed: str) -> None: os.rename(_dir, build_dir.joinpath(renamed)) -def install_deps() -> None: +def install_deps() -> int: pip = build_dir.joinpath(f"{CPYTHON_BUILD}/bin/pip") proc = subprocess.run([pip, "install", root]) return proc.returncode @@ -65,12 +65,12 @@ def repackage() -> None: tar.add(build_dir.joinpath(CPYTHON_BUILD), arcname="python") -def rebuild_cpython() -> None: +def rebuild_cpython() -> str: if cpython_dir.is_dir() is False: get_cpython() code = install_deps() if code != 0: - return + return "" repackage() return get_packaged_version() diff --git a/scripts/release.py b/scripts/release.py index 2afaf47c..934ef7c9 100644 --- a/scripts/release.py +++ b/scripts/release.py @@ -92,8 +92,8 @@ with tarfile.open(tarpath, "w:gz") as tar: tar.add(subfolder, arcname=appname, filter=update_uname) print(f"Wrote tarfile to '{tarpath}'") -proc = subprocess.run([release_exe, "-v"], capture_output=True, text=True) -assert proc.stdout.rstrip() == version +built_proc = subprocess.run([release_exe, "-v"], capture_output=True, text=True) +assert str(built_proc.stdout).rstrip() == version # TODO: clean up staging directory release_exe.unlink() diff --git a/scripts/scrot.py b/scripts/scrot.py index 38001972..be400d49 100644 --- a/scripts/scrot.py +++ b/scripts/scrot.py @@ -8,7 +8,13 @@ def get_image_path() -> Path: return get_git_root().joinpath("dzgui/data/images/example.png") -p = get_image_path() -app = build_gui("", False) -app.set_automation_param("screenshot_path", p) -app.run(None) +def take_screenshot() -> None: + p = get_image_path() + app = build_gui("", False) + if app is None: + return + app.set_automation_param("screenshot_path", p) + app.run(None) + + +take_screenshot() diff --git a/scripts/untracked.py b/scripts/untracked.py index f53714d0..d77fa261 100644 --- a/scripts/untracked.py +++ b/scripts/untracked.py @@ -3,14 +3,11 @@ import subprocess import sys cmd = ["git", "ls-files", "--others", "--exclude-standard"] -result = subprocess.Popen( - cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True +result = subprocess.run( + cmd, capture_output=True, text=True ) -with open(".gitignore", "r") as f: - ignored = [line.rstrip() for line in f] - -untracked = [os.path.basename(line.rstrip()) for line in result.stdout] -for file in untracked: - if not any(file in item for item in ignored): - print(f"File '{file}' is untracked. Add to .gitignore file if this is intended.") - sys.exit(1) +untracked = [os.path.basename(line.rstrip()) for line in result.stdout.splitlines()] +if bool(untracked): + print(f"The following files are untracked. Add to .gitignore if this is intended.") + print("\n".join(untracked)) + sys.exit(1) From ea41503dad9ab4e5d671df3b6c6999779c00e35e Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:10:38 +0900 Subject: [PATCH 4/9] change: swallow stderr --- dzgui/init/prereqs.py | 2 +- dzgui/init/proc.py | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/dzgui/init/prereqs.py b/dzgui/init/prereqs.py index 9266bfbe..7e2a41f1 100644 --- a/dzgui/init/prereqs.py +++ b/dzgui/init/prereqs.py @@ -23,7 +23,7 @@ def has_flatpak_client() -> bool: else: return False except Exception as e: - logger.critical(e) + logger.debug(e) return False diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py index 7717f077..483c8fe1 100644 --- a/dzgui/init/proc.py +++ b/dzgui/init/proc.py @@ -30,6 +30,7 @@ def is_steam_running(cmd: str) -> bool: def is_sandboxed() -> bool: return bool(os.environ.get("FLATPAK_ID")) + def get_flatpak_output() -> list[str]: proc = subprocess.check_output( [FLATPAK_CMD, "ps", "--columns=application"], text=True @@ -37,15 +38,23 @@ def get_flatpak_output() -> list[str]: lines = proc.splitlines() return lines + def is_flatpak_steam_running() -> bool: if is_sandboxed(): return True if has_cmd(FLATPAK_CMD) is False: return False - lines = get_flatpak_output() - if FLATPAK_APPID in lines: - return True - return False + try: + proc = subprocess.check_output( + [FLATPAK_CMD, "ps", "--columns=application"], text=True + ) + lines = proc.splitlines() + if FLATPAK_APPID in lines: + return True + return False + except Exception as e: + logger.debug(e) + return False def get_steam_procs() -> list[list[str]]: From d47d7075e9e0939498c55a1856dddd11d8606c21 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:13:29 +0900 Subject: [PATCH 5/9] change: move try statement to outer function --- dzgui/init/proc.py | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py index 483c8fe1..ac1051cc 100644 --- a/dzgui/init/proc.py +++ b/dzgui/init/proc.py @@ -31,12 +31,16 @@ def is_sandboxed() -> bool: return bool(os.environ.get("FLATPAK_ID")) -def get_flatpak_output() -> list[str]: - proc = subprocess.check_output( - [FLATPAK_CMD, "ps", "--columns=application"], text=True - ) - lines = proc.splitlines() - return lines +def get_flatpak_output() -> list[str] | None: + try: + proc = subprocess.check_output( + [FLATPAK_CMD, "ps", "--columns=application"], text=True + ) + lines = proc.splitlines() + return lines + except Exception as e: + logger.debug(e) + return None def is_flatpak_steam_running() -> bool: @@ -44,17 +48,12 @@ def is_flatpak_steam_running() -> bool: return True if has_cmd(FLATPAK_CMD) is False: return False - try: - proc = subprocess.check_output( - [FLATPAK_CMD, "ps", "--columns=application"], text=True - ) - lines = proc.splitlines() - if FLATPAK_APPID in lines: - return True - return False - except Exception as e: - logger.debug(e) + lines = get_flatpak_output() + if lines is None: return False + if FLATPAK_APPID in lines: + return True + return False def get_steam_procs() -> list[list[str]]: From dfef2cfd752c7bf6302eb1168a967defd399c415 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Tue, 17 Nov 2026 02:13:56 +0900 Subject: [PATCH 6/9] drop: unused f-string --- scripts/untracked.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/untracked.py b/scripts/untracked.py index d77fa261..198345ff 100644 --- a/scripts/untracked.py +++ b/scripts/untracked.py @@ -3,11 +3,9 @@ import subprocess import sys cmd = ["git", "ls-files", "--others", "--exclude-standard"] -result = subprocess.run( - cmd, capture_output=True, text=True -) +result = subprocess.run(cmd, capture_output=True, text=True) untracked = [os.path.basename(line.rstrip()) for line in result.stdout.splitlines()] if bool(untracked): - print(f"The following files are untracked. Add to .gitignore if this is intended.") + print("The following files are untracked. Add to .gitignore if this is intended.") print("\n".join(untracked)) sys.exit(1) From 0f28885e7b81f9e279a81d15df913f06c7c28e36 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:31:57 +0900 Subject: [PATCH 7/9] chore: update thanks page --- dzgui/util/strings.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dzgui/util/strings.py b/dzgui/util/strings.py index 79512986..575175c5 100644 --- a/dzgui/util/strings.py +++ b/dzgui/util/strings.py @@ -347,7 +347,9 @@ thanks = Thanks( "scandalouss", "SnackSBR", "StevelDusa", + "sylvaingirardbe", "Thoughtduck216", + "u-alexandru", ], ) From 00741b0b60d7ea5cd3014acd9bf4f91c1e919593 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 19 Nov 2026 06:10:24 +0900 Subject: [PATCH 8/9] fix: parse real home in sandbox --- dzgui/config/xdg.py | 10 +++++----- dzgui/init/prereqs.py | 4 ++-- dzgui/init/proc.py | 14 ++++++++++++-- dzgui/strings/wizard.py | 2 +- tests/test_home_in_sandbox.py | 23 +++++++++++++++++++++++ 5 files changed, 43 insertions(+), 10 deletions(-) create mode 100644 tests/test_home_in_sandbox.py diff --git a/dzgui/config/xdg.py b/dzgui/config/xdg.py index eac3dcf4..1250dbbd 100644 --- a/dzgui/config/xdg.py +++ b/dzgui/config/xdg.py @@ -6,10 +6,9 @@ from dataclasses import dataclass from dzgui.const.constants import ( APP_NAME_LOWER, DEBUG_LOG, - FLATPAK_ROOT_PATH, SYSTEM_LOG, ) -from dzgui.init.proc import is_sandboxed +from dzgui.init.proc import is_flatpak_sandbox, is_snap_sandbox @dataclass(slots=True, frozen=True) @@ -53,6 +52,10 @@ def is_writeable(path_str: str) -> bool: def get_xdg_paths() -> dict[str, Path]: home = Path.home() + if resolved := os.environ.get("SNAP_REAL_HOME"): # Snap + home = Path(resolved) + elif resolved := os.environ.get("HOME"): # Flatpak + home = Path(resolved) xdg_paths = { "XDG_CONFIG_HOME": home / ".config", "XDG_STATE_HOME": home / ".local" / "state", @@ -62,9 +65,6 @@ def get_xdg_paths() -> dict[str, Path]: resolved_paths = {} for path in xdg_paths: real_path = os.environ.get(path) - if real_path is not None and is_sandboxed(): - search_string = FLATPAK_ROOT_PATH + "/" - real_path = real_path.replace(search_string, "") if real_path is not None and is_writeable(real_path): new_path = Path(real_path) else: diff --git a/dzgui/init/prereqs.py b/dzgui/init/prereqs.py index 7e2a41f1..122ebb68 100644 --- a/dzgui/init/prereqs.py +++ b/dzgui/init/prereqs.py @@ -3,13 +3,13 @@ import shutil import subprocess from dzgui.const.constants import APP_NAME, FLATPAK_APPID, FLATPAK_CMD, STEAM_CMD -from dzgui.init.proc import is_sandboxed +from dzgui.init.proc import is_flatpak_sandbox logger = logging.getLogger(APP_NAME) def has_flatpak_client() -> bool: - if is_sandboxed(): + if is_flatpak_sandbox(): return True try: res = subprocess.run( diff --git a/dzgui/init/proc.py b/dzgui/init/proc.py index ac1051cc..dbf3bf55 100644 --- a/dzgui/init/proc.py +++ b/dzgui/init/proc.py @@ -27,10 +27,20 @@ def is_steam_running(cmd: str) -> bool: raise TypeError("Not a valid Steam client selection") -def is_sandboxed() -> bool: +def is_snap_sandbox() -> bool: + return bool(os.environ.get("SNAP")) + + +def is_flatpak_sandbox() -> bool: return bool(os.environ.get("FLATPAK_ID")) +def is_sandboxed() -> bool: + if is_snap_sandbox() or is_flatpak_sandbox(): + return True + return False + + def get_flatpak_output() -> list[str] | None: try: proc = subprocess.check_output( @@ -44,7 +54,7 @@ def get_flatpak_output() -> list[str] | None: def is_flatpak_steam_running() -> bool: - if is_sandboxed(): + if is_flatpak_sandbox(): return True if has_cmd(FLATPAK_CMD) is False: return False diff --git a/dzgui/strings/wizard.py b/dzgui/strings/wizard.py index de837620..54497080 100644 --- a/dzgui/strings/wizard.py +++ b/dzgui/strings/wizard.py @@ -3,7 +3,7 @@ title_intro = "Welcome" blurb_intro = """ This wizard will help you set up some common config options before launching the application. """ -error_sandbox = "Setup cannot be run from inside Flatpak sandbox.\nPlease launch the application directly." +error_sandbox = "Setup cannot be run from inside a sandboxed version of Steam (Snap/Flatpak).\nPlease launch the application directly first." welcome = "Welcome to {0}!" ### SteamPathPage diff --git a/tests/test_home_in_sandbox.py b/tests/test_home_in_sandbox.py new file mode 100644 index 00000000..4404b62a --- /dev/null +++ b/tests/test_home_in_sandbox.py @@ -0,0 +1,23 @@ +import pytest +import tempfile + +from pathlib import Path +from typing import TYPE_CHECKING + +from dzgui.config.xdg import get_xdg_paths + +if TYPE_CHECKING: + from _pytest.monkeypatch import MonkeyPatch + + +@pytest.mark.parametrize("env", ["SNAP_REAL_HOME", "HOME"]) +def test_sandbox_home_resolution(monkeypatch: "MonkeyPatch", env: str) -> None: + with tempfile.NamedTemporaryFile(delete=False) as f: + monkeypatch.setenv(env, f.name) + paths = get_xdg_paths() + assert paths["XDG_CONFIG_HOME"] == Path(f.name).joinpath(".config/dzgui") + + +def test_home_fallback() -> None: + paths = get_xdg_paths() + assert paths["XDG_CONFIG_HOME"] == Path.home().joinpath(".config/dzgui") From dee566932a5e9cb6cecfe64e551ee31706baa77b Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 19 Nov 2026 06:10:49 +0900 Subject: [PATCH 9/9] fix: wrap long error labels --- dzgui/views/dialogs/boot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dzgui/views/dialogs/boot.py b/dzgui/views/dialogs/boot.py index 5a8a7181..a737caac 100644 --- a/dzgui/views/dialogs/boot.py +++ b/dzgui/views/dialogs/boot.py @@ -19,7 +19,7 @@ from dzgui.views.components.buttons import ClipboardButton from dzgui.views.mixins.colorscheme import ColorAwareApp gi.require_version("Gtk", "3.0") -from gi.repository import Gtk, GLib, Gdk +from gi.repository import Gtk, GLib, Gdk, Pango if TYPE_CHECKING: from dzgui.config.xdg import Xdg @@ -95,7 +95,7 @@ class BootDialog(ColorAwareApp, Gtk.Dialog): # type: ignore margin_top=30, margin_bottom=30, ) - self.error_label = Gtk.Label(margin_start=15, margin_end=15) + self.error_label = Gtk.Label(margin_start=15, margin_end=15, wrap=True, wrap_mode=Pango.WrapMode.WORD) # TODO: abstract class self.copy_button = ClipboardButton(self.error_label.get_text)