import { invoke } from "@tauri-apps/api/core"; import type { Settings } from "@/types"; import type { AppId } from "./types"; export interface ConfigTransferResult { success: boolean; message: string; filePath?: string; backupId?: string; } export const settingsApi = { async get(): Promise { return await invoke("get_settings"); }, async save(settings: Settings): Promise { return await invoke("save_settings", { settings }); }, async restart(): Promise { return await invoke("restart_app"); }, async checkUpdates(): Promise { await invoke("check_for_updates"); }, async isPortable(): Promise { return await invoke("is_portable_mode"); }, async getConfigDir(appId: AppId): Promise { return await invoke("get_config_dir", { app: appId }); }, async openConfigFolder(appId: AppId): Promise { await invoke("open_config_folder", { app: appId }); }, async selectConfigDirectory(defaultPath?: string): Promise { return await invoke("pick_directory", { defaultPath }); }, async getClaudeCodeConfigPath(): Promise { return await invoke("get_claude_code_config_path"); }, async getAppConfigPath(): Promise { return await invoke("get_app_config_path"); }, async openAppConfigFolder(): Promise { await invoke("open_app_config_folder"); }, async getAppConfigDirOverride(): Promise { return await invoke("get_app_config_dir_override"); }, async setAppConfigDirOverride(path: string | null): Promise { return await invoke("set_app_config_dir_override", { path }); }, async applyClaudePluginConfig(options: { official: boolean; }): Promise { const { official } = options; return await invoke("apply_claude_plugin_config", { official }); }, async saveFileDialog(defaultName: string): Promise { return await invoke("save_file_dialog", { defaultName }); }, async openFileDialog(): Promise { return await invoke("open_file_dialog"); }, async exportConfigToFile(filePath: string): Promise { return await invoke("export_config_to_file", { filePath }); }, async importConfigFromFile(filePath: string): Promise { return await invoke("import_config_from_file", { filePath }); }, async syncCurrentProvidersLive(): Promise { 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"); } }, async openExternal(url: string): Promise { 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"); } await invoke("open_external", { url }); }, };