feat(gemini): add Gemini provider integration (#202)
* feat(gemini): add Gemini provider integration - Add gemini_config.rs module for .env file parsing - Extend AppType enum to support Gemini - Implement GeminiConfigEditor and GeminiFormFields components - Add GeminiIcon with standardized 1024x1024 viewBox - Add Gemini provider presets configuration - Update i18n translations for Gemini support - Extend ProviderService and McpService for Gemini * fix(gemini): resolve TypeScript errors, add i18n support, and fix MCP logic **Critical Fixes:** - Fix TS2741 errors in tests/msw/state.ts by adding missing Gemini type definitions - Fix ProviderCard.extractApiUrl to support GOOGLE_GEMINI_BASE_URL display - Add missing apps.gemini i18n keys (zh/en) for proper app name display - Fix MCP service Gemini cross-app duplication logic to prevent self-copy **Technical Details:** - tests/msw/state.ts: Add gemini default providers, current ID, and MCP config - ProviderCard.tsx: Check both ANTHROPIC_BASE_URL and GOOGLE_GEMINI_BASE_URL - services/mcp.rs: Skip Gemini in sync_other_side logic with unreachable!() guards - Run pnpm format to auto-fix code style issues **Verification:** - ✅ pnpm typecheck passes - ✅ pnpm format completed * feat(gemini): enhance authentication and config parsing - Add strict and lenient .env parsing modes - Implement PackyCode partner authentication detection - Support Google OAuth official authentication - Auto-configure security.auth.selectedType for PackyCode - Add comprehensive test coverage for all auth types - Update i18n for OAuth hints and Gemini config --------- Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
@@ -29,6 +29,15 @@ pub async fn get_config_status(app: String) -> Result<ConfigStatus, String> {
|
||||
|
||||
Ok(ConfigStatus { exists, path })
|
||||
}
|
||||
AppType::Gemini => {
|
||||
let env_path = crate::gemini_config::get_gemini_env_path();
|
||||
let exists = env_path.exists();
|
||||
let path = crate::gemini_config::get_gemini_dir()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
Ok(ConfigStatus { exists, path })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +53,7 @@ pub async fn get_config_dir(app: String) -> Result<String, String> {
|
||||
let dir = match AppType::from_str(&app).map_err(|e| e.to_string())? {
|
||||
AppType::Claude => config::get_claude_config_dir(),
|
||||
AppType::Codex => codex_config::get_codex_config_dir(),
|
||||
AppType::Gemini => crate::gemini_config::get_gemini_dir(),
|
||||
};
|
||||
|
||||
Ok(dir.to_string_lossy().to_string())
|
||||
@@ -55,16 +65,17 @@ pub async fn open_config_folder(handle: AppHandle, app: String) -> Result<bool,
|
||||
let config_dir = match AppType::from_str(&app).map_err(|e| e.to_string())? {
|
||||
AppType::Claude => config::get_claude_config_dir(),
|
||||
AppType::Codex => codex_config::get_codex_config_dir(),
|
||||
AppType::Gemini => crate::gemini_config::get_gemini_dir(),
|
||||
};
|
||||
|
||||
if !config_dir.exists() {
|
||||
std::fs::create_dir_all(&config_dir).map_err(|e| format!("创建目录失败: {}", e))?;
|
||||
std::fs::create_dir_all(&config_dir).map_err(|e| format!("创建目录失败: {e}"))?;
|
||||
}
|
||||
|
||||
handle
|
||||
.opener()
|
||||
.open_path(config_dir.to_string_lossy().to_string(), None::<String>)
|
||||
.map_err(|e| format!("打开文件夹失败: {}", e))?;
|
||||
.map_err(|e| format!("打开文件夹失败: {e}"))?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
@@ -87,14 +98,14 @@ pub async fn pick_directory(
|
||||
builder.blocking_pick_folder()
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("弹出目录选择器失败: {}", e))?;
|
||||
.map_err(|e| format!("弹出目录选择器失败: {e}"))?;
|
||||
|
||||
match result {
|
||||
Some(file_path) => {
|
||||
let resolved = file_path
|
||||
.simplified()
|
||||
.into_path()
|
||||
.map_err(|e| format!("解析选择的目录失败: {}", e))?;
|
||||
.map_err(|e| format!("解析选择的目录失败: {e}"))?;
|
||||
Ok(Some(resolved.to_string_lossy().to_string()))
|
||||
}
|
||||
None => Ok(None),
|
||||
@@ -114,13 +125,13 @@ pub async fn open_app_config_folder(handle: AppHandle) -> Result<bool, String> {
|
||||
let config_dir = config::get_app_config_dir();
|
||||
|
||||
if !config_dir.exists() {
|
||||
std::fs::create_dir_all(&config_dir).map_err(|e| format!("创建目录失败: {}", e))?;
|
||||
std::fs::create_dir_all(&config_dir).map_err(|e| format!("创建目录失败: {e}"))?;
|
||||
}
|
||||
|
||||
handle
|
||||
.opener()
|
||||
.open_path(config_dir.to_string_lossy().to_string(), None::<String>)
|
||||
.map_err(|e| format!("打开文件夹失败: {}", e))?;
|
||||
.map_err(|e| format!("打开文件夹失败: {e}"))?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ pub async fn export_config_to_file(
|
||||
}))
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("导出配置失败: {}", e))?
|
||||
.map_err(|e| format!("导出配置失败: {e}"))?
|
||||
.map_err(|e: AppError| e.to_string())
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ pub async fn import_config_from_file(
|
||||
ConfigService::load_config_for_import(&path_buf)
|
||||
})
|
||||
.await
|
||||
.map_err(|e| format!("导入配置失败: {}", e))?
|
||||
.map_err(|e| format!("导入配置失败: {e}"))?
|
||||
.map_err(|e: AppError| e.to_string())?;
|
||||
|
||||
{
|
||||
|
||||
@@ -10,12 +10,12 @@ pub async fn open_external(app: AppHandle, url: String) -> Result<bool, String>
|
||||
let url = if url.starts_with("http://") || url.starts_with("https://") {
|
||||
url
|
||||
} else {
|
||||
format!("https://{}", url)
|
||||
format!("https://{url}")
|
||||
};
|
||||
|
||||
app.opener()
|
||||
.open_url(&url, None::<String>)
|
||||
.map_err(|e| format!("打开链接失败: {}", e))?;
|
||||
.map_err(|e| format!("打开链接失败: {e}"))?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
@@ -29,7 +29,7 @@ pub async fn check_for_updates(handle: AppHandle) -> Result<bool, String> {
|
||||
"https://github.com/farion1231/cc-switch/releases/latest",
|
||||
None::<String>,
|
||||
)
|
||||
.map_err(|e| format!("打开更新页面失败: {}", e))?;
|
||||
.map_err(|e| format!("打开更新页面失败: {e}"))?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
@@ -37,7 +37,7 @@ pub async fn check_for_updates(handle: AppHandle) -> Result<bool, String> {
|
||||
/// 判断是否为便携版(绿色版)运行
|
||||
#[tauri::command]
|
||||
pub async fn is_portable_mode() -> Result<bool, String> {
|
||||
let exe_path = std::env::current_exe().map_err(|e| format!("获取可执行路径失败: {}", e))?;
|
||||
let exe_path = std::env::current_exe().map_err(|e| format!("获取可执行路径失败: {e}"))?;
|
||||
if let Some(dir) = exe_path.parent() {
|
||||
Ok(dir.join("portable.ini").is_file())
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user