1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
/**
* Configuration schema and management for LSFG VK plugin
*
* This file re-exports auto-generated configuration constants from generatedConfigSchema.ts
* and provides the ConfigurationManager class for handling configuration operations.
*/
import { callable } from "@decky/api";
import type { ConfigurationData } from './generatedConfigSchema';
import { getDefaults } from './generatedConfigSchema';
import { updateLsfgConfig } from "../api/lsfgApi";
// Re-export all auto-generated configuration constants
export {
ConfigFieldType,
ConfigField,
CONFIG_SCHEMA,
ConfigurationData,
getFieldNames,
getDefaults,
getFieldTypes,
// Field name constants for type-safe access
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
} from './generatedConfigSchema';
/**
* Configuration management class
* Handles CRUD operations for plugin configuration
*/
export class ConfigurationManager {
private static instance: ConfigurationManager;
private _config: ConfigurationData | null = null;
// Callable methods for backend communication
private getConfiguration = callable<[], { success: boolean; data?: ConfigurationData; error?: string }>("get_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;
}
/**
* Get default configuration values
*/
static getDefaults(): ConfigurationData {
return getDefaults();
}
/**
* Load configuration from backend
*/
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;
}
}
/**
* Save configuration to backend
*/
async saveConfig(config: ConfigurationData): Promise<void> {
try {
const result = await updateLsfgConfig(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;
}
}
/**
* Update a single configuration field
*/
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 current configuration (cached)
*/
getConfig(): ConfigurationData | null {
return this._config;
}
/**
* Reset configuration to defaults
*/
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();
|