2025-10-16 10:00:22 +08:00
|
|
|
import { invoke } from "@tauri-apps/api/core";
|
|
|
|
|
import type { Settings } from "@/types";
|
2025-10-30 14:59:15 +08:00
|
|
|
import type { AppId } from "./types";
|
2025-10-16 10:00:22 +08:00
|
|
|
|
2025-10-16 11:40:02 +08:00
|
|
|
export interface ConfigTransferResult {
|
|
|
|
|
success: boolean;
|
|
|
|
|
message: string;
|
|
|
|
|
filePath?: string;
|
|
|
|
|
backupId?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-16 10:00:22 +08:00
|
|
|
export const settingsApi = {
|
|
|
|
|
async get(): Promise<Settings> {
|
|
|
|
|
return await invoke("get_settings");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async save(settings: Settings): Promise<boolean> {
|
|
|
|
|
return await invoke("save_settings", { settings });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async restart(): Promise<boolean> {
|
|
|
|
|
return await invoke("restart_app");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async checkUpdates(): Promise<void> {
|
|
|
|
|
await invoke("check_for_updates");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async isPortable(): Promise<boolean> {
|
|
|
|
|
return await invoke("is_portable_mode");
|
|
|
|
|
},
|
|
|
|
|
|
2025-10-30 14:59:15 +08:00
|
|
|
async getConfigDir(appId: AppId): Promise<string> {
|
|
|
|
|
return await invoke("get_config_dir", { app: appId });
|
2025-10-16 10:00:22 +08:00
|
|
|
},
|
|
|
|
|
|
2025-10-30 14:59:15 +08:00
|
|
|
async openConfigFolder(appId: AppId): Promise<void> {
|
|
|
|
|
await invoke("open_config_folder", { app: appId });
|
2025-10-16 10:00:22 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async selectConfigDirectory(defaultPath?: string): Promise<string | null> {
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
return await invoke("pick_directory", { defaultPath });
|
2025-10-16 10:00:22 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getClaudeCodeConfigPath(): Promise<string> {
|
|
|
|
|
return await invoke("get_claude_code_config_path");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async getAppConfigPath(): Promise<string> {
|
|
|
|
|
return await invoke("get_app_config_path");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async openAppConfigFolder(): Promise<void> {
|
|
|
|
|
await invoke("open_app_config_folder");
|
|
|
|
|
},
|
2025-10-16 11:40:02 +08:00
|
|
|
|
|
|
|
|
async getAppConfigDirOverride(): Promise<string | null> {
|
|
|
|
|
return await invoke("get_app_config_dir_override");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async setAppConfigDirOverride(path: string | null): Promise<boolean> {
|
|
|
|
|
return await invoke("set_app_config_dir_override", { path });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async applyClaudePluginConfig(options: {
|
|
|
|
|
official: boolean;
|
|
|
|
|
}): Promise<boolean> {
|
|
|
|
|
const { official } = options;
|
|
|
|
|
return await invoke("apply_claude_plugin_config", { official });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async saveFileDialog(defaultName: string): Promise<string | null> {
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
return await invoke("save_file_dialog", { defaultName });
|
2025-10-16 11:40:02 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async openFileDialog(): Promise<string | null> {
|
|
|
|
|
return await invoke("open_file_dialog");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async exportConfigToFile(filePath: string): Promise<ConfigTransferResult> {
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
return await invoke("export_config_to_file", { filePath });
|
2025-10-16 11:40:02 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
async importConfigFromFile(filePath: string): Promise<ConfigTransferResult> {
|
refactor: migrate all Tauri commands to camelCase parameters
This commit addresses parameter naming inconsistencies caused by Tauri v2's
requirement for camelCase parameter names in IPC commands.
Backend changes (Rust):
- Updated all command parameters from snake_case to camelCase
- Commands affected:
* provider.rs: providerId (×4), timeoutSecs
* import_export.rs: filePath (×2), defaultName
* config.rs: defaultPath
- Added #[allow(non_snake_case)] attributes for camelCase parameters
- Removed unused QueryUsageParams struct
Frontend changes (TypeScript):
- Removed redundant snake_case parameters from all invoke() calls
- Updated API files:
* usage.ts: removed debug logs, unified to providerId
* vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
* settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
- Ensured all parameters now use camelCase exclusively
Test updates:
- Updated MSW handlers to accept both old and new parameter formats during transition
- Added i18n mock compatibility for tests
Root cause:
The issue stemmed from Tauri v2 strictly requiring camelCase for command
parameters, while the codebase was using snake_case. This caused parameters
like 'provider_id' to not be recognized by the backend, resulting in
"missing providerId parameter" errors.
BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
Any external tools or scripts calling these commands must be updated accordingly.
Fixes: Usage query always failing with "missing providerId" error
Fixes: Custom endpoint management not receiving provider ID
Fixes: Import/export dialogs not respecting default paths
2025-11-03 16:50:23 +08:00
|
|
|
return await invoke("import_config_from_file", { filePath });
|
2025-10-16 11:40:02 +08:00
|
|
|
},
|
|
|
|
|
|
2025-10-27 13:20:59 +08:00
|
|
|
async syncCurrentProvidersLive(): Promise<void> {
|
|
|
|
|
const result = (await invoke("sync_current_providers_live")) as {
|
|
|
|
|
success?: boolean;
|
|
|
|
|
message?: string;
|
|
|
|
|
};
|
|
|
|
|
if (!result?.success) {
|
|
|
|
|
throw new Error(result?.message || "Sync current providers failed");
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
2025-10-16 11:40:02 +08:00
|
|
|
async openExternal(url: string): Promise<void> {
|
2025-10-17 16:35:12 +08:00
|
|
|
try {
|
|
|
|
|
const u = new URL(url);
|
|
|
|
|
const scheme = u.protocol.replace(":", "").toLowerCase();
|
|
|
|
|
if (scheme !== "http" && scheme !== "https") {
|
|
|
|
|
throw new Error("Unsupported URL scheme");
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
throw new Error("Invalid URL");
|
|
|
|
|
}
|
2025-10-16 11:40:02 +08:00
|
|
|
await invoke("open_external", { url });
|
|
|
|
|
},
|
2025-10-16 10:00:22 +08:00
|
|
|
};
|