chore: format code and clean up unused props

- Run cargo fmt on Rust backend code
- Format TypeScript imports and code style
- Remove unused appId prop from ProviderPresetSelector
- Clean up unused variables in tests
- Integrate notes field handling in provider dialogs
This commit is contained in:
YoVinchen
2025-11-17 16:45:57 +08:00
parent ec1ae7073f
commit 6b5752db24
15 changed files with 71 additions and 56 deletions
+4 -4
View File
@@ -317,7 +317,9 @@ impl MultiAppConfig {
// 迁移通用配置片段:claude_common_config_snippet → common_config_snippets.claude
if let Some(old_claude_snippet) = config.claude_common_config_snippet.take() {
log::info!("迁移通用配置:claude_common_config_snippet → common_config_snippets.claude");
log::info!(
"迁移通用配置:claude_common_config_snippet → common_config_snippets.claude"
);
config.common_config_snippets.claude = Some(old_claude_snippet);
updated = true;
}
@@ -414,9 +416,7 @@ impl MultiAppConfig {
return Ok(false);
}
log::info!(
"检测到已存在配置文件且 Prompt 列表为空,将尝试从现有提示词文件自动导入"
);
log::info!("检测到已存在配置文件且 Prompt 列表为空,将尝试从现有提示词文件自动导入");
let mut imported = false;
for app in [AppType::Claude, AppType::Codex, AppType::Gemini] {
+5 -7
View File
@@ -139,13 +139,11 @@ pub fn upsert_mcp_server(id: &str, spec: Value) -> Result<bool, AppError> {
if is_http || is_sse {
let url = spec.get("url").and_then(|x| x.as_str()).unwrap_or("");
if url.is_empty() {
return Err(AppError::McpValidation(
if is_http {
"http 类型的 MCP 服务器缺少 url 字段".into()
} else {
"sse 类型的 MCP 服务器缺少 url 字段".into()
},
));
return Err(AppError::McpValidation(if is_http {
"http 类型的 MCP 服务器缺少 url 字段".into()
} else {
"sse 类型的 MCP 服务器缺少 url 字段".into()
}));
}
}
+5 -7
View File
@@ -184,13 +184,12 @@ pub async fn get_common_config_snippet(
use crate::app_config::AppType;
use std::str::FromStr;
let app = AppType::from_str(&app_type)
.map_err(|e| format!("无效的应用类型: {}", e))?;
let app = AppType::from_str(&app_type).map_err(|e| format!("无效的应用类型: {e}"))?;
let guard = state
.config
.read()
.map_err(|e| format!("读取配置锁失败: {}", e))?;
.map_err(|e| format!("读取配置锁失败: {e}"))?;
Ok(guard.common_config_snippets.get(&app).cloned())
}
@@ -205,13 +204,12 @@ pub async fn set_common_config_snippet(
use crate::app_config::AppType;
use std::str::FromStr;
let app = AppType::from_str(&app_type)
.map_err(|e| format!("无效的应用类型: {}", e))?;
let app = AppType::from_str(&app_type).map_err(|e| format!("无效的应用类型: {e}"))?;
let mut guard = state
.config
.write()
.map_err(|e| format!("写入配置锁失败: {}", e))?;
.map_err(|e| format!("写入配置锁失败: {e}"))?;
// 验证格式(根据应用类型)
if !snippet.trim().is_empty() {
@@ -219,7 +217,7 @@ pub async fn set_common_config_snippet(
AppType::Claude | AppType::Gemini => {
// 验证 JSON 格式
serde_json::from_str::<serde_json::Value>(&snippet)
.map_err(|e| format!("无效的 JSON 格式: {}", e))?;
.map_err(|e| format!("无效的 JSON 格式: {e}"))?;
}
AppType::Codex => {
// TOML 格式暂不验证(或可使用 toml crate)
-2
View File
@@ -48,8 +48,6 @@ pub fn read_mcp_json() -> Result<Option<String>, AppError> {
Ok(Some(content))
}
/// 读取 Gemini settings.json 中的 mcpServers 映射
pub fn read_mcp_servers_map() -> Result<std::collections::HashMap<String, Value>, AppError> {
let path = user_config_path();
+2 -10
View File
@@ -396,11 +396,7 @@ pub fn import_from_claude(config: &mut MultiAppConfig) -> Result<usize, AppError
}
if !errors.is_empty() {
log::warn!(
"导入完成,但有 {} 项失败: {:?}",
errors.len(),
errors
);
log::warn!("导入完成,但有 {} 项失败: {:?}", errors.len(), errors);
}
Ok(changed)
@@ -783,11 +779,7 @@ pub fn import_from_gemini(config: &mut MultiAppConfig) -> Result<usize, AppError
}
if !errors.is_empty() {
log::warn!(
"导入完成,但有 {} 项失败: {:?}",
errors.len(),
errors
);
log::warn!("导入完成,但有 {} 项失败: {:?}", errors.len(), errors);
}
Ok(changed)