mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-28 03:40:09 +08:00
fix: 修复所有 Clippy 警告,CI 质量门禁全部通过
- agent.rs: !...is_some() → .is_none() (nonminimal_bool) - config.rs: 去掉 macOS/Windows 块多余 return (needless_return) - config.rs: &old_pkg → old_pkg (needless_borrow) - logs.rs: 第二处 saturating_sub + filter_map → map_while (lines_filter_map_ok) - memory.rs: 两处 for/if-let → .iter().flatten() (manual_flatten) - tray.rs: let _ = future → std::mem::drop (let_underscore_future)
This commit is contained in:
@@ -114,7 +114,7 @@ pub fn update_agent_identity(
|
||||
.ok_or(format!("Agent「{id}」不存在"))?;
|
||||
|
||||
// 确保 identity 字段存在且为对象
|
||||
if !agent.get("identity").and_then(|i| i.as_object()).is_some() {
|
||||
if agent.get("identity").and_then(|i| i.as_object()).is_none() {
|
||||
agent
|
||||
.as_object_mut()
|
||||
.ok_or("Agent 格式错误")?
|
||||
|
||||
@@ -259,7 +259,7 @@ fn detect_installed_source() -> String {
|
||||
}
|
||||
return "official".into();
|
||||
}
|
||||
return "official".into();
|
||||
"official".into()
|
||||
}
|
||||
// Windows: 优先通过文件系统检测,避免 npm list 阻塞
|
||||
#[cfg(target_os = "windows")]
|
||||
@@ -274,7 +274,7 @@ fn detect_installed_source() -> String {
|
||||
return "chinese".into();
|
||||
}
|
||||
}
|
||||
return "official".into();
|
||||
"official".into()
|
||||
}
|
||||
// 所有平台通用: npm list 检测
|
||||
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
|
||||
@@ -339,7 +339,7 @@ pub async fn upgrade_openclaw(app: tauri::AppHandle, source: String) -> Result<S
|
||||
// 先检查是否真的安装了旧包,如果没有安装,npm uninstall 会报错但不影响
|
||||
let _ = app.emit("upgrade-log", format!("清理遗留环境 ({old_pkg})..."));
|
||||
let _ = app.emit("upgrade-progress", 5);
|
||||
let _ = npm_command().args(["uninstall", "-g", &old_pkg]).output();
|
||||
let _ = npm_command().args(["uninstall", "-g", old_pkg]).output();
|
||||
}
|
||||
|
||||
let _ = app.emit("upgrade-log", format!("$ npm install -g {pkg}"));
|
||||
|
||||
@@ -87,11 +87,7 @@ pub fn search_log(
|
||||
|
||||
// 搜索最多读取尾部 2MB,避免 OOM,同时保证搜索最新内容
|
||||
let max_read: u64 = 2 * 1024 * 1024;
|
||||
let start_pos = if file_len > max_read {
|
||||
file_len - max_read
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let start_pos = file_len.saturating_sub(max_read);
|
||||
|
||||
file.seek(SeekFrom::Start(start_pos))
|
||||
.map_err(|e| format!("Seek 失败: {e}"))?;
|
||||
@@ -101,7 +97,7 @@ pub fn search_log(
|
||||
|
||||
let mut matched: Vec<String> = reader
|
||||
.lines()
|
||||
.filter_map(|l| l.ok())
|
||||
.map_while(Result::ok)
|
||||
.filter(|l| l.to_lowercase().contains(&query_lower))
|
||||
.collect();
|
||||
|
||||
|
||||
@@ -121,12 +121,10 @@ pub async fn read_memory_file(path: String, agent_id: Option<String>) -> Result<
|
||||
memory_dir_for_agent(aid, "core").await,
|
||||
];
|
||||
|
||||
for c in &candidates {
|
||||
if let Ok(dir) = c {
|
||||
let full = dir.join(&path);
|
||||
if full.exists() {
|
||||
return fs::read_to_string(&full).map_err(|e| format!("读取失败: {e}"));
|
||||
}
|
||||
for dir in candidates.iter().flatten() {
|
||||
let full = dir.join(&path);
|
||||
if full.exists() {
|
||||
return fs::read_to_string(&full).map_err(|e| format!("读取失败: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,12 +166,10 @@ pub async fn delete_memory_file(path: String, agent_id: Option<String>) -> Resul
|
||||
memory_dir_for_agent(aid, "core").await,
|
||||
];
|
||||
|
||||
for c in &candidates {
|
||||
if let Ok(dir) = c {
|
||||
let full = dir.join(&path);
|
||||
if full.exists() {
|
||||
return fs::remove_file(&full).map_err(|e| format!("删除失败: {e}"));
|
||||
}
|
||||
for dir in candidates.iter().flatten() {
|
||||
let full = dir.join(&path);
|
||||
if full.exists() {
|
||||
return fs::remove_file(&full).map_err(|e| format!("删除失败: {e}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,13 +60,19 @@ fn handle_menu_event(app: &AppHandle, id: &str) {
|
||||
}
|
||||
}
|
||||
"gateway_start" => {
|
||||
let _ = crate::commands::service::start_service("ai.openclaw.gateway".into());
|
||||
std::mem::drop(crate::commands::service::start_service(
|
||||
"ai.openclaw.gateway".into(),
|
||||
));
|
||||
}
|
||||
"gateway_stop" => {
|
||||
let _ = crate::commands::service::stop_service("ai.openclaw.gateway".into());
|
||||
std::mem::drop(crate::commands::service::stop_service(
|
||||
"ai.openclaw.gateway".into(),
|
||||
));
|
||||
}
|
||||
"gateway_restart" => {
|
||||
let _ = crate::commands::service::restart_service("ai.openclaw.gateway".into());
|
||||
std::mem::drop(crate::commands::service::restart_service(
|
||||
"ai.openclaw.gateway".into(),
|
||||
));
|
||||
}
|
||||
"quit" => {
|
||||
app.exit(0);
|
||||
|
||||
Reference in New Issue
Block a user