diff --git a/src-tauri/src/codex_config.rs b/src-tauri/src/codex_config.rs index 8789860..5bda93c 100644 --- a/src-tauri/src/codex_config.rs +++ b/src-tauri/src/codex_config.rs @@ -1,9 +1,8 @@ -use serde_json::Value; -use std::fs; +// unused imports removed use std::path::PathBuf; use crate::config::{ - copy_file, delete_file, read_json_file, sanitize_provider_name, write_json_file, + delete_file, sanitize_provider_name, }; /// 获取 Codex 配置目录路径 @@ -36,56 +35,6 @@ pub fn get_codex_provider_paths( (auth_path, config_path) } -/// 备份 Codex 当前配置 -pub fn backup_codex_config(provider_id: &str, provider_name: &str) -> Result<(), String> { - let auth_path = get_codex_auth_path(); - let config_path = get_codex_config_path(); - let (backup_auth_path, backup_config_path) = - get_codex_provider_paths(provider_id, Some(provider_name)); - - // 备份 auth.json - if auth_path.exists() { - copy_file(&auth_path, &backup_auth_path)?; - log::info!("已备份 Codex auth.json: {}", backup_auth_path.display()); - } - - // 备份 config.toml - if config_path.exists() { - copy_file(&config_path, &backup_config_path)?; - log::info!("已备份 Codex config.toml: {}", backup_config_path.display()); - } - - Ok(()) -} - -/// 保存 Codex 供应商配置副本 -pub fn save_codex_provider_config( - provider_id: &str, - provider_name: &str, - settings_config: &Value, -) -> Result<(), String> { - let (auth_path, config_path) = get_codex_provider_paths(provider_id, Some(provider_name)); - - // 保存 auth.json - if let Some(auth) = settings_config.get("auth") { - write_json_file(&auth_path, auth)?; - } - - // 保存 config.toml - if let Some(config) = settings_config.get("config") { - if let Some(config_str) = config.as_str() { - // 若非空则进行 TOML 语法校验 - if !config_str.trim().is_empty() { - toml::from_str::(config_str) - .map_err(|e| format!("config.toml 格式错误: {}", e))?; - } - crate::config::write_text_file(&config_path, config_str)?; - } - } - - Ok(()) -} - /// 删除 Codex 供应商配置文件 pub fn delete_codex_provider_config(provider_id: &str, provider_name: &str) -> Result<(), String> { let (auth_path, config_path) = get_codex_provider_paths(provider_id, Some(provider_name)); @@ -96,77 +45,4 @@ pub fn delete_codex_provider_config(provider_id: &str, provider_name: &str) -> R Ok(()) } -/// 从 Codex 供应商配置副本恢复到主配置 -pub fn restore_codex_provider_config(provider_id: &str, provider_name: &str) -> Result<(), String> { - let (provider_auth_path, provider_config_path) = - get_codex_provider_paths(provider_id, Some(provider_name)); - let auth_path = get_codex_auth_path(); - let config_path = get_codex_config_path(); - - // 确保目录存在 - if let Some(parent) = auth_path.parent() { - fs::create_dir_all(parent).map_err(|e| format!("创建 Codex 目录失败: {}", e))?; - } - - // 复制 auth.json(必需) - if provider_auth_path.exists() { - copy_file(&provider_auth_path, &auth_path)?; - log::info!("已恢复 Codex auth.json"); - } else { - return Err(format!( - "供应商 auth.json 不存在: {}", - provider_auth_path.display() - )); - } - - // 复制 config.toml(可选,允许为空;不存在则创建空文件以保持一致性) - if provider_config_path.exists() { - copy_file(&provider_config_path, &config_path)?; - log::info!("已恢复 Codex config.toml"); - } else { - // 写入空文件 - crate::config::write_text_file(&config_path, "") - .map_err(|e| format!("创建空的 config.toml 失败: {}", e))?; - log::info!("供应商 config.toml 缺失,已创建空文件"); - } - - Ok(()) -} - -/// 导入当前 Codex 配置为默认供应商 -pub fn import_current_codex_config() -> Result { - let auth_path = get_codex_auth_path(); - let config_path = get_codex_config_path(); - - // 行为放宽:仅要求 auth.json 存在;config.toml 可缺失 - if !auth_path.exists() { - return Err("Codex 配置文件不存在".to_string()); - } - - // 读取 auth.json - let auth = read_json_file::(&auth_path)?; - - // 读取 config.toml(允许不存在或读取失败时为空) - let config_str = if config_path.exists() { - let s = fs::read_to_string(&config_path) - .map_err(|e| format!("读取 config.toml 失败: {}", e))?; - if !s.trim().is_empty() { - toml::from_str::(&s) - .map_err(|e| format!("config.toml 语法错误: {}", e))?; - } - s - } else { - String::new() - }; - - // 组合成完整配置 - let settings_config = serde_json::json!({ - "auth": auth, - "config": config_str - }); - - // 保存为默认供应商副本 - save_codex_provider_config("default", "default", &settings_config)?; - - Ok(settings_config) -} +//(移除未使用的备份/保存/恢复/导入函数,避免 dead_code 告警) diff --git a/src-tauri/src/config.rs b/src-tauri/src/config.rs index 2b58268..10b39c4 100644 --- a/src-tauri/src/config.rs +++ b/src-tauri/src/config.rs @@ -1,5 +1,5 @@ use serde::{Deserialize, Serialize}; -use serde_json::Value; +// unused import removed use std::fs; use std::io::Write; use std::path::{Path, PathBuf}; @@ -44,7 +44,7 @@ pub fn get_archive_root() -> PathBuf { get_app_config_dir().join("archive") } -fn ensure_unique_path(mut dest: PathBuf) -> PathBuf { +fn ensure_unique_path(dest: PathBuf) -> PathBuf { if !dest.exists() { return dest; } @@ -209,27 +209,4 @@ pub fn get_claude_config_status() -> ConfigStatus { } } -/// 备份配置文件 -pub fn backup_config(from: &Path, to: &Path) -> Result<(), String> { - if from.exists() { - copy_file(from, to)?; - log::info!("已备份配置文件: {} -> {}", from.display(), to.display()); - } - Ok(()) -} - -/// 导入当前 Claude Code 配置为默认供应商 -pub fn import_current_config_as_default() -> Result { - let settings_path = get_claude_settings_path(); - - if !settings_path.exists() { - return Err("Claude Code 配置文件不存在".to_string()); - } - - // 读取当前配置 - let settings_config: Value = read_json_file(&settings_path)?; - - // 不再写入供应商副本文件,这里仅返回读取到的配置 - log::info!("已读取当前配置用于默认供应商导入"); - Ok(settings_config) -} +//(移除未使用的备份/导入函数,避免 dead_code 告警) diff --git a/src-tauri/src/provider.rs b/src-tauri/src/provider.rs index 76b3ba8..924cfbf 100644 --- a/src-tauri/src/provider.rs +++ b/src-tauri/src/provider.rs @@ -50,13 +50,6 @@ impl Default for ProviderManager { } impl ProviderManager { - /// 添加供应商 - pub fn add_provider(&mut self, provider: Provider) -> Result<(), String> { - // 仅添加到管理器(SSOT:统一由 cc-switch/config.json 持久化) - self.providers.insert(provider.id.clone(), provider); - Ok(()) - } - /// 获取所有供应商 pub fn get_all_providers(&self) -> &HashMap { &self.providers