From f15de0cd4fc62b6b6cb0b4d5a121e64880cf66f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Wed, 1 Apr 2026 15:21:46 +0800 Subject: [PATCH] fix(ci): apply rustfmt to tauri sources --- src-tauri/src/commands/agent.rs | 10 +++++++--- src-tauri/src/commands/config.rs | 29 ++++++++++++++++++++++------- src-tauri/src/commands/messaging.rs | 12 ++++++------ src-tauri/src/commands/mod.rs | 4 ++-- src-tauri/src/commands/service.rs | 6 +++++- src-tauri/src/utils.rs | 14 ++++++-------- 6 files changed, 48 insertions(+), 27 deletions(-) diff --git a/src-tauri/src/commands/agent.rs b/src-tauri/src/commands/agent.rs index 1e0f417..ffe50fa 100644 --- a/src-tauri/src/commands/agent.rs +++ b/src-tauri/src/commands/agent.rs @@ -226,7 +226,8 @@ pub async fn list_agents() -> Result { pub async fn get_agent_detail(id: String) -> Result { let config_path = super::openclaw_dir().join("openclaw.json"); let content = fs::read_to_string(&config_path).map_err(|e| format!("读取配置失败: {e}"))?; - let config: Value = serde_json::from_str(&content).map_err(|e| format!("解析 JSON 失败: {e}"))?; + let config: Value = + serde_json::from_str(&content).map_err(|e| format!("解析 JSON 失败: {e}"))?; let defaults = config .get("agents") @@ -330,7 +331,8 @@ pub async fn update_agent_config( ) -> Result { let path = super::openclaw_dir().join("openclaw.json"); let content = fs::read_to_string(&path).map_err(|e| format!("读取配置失败: {e}"))?; - let mut root: Value = serde_json::from_str(&content).map_err(|e| format!("解析 JSON 失败: {e}"))?; + let mut root: Value = + serde_json::from_str(&content).map_err(|e| format!("解析 JSON 失败: {e}"))?; if root.get("agents").is_none() { root.as_object_mut() @@ -364,7 +366,9 @@ pub async fn update_agent_config( let agent = list[idx].as_object_mut().ok_or("Agent 格式错误")?; if let Some(identity) = config.get("identity").and_then(|v| v.as_object()) { - let identity_obj = agent.entry("identity".to_string()).or_insert_with(|| json!({})); + let identity_obj = agent + .entry("identity".to_string()) + .or_insert_with(|| json!({})); let identity_obj = identity_obj.as_object_mut().ok_or("identity 格式错误")?; if let Some(name) = identity.get("name") { if name.is_null() { diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index fad6468..b16fc28 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -1557,7 +1557,10 @@ fn scan_cli_identity(cli_path: &std::path::Path) -> String { .and_then(|name| name.to_str()) .unwrap_or_default() .to_ascii_lowercase(); - if matches!(file_name.as_str(), "openclaw" | "openclaw.exe" | "openclaw.ps1") { + if matches!( + file_name.as_str(), + "openclaw" | "openclaw.exe" | "openclaw.ps1" + ) { let cmd_path = cli_path.with_file_name("openclaw.cmd"); if cmd_path.exists() { identity_path = cmd_path; @@ -1714,9 +1717,19 @@ fn scan_all_installations( if let Some(home) = dirs::home_dir() { try_add(home.join(".npm-global").join("bin").join("openclaw")); try_add(home.join(".local").join("bin").join("openclaw")); - try_add(home.join(".nvm").join("current").join("bin").join("openclaw")); + try_add( + home.join(".nvm") + .join("current") + .join("bin") + .join("openclaw"), + ); try_add(home.join(".volta").join("bin").join("openclaw")); - try_add(home.join(".fnm").join("current").join("bin").join("openclaw")); + try_add( + home.join(".fnm") + .join("current") + .join("bin") + .join("openclaw"), + ); try_add(home.join("bin").join("openclaw")); } try_add(std::path::PathBuf::from("/opt/openclaw/openclaw")); @@ -2116,7 +2129,11 @@ fn npm_global_bin_dir() -> Option { { super::windows_npm_global_prefix() .map(PathBuf::from) - .or_else(|| std::env::var("APPDATA").ok().map(|a| PathBuf::from(a).join("npm"))) + .or_else(|| { + std::env::var("APPDATA") + .ok() + .map(|a| PathBuf::from(a).join("npm")) + }) } #[cfg(target_os = "macos")] { @@ -4613,9 +4630,7 @@ pub fn check_git() -> Result { result.insert("version".into(), Value::String(ver)); result.insert( "path".into(), - git_path - .map(Value::String) - .unwrap_or(Value::Null), + git_path.map(Value::String).unwrap_or(Value::Null), ); } _ => { diff --git a/src-tauri/src/commands/messaging.rs b/src-tauri/src/commands/messaging.rs index 8011507..0ff4435 100644 --- a/src-tauri/src/commands/messaging.rs +++ b/src-tauri/src/commands/messaging.rs @@ -169,8 +169,7 @@ fn normalize_binding_match_value(value: &Value) -> Option { let Some(normalized) = normalize_binding_match_value(item) else { continue; }; - if key == "accountId" - && normalized.as_str().map(|s| s.is_empty()).unwrap_or(false) + if key == "accountId" && normalized.as_str().map(|s| s.is_empty()).unwrap_or(false) { continue; } @@ -234,10 +233,11 @@ fn binding_identity_matches(binding: &Value, agent_id: &str, target_match: &Valu return false; } - let existing_match = normalize_binding_match_value(binding.get("match").unwrap_or(&Value::Null)) - .unwrap_or_else(|| Value::Object(Map::new())); - let expected_match = normalize_binding_match_value(target_match) - .unwrap_or_else(|| Value::Object(Map::new())); + let existing_match = + normalize_binding_match_value(binding.get("match").unwrap_or(&Value::Null)) + .unwrap_or_else(|| Value::Object(Map::new())); + let expected_match = + normalize_binding_match_value(target_match).unwrap_or_else(|| Value::Object(Map::new())); existing_match == expected_match } diff --git a/src-tauri/src/commands/mod.rs b/src-tauri/src/commands/mod.rs index 110945f..b693e93 100644 --- a/src-tauri/src/commands/mod.rs +++ b/src-tauri/src/commands/mod.rs @@ -295,8 +295,8 @@ fn build_enhanced_path() -> String { let home = dirs::home_dir().unwrap_or_default(); // 读取用户保存的自定义 Node.js 路径 - let custom_path = read_panel_config_value() - .and_then(|v| v.get("nodePath")?.as_str().map(String::from)); + let custom_path = + read_panel_config_value().and_then(|v| v.get("nodePath")?.as_str().map(String::from)); #[cfg(target_os = "macos")] { diff --git a/src-tauri/src/commands/service.rs b/src-tauri/src/commands/service.rs index 7d066fa..30e1736 100644 --- a/src-tauri/src/commands/service.rs +++ b/src-tauri/src/commands/service.rs @@ -84,7 +84,11 @@ fn current_gateway_owner_signature() -> (u16, String, Option) { let openclaw_dir = normalize_owned_path(crate::commands::openclaw_dir()); let cli_path = crate::utils::resolve_openclaw_cli_path() .map(|p| normalize_owned_path(std::path::PathBuf::from(p))); - (crate::commands::gateway_listen_port(), openclaw_dir, cli_path) + ( + crate::commands::gateway_listen_port(), + openclaw_dir, + cli_path, + ) } fn read_gateway_owner() -> Option { diff --git a/src-tauri/src/utils.rs b/src-tauri/src/utils.rs index 2341453..9493993 100644 --- a/src-tauri/src/utils.rs +++ b/src-tauri/src/utils.rs @@ -1,10 +1,10 @@ #[cfg(target_os = "windows")] use std::os::windows::process::CommandExt; - pub fn is_rejected_cli_path(cli_path: &str) -> bool { - let lower = cli_path.replace('\\', "/").to_lowercase(); - lower.contains("/.cherrystudio/") || lower.contains("cherry-studio") - } +pub fn is_rejected_cli_path(cli_path: &str) -> bool { + let lower = cli_path.replace('\\', "/").to_lowercase(); + lower.contains("/.cherrystudio/") || lower.contains("cherry-studio") +} /// 读取 clawpanel.json 中用户绑定的 CLI 路径 fn bound_cli_path() -> Option { @@ -180,8 +180,7 @@ pub fn openclaw_command() -> std::process::Command { } #[cfg(not(target_os = "windows"))] { - let bin = resolve_openclaw_cli_path() - .unwrap_or_else(|| "openclaw".into()); + let bin = resolve_openclaw_cli_path().unwrap_or_else(|| "openclaw".into()); let mut cmd = std::process::Command::new(bin); cmd.env("PATH", crate::commands::enhanced_path()); apply_openclaw_dir_env(&mut cmd); @@ -217,8 +216,7 @@ pub fn openclaw_command_async() -> tokio::process::Command { } #[cfg(not(target_os = "windows"))] { - let bin = resolve_openclaw_cli_path() - .unwrap_or_else(|| "openclaw".into()); + let bin = resolve_openclaw_cli_path().unwrap_or_else(|| "openclaw".into()); let mut cmd = tokio::process::Command::new(bin); cmd.env("PATH", crate::commands::enhanced_path()); apply_openclaw_dir_env_tokio(&mut cmd);