summaryrefslogtreecommitdiff
path: root/py_modules
diff options
context:
space:
mode:
authorxXJSONDeruloXx <danielhimebauch@gmail.com>2025-10-19 11:55:54 -0400
committerxXJSONDeruloXx <danielhimebauch@gmail.com>2025-10-19 11:55:54 -0400
commitcecbefc71eacf8ae61a36bbb7fe06eb8c1fa03c6 (patch)
treeb3f09b029d9ccd2655c05888759d9be3477780ff /py_modules
parentf076064a9c064a7e2ca74be013e2174aec8a0a1e (diff)
downloaddecky-lsfg-vk-cecbefc71eacf8ae61a36bbb7fe06eb8c1fa03c6.tar.gz
decky-lsfg-vk-cecbefc71eacf8ae61a36bbb7fe06eb8c1fa03c6.zip
chore: clean up imports, rm dupe inits, bump ver
Diffstat (limited to 'py_modules')
-rw-r--r--py_modules/lsfg_vk/base_service.py8
-rw-r--r--py_modules/lsfg_vk/config_schema.py8
-rw-r--r--py_modules/lsfg_vk/flatpak_service.py9
-rw-r--r--py_modules/lsfg_vk/installation.py7
-rw-r--r--py_modules/lsfg_vk/plugin.py19
5 files changed, 20 insertions, 31 deletions
diff --git a/py_modules/lsfg_vk/base_service.py b/py_modules/lsfg_vk/base_service.py
index b684ec9..9c3dec3 100644
--- a/py_modules/lsfg_vk/base_service.py
+++ b/py_modules/lsfg_vk/base_service.py
@@ -2,11 +2,14 @@
Base service class with common functionality.
"""
+import logging
import os
import shutil
from pathlib import Path
from typing import Any, Optional, TypeVar, Dict
+import decky
+
from .constants import LOCAL_LIB, LOCAL_SHARE_BASE, VULKAN_LAYER_DIR, SCRIPT_NAME, CONFIG_DIR, CONFIG_FILENAME
# Generic type for response dictionaries
@@ -23,7 +26,6 @@ class BaseService:
logger: Logger instance, defaults to decky.logger if None
"""
if logger is None:
- import decky
self.log = decky.logger
else:
self.log = logger
@@ -90,8 +92,8 @@ class BaseService:
path.chmod(mode)
self.log.info(f"Wrote to {path}")
- except Exception:
- self.log.error(f"Failed to write to {path}")
+ except (OSError, IOError, PermissionError) as e:
+ self.log.error(f"Failed to write to {path}: {e}")
raise
def _success_response(self, response_type: type, message: str = "", **kwargs) -> Any:
diff --git a/py_modules/lsfg_vk/config_schema.py b/py_modules/lsfg_vk/config_schema.py
index 66aeb69..807c798 100644
--- a/py_modules/lsfg_vk/config_schema.py
+++ b/py_modules/lsfg_vk/config_schema.py
@@ -8,6 +8,7 @@ This module defines the complete configuration structure for lsfg-vk, managing T
- Type definitions
"""
+import logging
import re
import sys
from typing import TypedDict, Dict, Any, Union, cast, List
@@ -124,9 +125,9 @@ class ConfigurationManager:
dll_result = dll_detection_service.check_lossless_scaling_dll()
if dll_result.get("detected") and dll_result.get("path"):
defaults["dll"] = dll_result["path"]
- except Exception:
+ except (OSError, IOError, KeyError, TypeError) as e:
# If detection fails, keep empty default
- pass
+ logging.getLogger(__name__).debug(f"DLL detection failed: {e}")
# If DLL path is still empty, use a reasonable fallback
if not defaults["dll"]:
@@ -403,8 +404,9 @@ class ConfigurationManager:
global_config=global_config
)
- except Exception:
+ except (ValueError, KeyError, TypeError, AttributeError) as e:
# If parsing fails completely, return default profile structure
+ logging.getLogger(__name__).warning(f"Failed to parse TOML profiles, using defaults: {e}")
return ProfileData(
current_profile=DEFAULT_PROFILE_NAME,
profiles={DEFAULT_PROFILE_NAME: ConfigurationManager.get_defaults()},
diff --git a/py_modules/lsfg_vk/flatpak_service.py b/py_modules/lsfg_vk/flatpak_service.py
index cdf4a55..7c1ccdc 100644
--- a/py_modules/lsfg_vk/flatpak_service.py
+++ b/py_modules/lsfg_vk/flatpak_service.py
@@ -49,16 +49,9 @@ class FlatpakService(BaseService):
self.extension_id_23_08 = "org.freedesktop.Platform.VulkanLayer.lsfgvk/x86_64/23.08"
self.extension_id_24_08 = "org.freedesktop.Platform.VulkanLayer.lsfgvk/x86_64/24.08"
self.flatpak_command = None # Will be set when flatpak is detected
- def __init__(self, logger=None):
- super().__init__(logger)
- self.extension_id_23_08 = "org.freedesktop.Platform.VulkanLayer.lsfgvk/x86_64/23.08"
- self.extension_id_24_08 = "org.freedesktop.Platform.VulkanLayer.lsfgvk/x86_64/24.08"
- self.flatpak_command = None # Will be set when flatpak is detected
def _get_clean_env(self):
"""Get a clean environment without PyInstaller's bundled libraries"""
- import os
-
# Create a clean environment without PyInstaller's bundled libraries
env = os.environ.copy()
@@ -96,8 +89,6 @@ class FlatpakService(BaseService):
def check_flatpak_available(self) -> bool:
"""Check if flatpak command is available and store the working command"""
- import os
-
# Log environment info for debugging
self.log.info(f"PATH: {os.environ.get('PATH', 'Not set')}")
self.log.info(f"HOME: {os.environ.get('HOME', 'Not set')}")
diff --git a/py_modules/lsfg_vk/installation.py b/py_modules/lsfg_vk/installation.py
index 3b47be0..763154f 100644
--- a/py_modules/lsfg_vk/installation.py
+++ b/py_modules/lsfg_vk/installation.py
@@ -4,6 +4,7 @@ Installation service for lsfg-vk.
import os
import shutil
+import traceback
import zipfile
import tempfile
import json
@@ -188,8 +189,9 @@ class InstallationService(BaseService):
final_config = ConfigurationManager.parse_toml_content(final_content)
if final_config.get(DLL):
self.log.info(f"Configured DLL path: {final_config[DLL]}")
- except Exception:
- pass # Don't fail installation if we can't log the DLL path
+ except (OSError, IOError, ValueError, KeyError) as e:
+ # Don't fail installation if we can't log the DLL path
+ self.log.debug(f"Could not log DLL path: {e}")
def _create_lsfg_launch_script(self) -> None:
"""Create the ~/lsfg launch script for easier game setup"""
@@ -328,7 +330,6 @@ class InstallationService(BaseService):
except Exception as e:
self.log.error(f"Error cleaning up lsfg-vk files during uninstall: {str(e)}")
- import traceback
self.log.error(f"Traceback: {traceback.format_exc()}")
def _merge_config_with_defaults(self, existing_profile_data, dll_service):
diff --git a/py_modules/lsfg_vk/plugin.py b/py_modules/lsfg_vk/plugin.py
index ed4b552..7731558 100644
--- a/py_modules/lsfg_vk/plugin.py
+++ b/py_modules/lsfg_vk/plugin.py
@@ -14,6 +14,8 @@ import hashlib
from typing import Dict, Any
from pathlib import Path
+import decky
+
from .installation import InstallationService
from .dll_detection import DllDetectionService
from .configuration import ConfigurationService
@@ -200,8 +202,9 @@ class Plugin:
return schema_data
- except Exception:
+ except (ValueError, KeyError, AttributeError) as e:
# Fallback to basic schema without profile info
+ self.configuration_service.log.warning(f"Failed to get full schema, using fallback: {e}")
return {
"field_names": ConfigurationManager.get_field_names(),
"field_types": {name: field_type.value for name, field_type in ConfigurationManager.get_field_types().items()},
@@ -325,8 +328,6 @@ class Plugin:
}
"""
try:
- import decky
-
# Read current version from package.json
package_json_path = Path(decky.DECKY_PLUGIN_DIR) / "package.json"
current_version = "0.0.0"
@@ -411,8 +412,6 @@ class Plugin:
}
"""
try:
- import decky
-
# Create download path
downloads_dir = Path.home() / "Downloads"
downloads_dir.mkdir(exist_ok=True)
@@ -504,8 +503,9 @@ class Plugin:
# All parts are equal
return False
- except Exception:
+ except (IndexError, AttributeError, TypeError) as e:
# If comparison fails, assume no update available
+ self.configuration_service.log.warning(f"Version comparison failed: {e}")
return False
# Plugin lifecycle methods
@@ -580,7 +580,6 @@ class Plugin:
}
except Exception as e:
- import decky
decky.logger.error(f"Error reading launch script: {e}")
return {
"success": False,
@@ -594,7 +593,6 @@ class Plugin:
Dict with exists status and directory path
"""
try:
- import decky
home_path = Path(decky.DECKY_USER_HOME)
fgmod_path = home_path / "fgmod"
@@ -607,7 +605,6 @@ class Plugin:
}
except Exception as e:
- import decky
decky.logger.error(f"Error checking fgmod directory: {e}")
return {
"success": False,
@@ -686,7 +683,6 @@ class Plugin:
This method is called by Decky Loader when the plugin is loaded.
Any initialization code should go here.
"""
- import decky
decky.logger.info("decky-lsfg-vk plugin loaded")
async def _unload(self):
@@ -696,7 +692,6 @@ class Plugin:
This method is called by Decky Loader when the plugin is being unloaded.
Any cleanup code should go here.
"""
- import decky
decky.logger.info("decky-lsfg-vk plugin unloaded")
async def _uninstall(self):
@@ -707,7 +702,6 @@ class Plugin:
It automatically cleans up any lsfg-vk files that were installed and
uninstalls any flatpak extensions.
"""
- import decky
decky.logger.info("decky-lsfg-vk plugin uninstalled - starting cleanup")
# Clean up lsfg-vk files when the plugin is uninstalled
@@ -756,7 +750,6 @@ class Plugin:
This method is called by Decky Loader for plugin migrations.
Currently migrates logs, settings, and runtime data from old locations.
"""
- import decky
decky.logger.info("Running decky-lsfg-vk plugin migrations")
# Migrate logs from old location