diff options
| author | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2026-07-30 16:26:27 -0400 |
|---|---|---|
| committer | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2026-07-30 16:26:27 -0400 |
| commit | 4390d600ffd35184c4c30bc64480f58e468627de (patch) | |
| tree | a99fbdadacd15395125e5344a462abbe5327e17e /py_modules/lsfg_vk/flatpak_service.py | |
| parent | 6c5e8a8ef81b7b3d2bf19b1783250e6b0cefedf7 (diff) | |
| download | decky-lsfg-vk-4390d600ffd35184c4c30bc64480f58e468627de.tar.gz decky-lsfg-vk-4390d600ffd35184c4c30bc64480f58e468627de.zip | |
feat: migrate Decky plugin to lsfg-vk v2
Diffstat (limited to 'py_modules/lsfg_vk/flatpak_service.py')
| -rw-r--r-- | py_modules/lsfg_vk/flatpak_service.py | 85 |
1 files changed, 34 insertions, 51 deletions
diff --git a/py_modules/lsfg_vk/flatpak_service.py b/py_modules/lsfg_vk/flatpak_service.py index c9be0ec..7f7ef07 100644 --- a/py_modules/lsfg_vk/flatpak_service.py +++ b/py_modules/lsfg_vk/flatpak_service.py @@ -8,9 +8,6 @@ from pathlib import Path from typing import Dict, Any, List, Optional from .base_service import BaseService -from .constants import ( - FLATPAK_23_08_FILENAME, FLATPAK_24_08_FILENAME, FLATPAK_25_08_FILENAME, BIN_DIR, CONFIG_DIR -) from .types import BaseResponse @@ -52,6 +49,23 @@ class FlatpakService(BaseService): self.extension_id_25_08 = "org.freedesktop.Platform.VulkanLayer.lsfgvk/x86_64/25.08" self.flatpak_command = None + def _get_lsfg_paths(self) -> tuple[str, str]: + """Return the v2 config directory and directory containing Lossless.dll.""" + config_path = str(self.config_dir) + dll_directory = str(self.user_home / ".local/share/Steam/steamapps/common") + if not self.config_file_path.exists(): + return config_path, dll_directory + try: + profile_data = ConfigurationManager.parse_toml_content_multi_profile( + self.config_file_path.read_text(encoding="utf-8") + ) + configured_dll = profile_data["global_config"].get("dll", "") + if configured_dll: + dll_directory = str(Path(str(configured_dll)).parent) + except (OSError, ValueError, KeyError, TypeError) as error: + self.log.debug("Could not read configured DLL path for Flatpak override: %s", error) + return config_path, dll_directory + def _get_clean_env(self): """Get a clean environment without PyInstaller's bundled libraries""" env = os.environ.copy() @@ -177,20 +191,14 @@ class FlatpakService(BaseService): if not self.check_flatpak_available(): return self._error_response(BaseResponse, "Flatpak is not available on this system") - plugin_dir = Path(__file__).parent.parent.parent if version == "23.08": - filename = FLATPAK_23_08_FILENAME - elif version == "24.08": - filename = FLATPAK_24_08_FILENAME - else: - filename = FLATPAK_25_08_FILENAME - flatpak_path = plugin_dir / BIN_DIR / filename - - if not flatpak_path.exists(): - return self._error_response(BaseResponse, f"Flatpak file not found: {flatpak_path}") + return self._error_response( + BaseResponse, + "Flathub supplies the lsfg-vk v2 extension for runtimes 24.08 and 25.08; install 23.08 manually.", + ) result = self._run_flatpak_command( - ["install", "--user", "--noninteractive", str(flatpak_path)], + ["install", "--user", "--noninteractive", "flathub", f"org.freedesktop.Platform.VulkanLayer.lsfgvk//{version}"], capture_output=True, text=True ) @@ -298,10 +306,7 @@ class FlatpakService(BaseService): return {"filesystem": False, "env": False} output = result.stdout - home_path = os.path.expanduser("~") - config_path = f"{home_path}/.config/lsfg-vk" - dll_path = f"{home_path}/.local/share/Steam/steamapps/common/Lossless Scaling/Lossless.dll" - lsfg_path = f"{home_path}/lsfg" + config_path, dll_directory = self._get_lsfg_paths() filesystem_section = "" in_context = False @@ -317,10 +322,9 @@ class FlatpakService(BaseService): break has_config_fs = config_path in filesystem_section - has_dll_fs = dll_path in filesystem_section - has_lsfg_fs = lsfg_path in filesystem_section + has_dll_fs = dll_directory in filesystem_section - filesystem_override = has_config_fs and has_dll_fs and has_lsfg_fs + filesystem_override = has_config_fs and has_dll_fs env_override = False in_environment = False @@ -331,11 +335,11 @@ class FlatpakService(BaseService): in_environment = True elif line.startswith("[") and line != "[Environment]": in_environment = False - elif in_environment and line.startswith(f"LSFG_CONFIG={config_path}/conf.toml"): + elif in_environment and line.startswith(f"LSFGVK_CONFIG={config_path}/conf.toml"): env_override = True break - self.log.debug(f"Override status for {app_id}: filesystem={filesystem_override} ({has_config_fs}/{has_dll_fs}/{has_lsfg_fs}), env={env_override}") + self.log.debug(f"Override status for {app_id}: filesystem={filesystem_override} ({has_config_fs}/{has_dll_fs}), env={env_override}") return {"filesystem": filesystem_override, "env": env_override} @@ -351,15 +355,11 @@ class FlatpakService(BaseService): "Flatpak is not available on this system", app_id=app_id, operation="set") - home_path = os.path.expanduser("~") - config_path = f"{home_path}/.config/lsfg-vk" - dll_path = f"{home_path}/.local/share/Steam/steamapps/common/Lossless Scaling/Lossless.dll" - lsfg_path = f"{home_path}/lsfg" + config_path, dll_directory = self._get_lsfg_paths() filesystem_overrides = [ - f"--filesystem={dll_path}", - f"--filesystem={config_path}:rw", - f"--filesystem={lsfg_path}:rw" + f"--filesystem={dll_directory}:ro", + f"--filesystem={config_path}:rw", ] for override in filesystem_overrides: @@ -373,7 +373,7 @@ class FlatpakService(BaseService): app_id=app_id, operation="set") result = self._run_flatpak_command( - ["override", "--user", f"--env=LSFG_CONFIG={config_path}/conf.toml", app_id], + ["override", "--user", f"--env=LSFGVK_CONFIG={config_path}/conf.toml", app_id], capture_output=True, text=True ) @@ -401,28 +401,11 @@ class FlatpakService(BaseService): "Flatpak is not available on this system", app_id=app_id, operation="remove") - home_path = os.path.expanduser("~") - config_path = f"{home_path}/.config/lsfg-vk" - dll_path = f"{home_path}/.local/share/Steam/steamapps/common/Lossless Scaling/Lossless.dll" - lsfg_path = f"{home_path}/lsfg" + config_path, dll_directory = self._get_lsfg_paths() - reset_result = self._run_flatpak_command( - ["override", "--user", "--reset", app_id], - capture_output=True, text=True - ) - - if reset_result.returncode == 0: - self.log.info(f"Successfully reset all overrides for {app_id}") - return self._success_response(FlatpakOverrideResponse, - f"All overrides reset for {app_id}", - app_id=app_id, operation="remove") - - self.log.debug(f"Reset failed, trying individual removal: {reset_result.stderr}") - filesystem_overrides = [ - f"--nofilesystem={dll_path}", + f"--nofilesystem={dll_directory}", f"--nofilesystem={config_path}", - f"--nofilesystem={lsfg_path}" ] removal_errors = [] @@ -437,7 +420,7 @@ class FlatpakService(BaseService): removal_errors.append(f"{override}: {result.stderr}") result = self._run_flatpak_command( - ["override", "--user", "--unset-env=LSFG_CONFIG", app_id], + ["override", "--user", "--unset-env=LSFGVK_CONFIG", app_id], capture_output=True, text=True ) |
