summaryrefslogtreecommitdiff
path: root/src/api/lsfgApi.ts
blob: b38fa3b54fe8705514fc09bece79fbafe3af5942 (plain)
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import { callable } from "@decky/api";
import { ConfigurationData } from "../config/configSchema";

// Type definitions for API responses
export interface InstallationResult {
  success: boolean;
  error?: string;
  message?: string;
  removed_files?: string[];
}

export interface InstallationStatus {
  installed: boolean;
  lossless_scaling_installed: boolean;
  lossless_scaling_status: string;
  error?: string;
}

export interface SteamBranchStatus {
  success: boolean;
  message: string;
  error?: string;
  installed: boolean;
  manifest_path?: string;
  selected_branch?: string;
  current_branch?: string;
  target_branch: string;
  needs_switch: boolean;
  restart_required: boolean;
}

// Use centralized configuration data type
export type LsfgConfig = ConfigurationData;

export interface ConfigResult {
  success: boolean;
  config?: LsfgConfig;
  error?: string;
}

export interface ConfigUpdateResult {
  success: boolean;
  message?: string;
  error?: string;
}

export interface GameConfigEntry {
  appid: string;
  profile: string;
  config: LsfgConfig;
}
export interface InstalledGame { appid: string; name: string; }
export interface InstalledGamesResult { success: boolean; games?: InstalledGame[]; error?: string; }

export interface GameConfigsResult {
  success: boolean;
  default?: LsfgConfig;
  games?: GameConfigEntry[];
  error?: string;
}

export interface GameConfigResult extends ConfigUpdateResult {
  appid?: string;
  exists?: boolean;
  config?: LsfgConfig;
}

export interface ConfigSchemaResult {
  field_names: string[];
  field_types: Record<string, string>;
  defaults: ConfigurationData;
}

export interface LaunchOptionResult {
  launch_option: string;
  instructions: string;
  explanation: string;
}

export interface FileContentResult {
  success: boolean;
  content?: string;
  path?: string;
  error?: string;
}

export interface FgmodCheckResult {
  success: boolean;
  exists: boolean;
  path?: string;
  error?: string;
}

// Flatpak management interfaces
export interface FlatpakExtensionStatus {
  success: boolean;
  message: string;
  error?: string;
  installed_23_08: boolean;
  installed_24_08: boolean;
  installed_25_08: boolean;
}

export interface FlatpakApp {
  app_id: string;
  app_name: string;
  has_filesystem_override: boolean;
  has_env_override: boolean;
}

export interface FlatpakAppInfo {
  success: boolean;
  message: string;
  error?: string;
  apps: FlatpakApp[];
  total_apps: number;
}

export interface FlatpakOperationResult {
  success: boolean;
  message: string;
  error?: string;
  app_id?: string;
  operation?: string;
}

// API functions
export const installLsfgVk = callable<[], InstallationResult>("install_lsfg_vk");
export const uninstallLsfgVk = callable<[], InstallationResult>("uninstall_lsfg_vk");
export const checkLsfgVkInstalled = callable<[], InstallationStatus>("check_lsfg_vk_installed");
export const getLosslessScalingBranchStatus = callable<[], SteamBranchStatus>("get_lossless_scaling_branch_status");
export const getLsfgConfig = callable<[], ConfigResult>("get_lsfg_config");
export const getConfigSchema = callable<[], ConfigSchemaResult>("get_config_schema");
export const getLaunchOption = callable<[], LaunchOptionResult>("get_launch_option");
export const getConfigFileContent = callable<[], FileContentResult>("get_config_file_content");
export const getLaunchScriptContent = callable<[], FileContentResult>("get_launch_script_content");
export const checkFgmodDirectory = callable<[], FgmodCheckResult>("check_fgmod_directory");

// Flatpak management API functions
export const checkFlatpakExtensionStatus = callable<[], FlatpakExtensionStatus>("check_flatpak_extension_status");
export const installFlatpakExtension = callable<[string], FlatpakOperationResult>("install_flatpak_extension");
export const uninstallFlatpakExtension = callable<[string], FlatpakOperationResult>("uninstall_flatpak_extension");
export const getFlatpakApps = callable<[], FlatpakAppInfo>("get_flatpak_apps");
export const setFlatpakAppOverride = callable<[string], FlatpakOperationResult>("set_flatpak_app_override");
export const removeFlatpakAppOverride = callable<[string], FlatpakOperationResult>("remove_flatpak_app_override");

// Updated config function using object-based configuration (single source of truth)
export const updateLsfgConfig = callable<
  [ConfigurationData],
  ConfigUpdateResult
>("update_lsfg_config");
export const getGameConfigs = callable<[], GameConfigsResult>("get_game_configs");
export const getInstalledGames = callable<[], InstalledGamesResult>("get_installed_games");
export const getGameConfig = callable<[string], GameConfigResult>("get_game_config");
export const updateGameConfig = callable<[string, LsfgConfig], GameConfigResult>("update_game_config");
export const resetGameConfig = callable<[string], GameConfigResult>("reset_game_config");
export const resetAllGameConfigs = callable<[], GameConfigsResult>("reset_all_game_configs");

// Legacy helper function for backward compatibility
export const updateLsfgConfigFromObject = async (config: ConfigurationData): Promise<ConfigUpdateResult> => {
  return updateLsfgConfig(config);
};