Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions py_modules/lsfg_vk/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ def get_toml_value(self, value: Union[bool, int, float, str]) -> Union[bool, int
# Complete configuration schema (TOML + script-only fields)
COMPLETE_CONFIG_SCHEMA = {**CONFIG_SCHEMA, **SCRIPT_ONLY_FIELDS}


# Import auto-generated configuration components
from .config_schema_generated import ConfigurationData, get_script_parsing_logic, get_script_generation_logic

# Constants for profile management
DEFAULT_PROFILE_NAME = "decky-lsfg-vk"
GLOBAL_SECTION_FIELDS = {"dll", "no_fp16"}
Expand Down Expand Up @@ -446,13 +442,6 @@ def merge_config_with_script(toml_config: ConfigurationData, script_values: Dict

return cast(ConfigurationData, merged_config)

@staticmethod
@staticmethod
def create_config_from_args(**kwargs) -> ConfigurationData:
"""Create configuration from keyword arguments - USES GENERATED CODE"""
from .config_schema_generated import create_config_dict
return create_config_dict(**kwargs)

@staticmethod
def normalize_profile_name(profile_name: str) -> str:
"""Normalize profile name by converting spaces to dashes and trimming
Expand Down
45 changes: 1 addition & 44 deletions py_modules/lsfg_vk/config_schema_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build
"""

from typing import TypedDict, Dict, Any, Union, cast
from typing import TypedDict, Dict, Any, Union
from enum import Enum
import sys
from pathlib import Path
Expand Down Expand Up @@ -122,47 +122,4 @@ def generate_script_lines(config):
return generate_script_lines


def get_function_parameters() -> str:
"""Return function signature parameters"""
return """dll: str = "/games/Lossless Scaling/Lossless.dll",
no_fp16: bool = False,
multiplier: int = 1,
flow_scale: float = 0.8,
performance_mode: bool = False,
hdr_mode: bool = False,
experimental_present_mode: str = "fifo",
dxvk_frame_rate: int = 0,
enable_wow64: bool = False,
disable_steamdeck_mode: bool = False,
mangohud_workaround: bool = False,
disable_vkbasalt: bool = False,
force_enable_vkbasalt: bool = False,
enable_wsi: bool = False,
enable_zink: bool = False"""


def create_config_dict(**kwargs) -> ConfigurationData:
"""Create configuration dictionary from keyword arguments"""
return cast(ConfigurationData, {
"dll": kwargs.get("dll"),
"no_fp16": kwargs.get("no_fp16"),
"multiplier": kwargs.get("multiplier"),
"flow_scale": kwargs.get("flow_scale"),
"performance_mode": kwargs.get("performance_mode"),
"hdr_mode": kwargs.get("hdr_mode"),
"experimental_present_mode": kwargs.get("experimental_present_mode"),
"dxvk_frame_rate": kwargs.get("dxvk_frame_rate"),
"enable_wow64": kwargs.get("enable_wow64"),
"disable_steamdeck_mode": kwargs.get("disable_steamdeck_mode"),
"mangohud_workaround": kwargs.get("mangohud_workaround"),
"disable_vkbasalt": kwargs.get("disable_vkbasalt"),
"force_enable_vkbasalt": kwargs.get("force_enable_vkbasalt"),
"enable_wsi": kwargs.get("enable_wsi"),
"enable_zink": kwargs.get("enable_zink"),
})


# Field lists for dynamic operations
TOML_FIELDS = ['dll', 'no_fp16', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode']
SCRIPT_FIELDS = ['dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt', 'force_enable_vkbasalt', 'enable_wsi', 'enable_zink']
ALL_FIELDS = ['dll', 'no_fp16', 'multiplier', 'flow_scale', 'performance_mode', 'hdr_mode', 'experimental_present_mode', 'dxvk_frame_rate', 'enable_wow64', 'disable_steamdeck_mode', 'mangohud_workaround', 'disable_vkbasalt', 'force_enable_vkbasalt', 'enable_wsi', 'enable_zink']
24 changes: 0 additions & 24 deletions py_modules/lsfg_vk/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .base_service import BaseService
from .config_schema import ConfigurationManager, CONFIG_SCHEMA, ProfileData, DEFAULT_PROFILE_NAME
from .config_schema_generated import ConfigurationData, get_script_generation_logic
from .configuration_helpers_generated import log_configuration_update
from .types import ConfigurationResponse, ProfilesResponse, ProfileResponse


Expand Down Expand Up @@ -81,29 +80,6 @@ def update_config_from_dict(self, config: ConfigurationData) -> ConfigurationRes
self.log.error(error_msg)
return self._error_response(ConfigurationResponse, str(e), config=None)

def update_config(self, **kwargs) -> ConfigurationResponse:
"""Update TOML configuration using generated schema - SIMPLIFIED WITH GENERATED CODE

Args:
**kwargs: Configuration field values (see shared_config.py for available fields)

Returns:
ConfigurationResponse with success status
"""
try:
config = ConfigurationManager.create_config_from_args(**kwargs)

return self.update_config_from_dict(config)

except (OSError, IOError) as e:
error_msg = f"Error updating lsfg config: {str(e)}"
self.log.error(error_msg)
return self._error_response(ConfigurationResponse, str(e), config=None)
except ValueError as e:
error_msg = f"Invalid configuration arguments: {str(e)}"
self.log.error(error_msg)
return self._error_response(ConfigurationResponse, str(e), config=None)

def update_lsfg_script(self, config: ConfigurationData) -> ConfigurationResponse:
"""Update the ~/lsfg launch script with current configuration

Expand Down
22 changes: 0 additions & 22 deletions py_modules/lsfg_vk/configuration_helpers_generated.py

This file was deleted.

111 changes: 3 additions & 108 deletions scripts/generate_python_boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,38 +56,6 @@ def generate_typed_dict() -> str:
return "\n".join(lines)


def generate_function_signature() -> str:
"""Generate function signature for update_config and create_config_from_args"""
params = []

for field_name, field_def in CONFIG_SCHEMA_DEF.items():
python_type = get_python_type(ConfigFieldType(field_def["fieldType"]))
default = field_def["default"]

# Format default value
if isinstance(default, str):
default_str = f'"{default}"'
elif isinstance(default, bool):
default_str = str(default)
else:
default_str = str(default)

params.append(f"{field_name}: {python_type} = {default_str}")

return ",\n ".join(params)


def generate_config_dict_creation() -> str:
"""Generate dictionary creation for create_config_from_args"""
lines = [" return cast(ConfigurationData, {"]

for field_name in CONFIG_SCHEMA_DEF.keys():
lines.append(f' "{field_name}": kwargs.get("{field_name}"),')

lines.append(" })")
return "\n".join(lines)


def generate_script_parsing() -> str:
"""Generate script content parsing logic"""
lines = []
Expand Down Expand Up @@ -195,17 +163,6 @@ def generate_script_generation() -> str:
return "\n".join(lines)


def generate_log_statement() -> str:
"""Generate logging statement with all field values"""
field_parts = []

for field_name in CONFIG_SCHEMA_DEF.keys():
field_parts.append(f"{field_name}={{{field_name}}}")

log_format = ", ".join(field_parts)
return f' self.log.info(f"Updated lsfg TOML configuration: {log_format}")'


def generate_complete_schema_file() -> str:
"""Generate complete config_schema_generated.py file"""

Expand All @@ -221,7 +178,7 @@ def generate_complete_schema_file() -> str:
'DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build',
'"""',
'',
'from typing import TypedDict, Dict, Any, Union, cast',
'from typing import TypedDict, Dict, Any, Union',
'from enum import Enum',
'import sys',
'from pathlib import Path',
Expand Down Expand Up @@ -267,86 +224,24 @@ def generate_complete_schema_file() -> str:
' return generate_script_lines',
'',
'',
'def get_function_parameters() -> str:',
' """Return function signature parameters"""',
f' return """{generate_function_signature()}"""',
'',
'',
'def create_config_dict(**kwargs) -> ConfigurationData:',
' """Create configuration dictionary from keyword arguments"""',
f'{generate_config_dict_creation().replace(" return cast(ConfigurationData, {", " return cast(ConfigurationData, {").replace(" })", " })")}',
'',
'',
'# Field lists for dynamic operations',
f'TOML_FIELDS = {[name for name, field in CONFIG_SCHEMA_DEF.items() if field.get("location") == "toml"]}',
f'SCRIPT_FIELDS = {[name for name, field in CONFIG_SCHEMA_DEF.items() if field.get("location") == "script"]}',
f'ALL_FIELDS = {list(CONFIG_SCHEMA_DEF.keys())}',
''
]

return '\n'.join(lines)


def generate_complete_configuration_helpers() -> str:
"""Generate configuration_helpers_generated.py file"""

# Generate the log format string using config parameter
log_parts = []
for field_name in CONFIG_SCHEMA_DEF.keys():
log_parts.append(f"{field_name}={{config['{field_name}']}}")
log_format = ", ".join(log_parts)

lines = [
'"""',
'Auto-generated configuration helper functions from shared_config.py',
'DO NOT EDIT THIS FILE MANUALLY - it will be overwritten on build',
'"""',
'',
'from typing import Dict, Any',
'from .config_schema_generated import ConfigurationData, ALL_FIELDS',
'',
'',
'def log_configuration_update(logger, config: ConfigurationData) -> None:',
' """Log configuration update with all field values"""',
f' logger.info(f"Updated lsfg TOML configuration: {log_format}")',
'',
'',
'def get_config_field_names() -> list[str]:',
' """Get all configuration field names"""',
' return ALL_FIELDS.copy()',
'',
'',
'def extract_config_values(config: ConfigurationData) -> Dict[str, Any]:',
' """Extract configuration values as a dictionary"""',
' return {field: config[field] for field in ALL_FIELDS}',
''
]

return '\n'.join(lines)


def main():
"""Generate complete Python configuration files"""
try:
# Create generated files in py_modules/lsfg_vk/
target_dir = project_root / "py_modules" / "lsfg_vk"

# Generate the complete schema file
schema_content = generate_complete_schema_file()
schema_file = target_dir / "config_schema_generated.py"
schema_file.write_text(schema_content)
print(f"✅ Generated {schema_file.relative_to(project_root)}")

# Generate configuration helpers
helpers_content = generate_complete_configuration_helpers()
helpers_file = target_dir / "configuration_helpers_generated.py"
helpers_file.write_text(helpers_content)
print(f"✅ Generated {helpers_file.relative_to(project_root)}")

print(f"\n🎯 Ready-to-use files generated!")
print(" Import these in your main files:")
print(" - from .config_schema_generated import ConfigurationData, get_script_parsing_logic, etc.")
print(" - from .configuration_helpers_generated import log_configuration_update, etc.")
print(f"Generated {schema_file.relative_to(project_root)}")

except Exception as e:
print(f"❌ Error generating Python files: {e}")
Expand Down
2 changes: 1 addition & 1 deletion src/components/Content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function Content() {
</>
)}

<UsageInstructions config={config} />
<UsageInstructions />

<PanelSectionRow>
<ButtonItem
Expand Down
7 changes: 1 addition & 6 deletions src/components/UsageInstructions.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { PanelSectionRow } from "@decky/ui";
import { ConfigurationData } from "../config/configSchema";

interface UsageInstructionsProps {
config: ConfigurationData;
}

export function UsageInstructions({ config: _config }: UsageInstructionsProps) {
export function UsageInstructions() {
return (
<>
<PanelSectionRow>
Expand Down
Loading