From 09ef3e446aa88c0de2a8e96b55dd658c84e58174 Mon Sep 17 00:00:00 2001 From: aclist <92275929+aclist@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:35:02 +0900 Subject: [PATCH] change: set flatpak option sensitivity dynamically --- dzgui/api/steam.py | 8 ++++---- dzgui/app_init.py | 4 ++-- dzgui/init/prereqs.py | 27 ++++++++++++++++++++------- dzgui/views/components/misc.py | 25 +++++++++++++++++++++++-- 4 files changed, 49 insertions(+), 15 deletions(-) diff --git a/dzgui/api/steam.py b/dzgui/api/steam.py index 2d0ee1e..5e914ae 100644 --- a/dzgui/api/steam.py +++ b/dzgui/api/steam.py @@ -11,7 +11,7 @@ from typing import Any, Union from warnings import deprecated from dzgui.api.acf import ACF -from dzgui.init.prereqs import has_steam_client +from dzgui.init.prereqs import has_any_client from dzgui.const.constants import ( APPID_DAYZ, APPID_DAYZ_EXP, @@ -59,7 +59,7 @@ class VDFLoadError(Exception): def get_steam_paths() -> list[tuple[Path, str]]: paths = [] - if has_steam_client(): + if has_any_client(): HOME = Path.home() env = os.environ.get("XDG_DATA_HOME") if env is not None: @@ -265,12 +265,12 @@ def find_user_id_32(path: Path) -> int: class SteamAPIKeyError(Exception): - def __init__(self, msg=None): + def __init__(self, msg: str | None = None) -> None: super().__init__(msg or api_validation_error) class SteamWorkshopEndpointError(Exception): - def __init__(self, msg=None): + def __init__(self, msg: str | None = None) -> None: super().__init__(msg or workshop_endpoint_error) diff --git a/dzgui/app_init.py b/dzgui/app_init.py index 643d32c..c200189 100644 --- a/dzgui/app_init.py +++ b/dzgui/app_init.py @@ -15,7 +15,7 @@ from dzgui.init.migrate import ( migrate_cols_file, ) from dzgui.init.flock import lock_acquire -from dzgui.init.prereqs import has_steam_client +from dzgui.init.prereqs import has_any_client from dzgui.strings import boot from dzgui.util.deck import is_steam_deck, is_game_mode @@ -136,7 +136,7 @@ def load_gui(version: str, is_debug: bool) -> None: # TODO: sudo escalation dialog # count = get_map_count() # TODO: move into module - if has_steam_client() is False: + if has_any_client() is False: EarlyAlertDialog(init.requires_steam) bootwin = BootWindow(XDG, version) diff --git a/dzgui/init/prereqs.py b/dzgui/init/prereqs.py index be92e20..5dce626 100644 --- a/dzgui/init/prereqs.py +++ b/dzgui/init/prereqs.py @@ -7,19 +7,32 @@ from dzgui.const.constants import APP_NAME, FLATPAK_APPID, FLATPAK_CMD, STEAM_CM logger = logging.getLogger(APP_NAME) -def has_steam_client() -> bool: - if shutil.which(STEAM_CMD): - return True - if not shutil.which(FLATPAK_CMD): - return False +def has_flatpak_client() -> bool: try: res = subprocess.run( - [FLATPAK_CMD, "list"], capture_output=True, text=True, check=True + [FLATPAK_CMD, "list", "--columns=application"], + capture_output=True, + text=True, + check=True, ) if FLATPAK_APPID in res.stdout: return True else: return False - except subprocess.CalledProcessError as e: + except Exception as e: logger.critical(e) return False + + +def has_steam_client() -> bool: + if shutil.which(STEAM_CMD): + return True + return False + + +def has_any_client() -> bool: + if shutil.which(STEAM_CMD): + return True + if not shutil.which(FLATPAK_CMD): + return False + return has_flatpak_client() diff --git a/dzgui/views/components/misc.py b/dzgui/views/components/misc.py index 9186246..80ef5fd 100644 --- a/dzgui/views/components/misc.py +++ b/dzgui/views/components/misc.py @@ -3,6 +3,8 @@ from dzgui.strings import options from dzgui.views.components.box import HBox from dzgui.views.components.buttons import Icon +from typing import Self +from dzgui.init.prereqs import has_steam_client, has_flatpak_client import gi @@ -14,36 +16,55 @@ class ClientCombo(Gtk.ComboBox): def __init__(self) -> None: super().__init__() - self.client_store = Gtk.ListStore(str, str) + has_steam = has_steam_client() + has_flatpak = has_flatpak_client() + self.client_store = Gtk.ListStore(str, str, bool) self.clients = ( ( options.steam_combo, STEAM_CMD, + has_steam, ), ( options.flatpak_combo, FLATPAK_RUN_CMD, + has_flatpak, ), ( options.flatpak_container_combo, FLATPAK_SANDBOX, + has_flatpak, ), ) for client in self.clients: self.client_store.append(client) + self.set_model(self.client_store) renderer_text = Gtk.CellRendererText() self.pack_start(renderer_text, True) self.add_attribute(renderer_text, "text", 0) self.set_active(0) + self.set_cell_data_func(self.get_cells()[0], self.data_func) + + def data_func( + self, + combo: Self, + cell: Gtk.CellRendererText, + model: Gtk.ListStore, + _iter: Gtk.TreeIter, + ) -> None: + sens = model[_iter][2] + cell.set_property("sensitive", sens) + def get_client_human_readable(self, cmd: str) -> str: for client in self.clients: - human, command = client + human, command, sens = client if command == cmd: return human raise TypeError("Not a valid Steam client selection") + class ErrorPopover(Gtk.Popover): def __init__(self, relative_to: Gtk.Widget, position: Gtk.PositionType) -> None: super().__init__(relative_to=relative_to, position=position)