fix(ci): apply rustfmt to tauri sources

This commit is contained in:
晴天
2026-04-01 15:21:46 +08:00
parent b427a6b000
commit f15de0cd4f
6 changed files with 48 additions and 27 deletions

View File

@@ -226,7 +226,8 @@ pub async fn list_agents() -> Result<Value, String> {
pub async fn get_agent_detail(id: String) -> Result<Value, String> {
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<Value, String> {
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() {

View File

@@ -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<PathBuf> {
{
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<Value, String> {
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),
);
}
_ => {

View File

@@ -169,8 +169,7 @@ fn normalize_binding_match_value(value: &Value) -> Option<Value> {
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
}

View File

@@ -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")]
{

View File

@@ -84,7 +84,11 @@ fn current_gateway_owner_signature() -> (u16, String, Option<String>) {
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<GatewayOwnerRecord> {

View File

@@ -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<std::path::PathBuf> {
@@ -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);