chore: cherry pick changes from test-typehints branch

This commit is contained in:
aclist committed 2026-11-19 06:41:05 +09:00
1 parent 5853e15b8e
commit 663e57b8cd
4 files changed
+31 -8

No files matched your search

+5 -5
View File
@@ -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:
+2 -2
View File
@@ -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(
+1 -1
View File
@@ -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
+23
View File
@@ -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")