diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index d2152b5..92921e9 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -12,9 +12,14 @@ use crate::store::AppState; #[tauri::command] pub async fn get_providers( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, ) -> Result, String> { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let config = state .config @@ -32,9 +37,14 @@ pub async fn get_providers( #[tauri::command] pub async fn get_current_provider( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let config = state .config @@ -52,10 +62,15 @@ pub async fn get_current_provider( #[tauri::command] pub async fn add_provider( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, provider: Provider, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let mut config = state .config @@ -97,10 +112,15 @@ pub async fn add_provider( #[tauri::command] pub async fn update_provider( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, provider: Provider, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let mut config = state .config @@ -164,10 +184,15 @@ pub async fn update_provider( #[tauri::command] pub async fn delete_provider( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, id: String, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let mut config = state .config @@ -216,10 +241,15 @@ pub async fn delete_provider( #[tauri::command] pub async fn switch_provider( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, id: String, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); let mut config = state .config @@ -304,9 +334,14 @@ pub async fn switch_provider( #[tauri::command] pub async fn import_default_config( state: State<'_, AppState>, + app_type: Option, app: Option, + appType: Option, ) -> Result { - let app_type = app.as_deref().map(|s| s.into()).unwrap_or(AppType::Claude); + let app_type = app_type + .or_else(|| app.as_deref().map(|s| s.into())) + .or_else(|| appType.as_deref().map(|s| s.into())) + .unwrap_or(AppType::Claude); // 若已存在 default 供应商,则直接返回,避免重复导入 { diff --git a/src/lib/tauri-api.ts b/src/lib/tauri-api.ts index 6c439fe..105cf67 100644 --- a/src/lib/tauri-api.ts +++ b/src/lib/tauri-api.ts @@ -22,7 +22,7 @@ export const tauriAPI = { // 获取所有供应商 getProviders: async (app?: AppType): Promise> => { try { - return await invoke("get_providers", { app }); + return await invoke("get_providers", { app_type: app, app }); } catch (error) { console.error("获取供应商列表失败:", error); return {}; @@ -32,7 +32,7 @@ export const tauriAPI = { // 获取当前供应商ID getCurrentProvider: async (app?: AppType): Promise => { try { - return await invoke("get_current_provider", { app }); + return await invoke("get_current_provider", { app_type: app, app }); } catch (error) { console.error("获取当前供应商失败:", error); return ""; @@ -42,7 +42,7 @@ export const tauriAPI = { // 添加供应商 addProvider: async (provider: Provider, app?: AppType): Promise => { try { - return await invoke("add_provider", { provider, app }); + return await invoke("add_provider", { provider, app_type: app, app }); } catch (error) { console.error("添加供应商失败:", error); throw error; @@ -55,7 +55,7 @@ export const tauriAPI = { app?: AppType, ): Promise => { try { - return await invoke("update_provider", { provider, app }); + return await invoke("update_provider", { provider, app_type: app, app }); } catch (error) { console.error("更新供应商失败:", error); throw error; @@ -65,7 +65,7 @@ export const tauriAPI = { // 删除供应商 deleteProvider: async (id: string, app?: AppType): Promise => { try { - return await invoke("delete_provider", { id, app }); + return await invoke("delete_provider", { id, app_type: app, app }); } catch (error) { console.error("删除供应商失败:", error); throw error; @@ -78,7 +78,7 @@ export const tauriAPI = { app?: AppType, ): Promise => { try { - return await invoke("switch_provider", { id: providerId, app }); + return await invoke("switch_provider", { id: providerId, app_type: app, app }); } catch (error) { console.error("切换供应商失败:", error); return false; @@ -90,7 +90,7 @@ export const tauriAPI = { app?: AppType, ): Promise => { try { - const success = await invoke("import_default_config", { app }); + const success = await invoke("import_default_config", { app_type: app, app }); return { success, message: success ? "成功导入默认配置" : "导入失败",