diff options
| author | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-07-21 23:04:08 -0400 |
|---|---|---|
| committer | xXJSONDeruloXx <danielhimebauch@gmail.com> | 2025-07-21 23:04:08 -0400 |
| commit | e54b7e2c5f3a736f248353317007f922771ab0c7 (patch) | |
| tree | 6fc8931d44b1fa93269d2bba89c9790bfd83fd7a /src | |
| parent | 2106ef8eb31ee46611fce07dd715d3ac1c4ca0ab (diff) | |
| download | decky-lsfg-vk-e54b7e2c5f3a736f248353317007f922771ab0c7.tar.gz decky-lsfg-vk-e54b7e2c5f3a736f248353317007f922771ab0c7.zip | |
refactor: remove unused backend files and improve configuration handling in TypeScript
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/UsageInstructions.tsx | 22 | ||||
| -rw-r--r-- | src/config/configSchema.ts | 252 | ||||
| -rw-r--r-- | src/config/generatedConfigSchema.ts | 127 |
3 files changed, 237 insertions, 164 deletions
diff --git a/src/components/UsageInstructions.tsx b/src/components/UsageInstructions.tsx index bcf258b..0c27517 100644 --- a/src/components/UsageInstructions.tsx +++ b/src/components/UsageInstructions.tsx @@ -5,7 +5,7 @@ interface UsageInstructionsProps { config: ConfigurationData; } -export function UsageInstructions({ config }: UsageInstructionsProps) { +export function UsageInstructions({ config: _config }: UsageInstructionsProps) { return ( <> <PanelSectionRow> @@ -56,26 +56,6 @@ export function UsageInstructions({ config }: UsageInstructionsProps) { </div> </PanelSectionRow> - {/* <PanelSectionRow> - <div - style={{ - fontSize: "12px", - lineHeight: "1.4", - opacity: "0.8", - whiteSpace: "pre-wrap" - }} - > - {`Current Configuration: -• DLL Path: ${config.dll} -• Multiplier: ${config.multiplier}x -• Flow Scale: ${Math.round(config.flow_scale * 100)}% -• Performance Mode: ${config.performance_mode ? "Yes" : "No"} -• HDR Mode: ${config.hdr_mode ? "Yes" : "No"} -• Present Mode: ${config.experimental_present_mode || "FIFO (VSync)"} -• DXVK Frame Rate: ${config.dxvk_frame_rate > 0 ? `${config.dxvk_frame_rate} FPS` : "Off"}`} - </div> - </PanelSectionRow> */} - <PanelSectionRow> <div style={{ diff --git a/src/config/configSchema.ts b/src/config/configSchema.ts index 03b1510..4ab0d25 100644 --- a/src/config/configSchema.ts +++ b/src/config/configSchema.ts @@ -1,181 +1,147 @@ /** - * Centralized configuration schema for lsfg-vk frontend. + * Configuration schema and management for LSFG VK plugin * - * This mirrors the Python configuration schema to ensure consistency - * between frontend and backend configuration handling. + * This file re-exports auto-generated configuration constants from generatedConfigSchema.ts + * and provides the ConfigurationManager class for handling configuration operations. */ -// Configuration field type enum -export enum ConfigFieldType { - BOOLEAN = "boolean", - INTEGER = "integer", - FLOAT = "float", - STRING = "string" -} +import { callable } from "@decky/api"; +import type { ConfigurationData } from './generatedConfigSchema'; +import { getDefaults } from './generatedConfigSchema'; -// Configuration field definition -export interface ConfigField { - name: string; - fieldType: ConfigFieldType; - default: boolean | number | string; - description: string; -} +// Re-export all auto-generated configuration constants +export { + ConfigFieldType, + ConfigField, + CONFIG_SCHEMA, + ConfigurationData, + getFieldNames, + getDefaults, + getFieldTypes +} from './generatedConfigSchema'; -// Configuration schema - must match Python CONFIG_SCHEMA -export const CONFIG_SCHEMA: Record<string, ConfigField> = { - dll: { - name: "dll", - fieldType: ConfigFieldType.STRING, - default: "/games/Lossless Scaling/Lossless.dll", - description: "specify where Lossless.dll is stored" - }, - - multiplier: { - name: "multiplier", - fieldType: ConfigFieldType.INTEGER, - default: 1, - description: "change the fps multiplier" - }, - - flow_scale: { - name: "flow_scale", - fieldType: ConfigFieldType.FLOAT, - default: 0.8, - description: "change the flow scale" - }, - - performance_mode: { - name: "performance_mode", - fieldType: ConfigFieldType.BOOLEAN, - default: true, - description: "toggle performance mode" - }, - - hdr_mode: { - name: "hdr_mode", - fieldType: ConfigFieldType.BOOLEAN, - default: false, - description: "enable hdr in games that support it" - }, - - experimental_present_mode: { - name: "experimental_present_mode", - fieldType: ConfigFieldType.STRING, - default: "fifo", - description: "experimental: override vulkan present mode (fifo/mailbox/immediate)" - }, - - dxvk_frame_rate: { - name: "dxvk_frame_rate", - fieldType: ConfigFieldType.INTEGER, - default: 0, - description: "Base framerate cap for DirectX games, before frame multiplier (0 = disabled, requires game re-launch)" - }, - - enable_wow64: { - name: "enable_wow64", - fieldType: ConfigFieldType.BOOLEAN, - default: false, - description: "enable PROTON_USE_WOW64=1 for 32-bit games (use with ProtonGE to fix crashing)" - }, - - disable_steamdeck_mode: { - name: "disable_steamdeck_mode", - fieldType: ConfigFieldType.BOOLEAN, - default: false, - description: "disable Steam Deck mode (unlocks hidden settings in some games)" - } -}; +/** + * Configuration management class + * Handles CRUD operations for plugin configuration + */ +export class ConfigurationManager { + private static instance: ConfigurationManager; + private _config: ConfigurationData | null = null; -// Type-safe configuration data structure -export interface ConfigurationData { - dll: string; - multiplier: number; - flow_scale: number; - performance_mode: boolean; - hdr_mode: boolean; - experimental_present_mode: string; - dxvk_frame_rate: number; - enable_wow64: boolean; - disable_steamdeck_mode: boolean; -} + // Callable methods for backend communication + private getConfiguration = callable<[], { success: boolean; data?: ConfigurationData; error?: string }>("get_configuration"); + private setConfiguration = callable<[{ config_data: ConfigurationData }], { success: boolean; error?: string }>("set_configuration"); + private resetConfiguration = callable<[], { success: boolean; data?: ConfigurationData; error?: string }>("reset_configuration"); + + private constructor() {} + + static getInstance(): ConfigurationManager { + if (!ConfigurationManager.instance) { + ConfigurationManager.instance = new ConfigurationManager(); + } + return ConfigurationManager.instance; + } -// Centralized configuration manager -export class ConfigurationManager { /** * Get default configuration values */ static getDefaults(): ConfigurationData { - const defaults = {} as ConfigurationData; - Object.values(CONFIG_SCHEMA).forEach(field => { - (defaults as any)[field.name] = field.default; - }); - return defaults; + return getDefaults(); } /** - * Get ordered list of configuration field names + * Create args array from config object for lsfg API calls */ - static getFieldNames(): string[] { - return Object.keys(CONFIG_SCHEMA); + static createArgsFromConfig(config: ConfigurationData): [string, number, number, boolean, boolean, string, number, boolean, boolean] { + return [ + config.dll, + config.multiplier, + config.flow_scale, + config.performance_mode, + config.hdr_mode, + config.experimental_present_mode, + config.dxvk_frame_rate, + config.enable_wow64, + config.disable_steamdeck_mode + ]; } /** - * Get field type mapping + * Load configuration from backend */ - static getFieldTypes(): Record<string, ConfigFieldType> { - return Object.values(CONFIG_SCHEMA).reduce((acc, field) => { - acc[field.name] = field.fieldType; - return acc; - }, {} as Record<string, ConfigFieldType>); + async loadConfig(): Promise<ConfigurationData> { + try { + const result = await this.getConfiguration(); + if (result.success && result.data) { + this._config = result.data; + return this._config; + } else { + throw new Error(result.error || 'Failed to load configuration'); + } + } catch (error) { + console.error('Error loading configuration:', error); + throw error; + } } /** - * Create ordered arguments array from configuration object + * Save configuration to backend */ - static createArgsFromConfig(config: ConfigurationData): (boolean | number | string)[] { - return this.getFieldNames().map(fieldName => - config[fieldName as keyof ConfigurationData] - ); + async saveConfig(config: ConfigurationData): Promise<void> { + try { + const result = await this.setConfiguration({ config_data: config }); + if (result.success) { + this._config = config; + } else { + throw new Error(result.error || 'Failed to save configuration'); + } + } catch (error) { + console.error('Error saving configuration:', error); + throw error; + } } /** - * Validate configuration object against schema + * Update a single configuration field */ - static validateConfig(config: Partial<ConfigurationData>): ConfigurationData { - const defaults = this.getDefaults(); - const validated = { ...defaults }; - - Object.entries(CONFIG_SCHEMA).forEach(([fieldName, fieldDef]) => { - const value = config[fieldName as keyof ConfigurationData]; - if (value !== undefined) { - // Type validation - if (fieldDef.fieldType === ConfigFieldType.BOOLEAN) { - (validated as any)[fieldName] = Boolean(value); - } else if (fieldDef.fieldType === ConfigFieldType.INTEGER) { - (validated as any)[fieldName] = parseInt(String(value), 10); - } else if (fieldDef.fieldType === ConfigFieldType.FLOAT) { - (validated as any)[fieldName] = parseFloat(String(value)); - } else if (fieldDef.fieldType === ConfigFieldType.STRING) { - (validated as any)[fieldName] = String(value); - } - } - }); - - return validated; + async updateField(fieldName: keyof ConfigurationData, value: any): Promise<void> { + if (!this._config) { + await this.loadConfig(); + } + + const updatedConfig = { + ...this._config!, + [fieldName]: value + }; + + await this.saveConfig(updatedConfig); } /** - * Get configuration field definition + * Get current configuration (cached) */ - static getFieldDef(fieldName: string): ConfigField | undefined { - return CONFIG_SCHEMA[fieldName]; + getConfig(): ConfigurationData | null { + return this._config; } /** - * Get all field definitions + * Reset configuration to defaults */ - static getAllFieldDefs(): ConfigField[] { - return Object.values(CONFIG_SCHEMA); + async resetToDefaults(): Promise<ConfigurationData> { + try { + const result = await this.resetConfiguration(); + if (result.success && result.data) { + this._config = result.data; + return this._config; + } else { + throw new Error(result.error || 'Failed to reset configuration'); + } + } catch (error) { + console.error('Error resetting configuration:', error); + throw error; + } } } + +// Export singleton instance +export const configManager = ConfigurationManager.getInstance(); diff --git a/src/config/generatedConfigSchema.ts b/src/config/generatedConfigSchema.ts new file mode 100644 index 0000000..d862ad2 --- /dev/null +++ b/src/config/generatedConfigSchema.ts @@ -0,0 +1,127 @@ +/** + * Auto-generated TypeScript configuration schema. + * DO NOT EDIT MANUALLY - Generated from shared_config.py + * + * To update this file, run: python3 generate_ts_config.py > src/config/generatedConfigSchema.ts + */ + +// Configuration field type enum - matches Python +export enum ConfigFieldType { + BOOLEAN = "boolean", + INTEGER = "integer", + FLOAT = "float", + STRING = "string" +} + +// Configuration field definition +export interface ConfigField { + name: string; + fieldType: ConfigFieldType; + default: boolean | number | string; + description: string; +} + +// Configuration schema - auto-generated from Python +export const CONFIG_SCHEMA: Record<string, ConfigField> = { + dll: { + name: "dll", + fieldType: ConfigFieldType.STRING, + default: "/games/Lossless Scaling/Lossless.dll", + description: "specify where Lossless.dll is stored" + }, + multiplier: { + name: "multiplier", + fieldType: ConfigFieldType.INTEGER, + default: 1, + description: "change the fps multiplier" + }, + flow_scale: { + name: "flow_scale", + fieldType: ConfigFieldType.FLOAT, + default: 0.8, + description: "change the flow scale" + }, + performance_mode: { + name: "performance_mode", + fieldType: ConfigFieldType.BOOLEAN, + default: true, + description: "use a lighter model for FG (recommended for most games)" + }, + hdr_mode: { + name: "hdr_mode", + fieldType: ConfigFieldType.BOOLEAN, + default: false, + description: "enable HDR mode (only for games that support HDR)" + }, + experimental_present_mode: { + name: "experimental_present_mode", + fieldType: ConfigFieldType.STRING, + default: "fifo", + description: "override Vulkan present mode (may cause crashes)" + }, + dxvk_frame_rate: { + name: "dxvk_frame_rate", + fieldType: ConfigFieldType.INTEGER, + default: 0, + description: "base framerate cap for DirectX games before frame multiplier" + }, + enable_wow64: { + name: "enable_wow64", + fieldType: ConfigFieldType.BOOLEAN, + default: false, + description: "enable PROTON_USE_WOW64=1 for 32-bit games (use with ProtonGE to fix crashing)" + }, + disable_steamdeck_mode: { + name: "disable_steamdeck_mode", + fieldType: ConfigFieldType.BOOLEAN, + default: false, + description: "disable Steam Deck mode (unlocks hidden settings in some games)" + }, +}; + +// Type-safe configuration data structure +export interface ConfigurationData { + dll: string; + multiplier: number; + flow_scale: number; + performance_mode: boolean; + hdr_mode: boolean; + experimental_present_mode: string; + dxvk_frame_rate: number; + enable_wow64: boolean; + disable_steamdeck_mode: boolean; +} + +// Helper functions +export function getFieldNames(): string[] { + return Object.keys(CONFIG_SCHEMA); +} + +export function getDefaults(): ConfigurationData { + return { + dll: "/games/Lossless Scaling/Lossless.dll", + multiplier: 1, + flow_scale: 0.8, + performance_mode: true, + hdr_mode: false, + experimental_present_mode: "fifo", + dxvk_frame_rate: 0, + enable_wow64: false, + disable_steamdeck_mode: false, + }; +} + +export function getFieldTypes(): Record<string, string> { + return { + dll: "ConfigFieldType.STRING", + multiplier: "ConfigFieldType.INTEGER", + flow_scale: "ConfigFieldType.FLOAT", + performance_mode: "ConfigFieldType.BOOLEAN", + hdr_mode: "ConfigFieldType.BOOLEAN", + experimental_present_mode: "ConfigFieldType.STRING", + dxvk_frame_rate: "ConfigFieldType.INTEGER", + enable_wow64: "ConfigFieldType.BOOLEAN", + disable_steamdeck_mode: "ConfigFieldType.BOOLEAN", + }; +} + |
