Skip to content

Commit 7e6d29d

Browse files
Merge pull request #190 from xXJSONDeruloXx/cleanup-misc
More cleanup
2 parents 7b5f3cb + 192716e commit 7e6d29d

19 files changed

+22
-478
lines changed

.gitignore

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ cli/
5656
cli/*
5757
cli/decky
5858

59-
# generated files
60-
py_modules/lsfg_vk/config_schema_generated.py
61-
py_modules/lsfg_vk/configuration_helpers_generated.py
62-
src/config/generatedConfigSchema.ts
59+
# generated files (uncommented for now, need in git for store build deploys)
60+
# py_modules/lsfg_vk/config_schema_generated.py
61+
# py_modules/lsfg_vk/configuration_helpers_generated.py
62+
# src/config/generatedConfigSchema.ts
6363

6464
# Additional development artifacts
6565
*.pyc

main.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
Main entry point for the lsfg-vk Decky Loader plugin.
33
44
This file imports and exposes the Plugin class from the lsfg_vk package.
5-
The actual implementation has been refactored into separate service modules
6-
for better maintainability and testability.
75
"""
86

9-
# Import the refactored Plugin class
107
from lsfg_vk import Plugin
118

12-
# Re-export Plugin at module level for Decky Loader compatibility
139
__all__ = ['Plugin']

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "decky-lsfg-vk",
3-
"version": "0.12.0",
3+
"version": "0.12.1",
44
"description": "Use Lossless Scaling on the Steam Deck using the lsfg-vk vulkan layer",
55
"type": "module",
66
"scripts": {

py_modules/lsfg_vk/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
Vulkan layer for Lossless Scaling frame generation.
66
"""
77

8-
# Import will be available once plugin.py exists
98
try:
109
from .plugin import Plugin
1110
__all__ = ['Plugin']
1211
except ImportError:
13-
# During development, plugin may not exist yet
1412
__all__ = []
13+

py_modules/lsfg_vk/base_service.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
from .constants import LOCAL_LIB, LOCAL_SHARE_BASE, VULKAN_LAYER_DIR, SCRIPT_NAME, CONFIG_DIR, CONFIG_FILENAME
1414

15-
# Generic type for response dictionaries
1615
ResponseType = TypeVar('ResponseType', bound=Dict[str, Any])
1716

1817

@@ -30,12 +29,11 @@ def __init__(self, logger: Optional[Any] = None):
3029
else:
3130
self.log = logger
3231

33-
# Initialize common paths using pathlib
3432
self.user_home = Path.home()
3533
self.local_lib_dir = self.user_home / LOCAL_LIB
3634
self.local_share_dir = self.user_home / VULKAN_LAYER_DIR
3735
self.lsfg_script_path = self.user_home / SCRIPT_NAME
38-
self.lsfg_launch_script_path = self.user_home / SCRIPT_NAME # ~/lsfg launch script
36+
self.lsfg_launch_script_path = self.user_home / SCRIPT_NAME
3937
self.config_dir = self.user_home / CONFIG_DIR
4038
self.config_file_path = self.config_dir / CONFIG_FILENAME
4139

@@ -82,13 +80,11 @@ def _write_file(self, path: Path, content: str, mode: int = 0o644) -> None:
8280
OSError: If write fails
8381
"""
8482
try:
85-
# Write directly to the file
8683
with open(path, 'w', encoding='utf-8') as f:
8784
f.write(content)
88-
f.flush() # Ensure data is written to disk
89-
os.fsync(f.fileno()) # Force filesystem sync
85+
f.flush()
86+
os.fsync(f.fileno())
9087

91-
# Set permissions
9288
path.chmod(mode)
9389
self.log.info(f"Wrote to {path}")
9490

py_modules/lsfg_vk/configuration.py

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,14 @@ def get_config(self) -> ConfigurationResponse:
2222
ConfigurationResponse with current configuration or error
2323
"""
2424
try:
25-
# Get TOML configuration (with defaults if file doesn't exist)
2625
if not self.config_file_path.exists():
27-
# Return default configuration with DLL detection if file doesn't exist
2826
from .dll_detection import DllDetectionService
2927
dll_service = DllDetectionService(self.log)
3028
toml_config = ConfigurationManager.get_defaults_with_dll_detection(dll_service)
3129
else:
3230
content = self.config_file_path.read_text(encoding='utf-8')
3331
toml_config = ConfigurationManager.parse_toml_content(content)
3432

35-
# Get script environment variables (if script exists)
3633
script_values = {}
3734
if self.lsfg_script_path.exists():
3835
try:
@@ -42,7 +39,6 @@ def get_config(self) -> ConfigurationResponse:
4239
except Exception as e:
4340
self.log.warning(f"Failed to parse launch script: {str(e)}")
4441

45-
# Merge TOML config with script values
4642
config = ConfigurationManager.merge_config_with_script(toml_config, script_values)
4743

4844
return self._success_response(ConfigurationResponse, config=config)
@@ -54,7 +50,6 @@ def get_config(self) -> ConfigurationResponse:
5450
except Exception as e:
5551
error_msg = f"Error parsing config file: {str(e)}"
5652
self.log.error(error_msg)
57-
# Return defaults with DLL detection if parsing fails
5853
from .dll_detection import DllDetectionService
5954
dll_service = DllDetectionService(self.log)
6055
config = ConfigurationManager.get_defaults_with_dll_detection(dll_service)
@@ -75,7 +70,6 @@ def update_config_from_dict(self, config: ConfigurationData) -> ConfigurationRes
7570
profile_data = self._get_profile_data()
7671
current_profile = profile_data["current_profile"]
7772

78-
# Update the current profile's config
7973
return self.update_profile_config(current_profile, config)
8074

8175
except (OSError, IOError) as e:
@@ -97,10 +91,8 @@ def update_config(self, **kwargs) -> ConfigurationResponse:
9791
ConfigurationResponse with success status
9892
"""
9993
try:
100-
# Create configuration from keyword arguments using generated function
10194
config = ConfigurationManager.create_config_from_args(**kwargs)
10295

103-
# Update using the new profile-aware method
10496
return self.update_config_from_dict(config)
10597

10698
except (OSError, IOError) as e:
@@ -112,45 +104,6 @@ def update_config(self, **kwargs) -> ConfigurationResponse:
112104
self.log.error(error_msg)
113105
return self._error_response(ConfigurationResponse, str(e), config=None)
114106

115-
def update_dll_path(self, dll_path: str) -> ConfigurationResponse:
116-
"""Update just the DLL path in the configuration
117-
118-
Args:
119-
dll_path: Path to the Lossless.dll file
120-
121-
Returns:
122-
ConfigurationResponse with success status
123-
"""
124-
try:
125-
profile_data = self._get_profile_data()
126-
127-
# Update global config (DLL path is global)
128-
profile_data["global_config"]["dll"] = dll_path
129-
130-
# Also update current profile's config for backward compatibility
131-
current_profile = profile_data["current_profile"]
132-
from .config_schema_generated import DLL
133-
profile_data["profiles"][current_profile][DLL] = dll_path
134-
135-
# Save to file
136-
self._save_profile_data(profile_data)
137-
138-
# Update launch script
139-
script_result = self.update_lsfg_script_from_profile_data(profile_data)
140-
if not script_result["success"]:
141-
self.log.warning(f"Failed to update launch script: {script_result['error']}")
142-
143-
self.log.info(f"Updated DLL path in lsfg configuration: '{dll_path}'")
144-
145-
return self._success_response(ConfigurationResponse,
146-
f"DLL path updated to: {dll_path}",
147-
config=profile_data["profiles"][current_profile])
148-
149-
except Exception as e:
150-
error_msg = f"Error updating DLL path: {str(e)}"
151-
self.log.error(error_msg)
152-
return self._error_response(ConfigurationResponse, str(e), config=None)
153-
154107
def update_lsfg_script(self, config: ConfigurationData) -> ConfigurationResponse:
155108
"""Update the ~/lsfg launch script with current configuration
156109
@@ -163,7 +116,6 @@ def update_lsfg_script(self, config: ConfigurationData) -> ConfigurationResponse
163116
try:
164117
script_content = self._generate_script_content(config)
165118

166-
# Write the script file
167119
self._write_file(self.lsfg_script_path, script_content, 0o755)
168120

169121
self.log.info(f"Updated lsfg launch script at {self.lsfg_script_path}")
@@ -189,14 +141,12 @@ def _generate_script_content(self, config: ConfigurationData) -> str:
189141
lines = [
190142
"#!/bin/bash",
191143
"# lsfg-vk launch script generated by decky-lossless-scaling-vk plugin",
192-
"# This script sets up the environment for lsfg-vk to work with the plugin configuration"
144+
"# This script sets up the environment for lsfg-vk to work with the plugin configuration",
193145
]
194146

195-
# Use auto-generated script generation logic
196147
generate_script_lines = get_script_generation_logic()
197148
lines.extend(generate_script_lines(config))
198149

199-
# Always add the LSFG_PROCESS export and execution line
200150
lines.extend([
201151
"export LSFG_PROCESS=decky-lsfg-vk",
202152
'exec "$@"'
@@ -216,23 +166,18 @@ def _generate_script_content_for_profile(self, profile_data: ProfileData) -> str
216166
current_profile = profile_data["current_profile"]
217167
config = profile_data["profiles"].get(current_profile, ConfigurationManager.get_defaults())
218168

219-
# Merge global config with profile config
220169
merged_config = dict(config)
221170
for field_name, value in profile_data["global_config"].items():
222171
merged_config[field_name] = value
223172

224173
lines = [
225174
"#!/bin/bash",
226-
"# lsfg-vk launch script generated by decky-lossless-scaling-vk plugin",
227175
f"# Current profile: {current_profile}",
228-
"# This script sets up the environment for lsfg-vk to work with the plugin configuration"
229176
]
230177

231-
# Use auto-generated script generation logic
232178
generate_script_lines = get_script_generation_logic()
233179
lines.extend(generate_script_lines(merged_config))
234180

235-
# Export LSFG_PROCESS with current profile name
236181
lines.extend([
237182
f"export LSFG_PROCESS={current_profile}",
238183
'exec "$@"'
@@ -243,7 +188,6 @@ def _generate_script_content_for_profile(self, profile_data: ProfileData) -> str
243188
def _get_profile_data(self) -> ProfileData:
244189
"""Get current profile data from config file"""
245190
if not self.config_file_path.exists():
246-
# Return default profile structure if file doesn't exist
247191
from .dll_detection import DllDetectionService
248192
dll_service = DllDetectionService(self.log)
249193
default_config = ConfigurationManager.get_defaults_with_dll_detection(dll_service)
@@ -263,13 +207,10 @@ def _save_profile_data(self, profile_data: ProfileData) -> None:
263207
"""Save profile data to config file"""
264208
toml_content = ConfigurationManager.generate_toml_content_multi_profile(profile_data)
265209

266-
# Ensure config directory exists
267210
self.config_dir.mkdir(parents=True, exist_ok=True)
268211

269-
# Write the updated config directly to preserve inode for file watchers
270212
self._write_file(self.config_file_path, toml_content, 0o644)
271213

272-
# Profile management methods
273214
def get_profiles(self) -> ProfilesResponse:
274215
"""Get list of all profiles and current profile
275216
@@ -303,14 +244,11 @@ def create_profile(self, profile_name: str, source_profile: str = None) -> Profi
303244
try:
304245
profile_data = self._get_profile_data()
305246

306-
# Use current profile as source if not specified
307247
if not source_profile:
308248
source_profile = profile_data["current_profile"]
309249

310-
# Create the new profile
311250
new_profile_data = ConfigurationManager.create_profile(profile_data, profile_name, source_profile)
312251

313-
# Save to file
314252
self._save_profile_data(new_profile_data)
315253

316254
self.log.info(f"Created profile '{profile_name}' from '{source_profile}'")
@@ -340,13 +278,10 @@ def delete_profile(self, profile_name: str) -> ProfileResponse:
340278
try:
341279
profile_data = self._get_profile_data()
342280

343-
# Delete the profile
344281
new_profile_data = ConfigurationManager.delete_profile(profile_data, profile_name)
345282

346-
# Save to file
347283
self._save_profile_data(new_profile_data)
348284

349-
# Update launch script if current profile changed
350285
script_result = self.update_lsfg_script_from_profile_data(new_profile_data)
351286
if not script_result["success"]:
352287
self.log.warning(f"Failed to update launch script: {script_result['error']}")
@@ -379,13 +314,10 @@ def rename_profile(self, old_name: str, new_name: str) -> ProfileResponse:
379314
try:
380315
profile_data = self._get_profile_data()
381316

382-
# Rename the profile
383317
new_profile_data = ConfigurationManager.rename_profile(profile_data, old_name, new_name)
384318

385-
# Save to file
386319
self._save_profile_data(new_profile_data)
387320

388-
# Update launch script if current profile changed
389321
script_result = self.update_lsfg_script_from_profile_data(new_profile_data)
390322
if not script_result["success"]:
391323
self.log.warning(f"Failed to update launch script: {script_result['error']}")
@@ -417,13 +349,10 @@ def set_current_profile(self, profile_name: str) -> ProfileResponse:
417349
try:
418350
profile_data = self._get_profile_data()
419351

420-
# Set current profile
421352
new_profile_data = ConfigurationManager.set_current_profile(profile_data, profile_name)
422353

423-
# Save to file
424354
self._save_profile_data(new_profile_data)
425355

426-
# Update launch script with new current profile
427356
script_result = self.update_lsfg_script_from_profile_data(new_profile_data)
428357
if not script_result["success"]:
429358
self.log.warning(f"Failed to update launch script: {script_result['error']}")
@@ -469,16 +398,13 @@ def update_profile_config(self, profile_name: str, config: ConfigurationData) ->
469398
if field_name in config:
470399
profile_data["global_config"][field_name] = config[field_name]
471400

472-
# Save to file
473401
self._save_profile_data(profile_data)
474402

475-
# Update launch script if this is the current profile
476403
if profile_name == profile_data["current_profile"]:
477404
script_result = self.update_lsfg_script_from_profile_data(profile_data)
478405
if not script_result["success"]:
479406
self.log.warning(f"Failed to update launch script: {script_result['error']}")
480407

481-
# Log with dynamic field listing
482408
field_values = ", ".join(f"{k}={repr(v)}" for k, v in config.items())
483409
self.log.info(f"Updated profile '{profile_name}' configuration: {field_values}")
484410

py_modules/lsfg_vk/constants.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,30 @@
44

55
from pathlib import Path
66

7-
# Directory paths
87
LOCAL_LIB = ".local/lib"
98
LOCAL_SHARE_BASE = ".local/share"
109
VULKAN_LAYER_DIR = ".local/share/vulkan/implicit_layer.d"
1110
CONFIG_DIR = ".config/lsfg-vk"
1211

13-
# File names
1412
SCRIPT_NAME = "lsfg"
1513
CONFIG_FILENAME = "conf.toml"
1614
LIB_FILENAME = "liblsfg-vk.so"
1715
JSON_FILENAME = "VkLayer_LS_frame_generation.json"
1816
ZIP_FILENAME = "lsfg-vk_noui.zip"
1917

20-
# Flatpak files
2118
FLATPAK_23_08_FILENAME = "org.freedesktop.Platform.VulkanLayer.lsfg_vk_23.08.flatpak"
2219
FLATPAK_24_08_FILENAME = "org.freedesktop.Platform.VulkanLayer.lsfg_vk_24.08.flatpak"
2320
FLATPAK_25_08_FILENAME = "org.freedesktop.Platform.VulkanLayer.lsfg_vk_25.08.flatpak"
2421

25-
# File extensions
2622
SO_EXT = ".so"
2723
JSON_EXT = ".json"
2824

29-
# Directory for the zip file
3025
BIN_DIR = "bin"
3126

32-
# Lossless Scaling paths
3327
STEAM_COMMON_PATH = Path("steamapps/common/Lossless Scaling")
3428
LOSSLESS_DLL_NAME = "Lossless.dll"
3529

36-
# Environment variable names
3730
ENV_LSFG_DLL_PATH = "LSFG_DLL_PATH"
3831
ENV_XDG_DATA_HOME = "XDG_DATA_HOME"
3932
ENV_HOME = "HOME"
33+

0 commit comments

Comments
 (0)