From c096ba143cc5f10c851f7a78b81feb7ae0dfcd77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=B4=E5=A4=A9?= Date: Wed, 4 Mar 2026 12:31:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20CI=20=E7=BC=96?= =?UTF-8?q?=E8=AF=91=E9=94=99=E8=AF=AF=E4=B8=8E=20Clippy=20=E8=AD=A6?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - service.rs: macOS platform impl 是同步 fn,用 #[cfg] 在 caller 处区分,避免 .await 类型不匹配 - config.rs: macOS detect_installed_source read_link 失败时无 fallback,补充 return official - config.rs: clippy::manual_strip,&path[2..] 改用 strip_prefix - device.rs: clippy::needless_borrow,&pub_bytes 去掉多余引用 - device.rs: clippy::manual_is_multiple_of,% 2 != 0 改用 .is_multiple_of(2) - logs.rs: clippy::manual_arithmetic_check,if/else 改用 saturating_sub --- src-tauri/src/commands/config.rs | 5 +++-- src-tauri/src/commands/device.rs | 4 ++-- src-tauri/src/commands/logs.rs | 6 +----- src-tauri/src/commands/service.rs | 9 +++++++++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/commands/config.rs b/src-tauri/src/commands/config.rs index 56ec473..1a6b831 100644 --- a/src-tauri/src/commands/config.rs +++ b/src-tauri/src/commands/config.rs @@ -259,6 +259,7 @@ fn detect_installed_source() -> String { } return "official".into(); } + return "official".into(); } // Windows: 优先通过文件系统检测,避免 npm list 阻塞 #[cfg(target_os = "windows")] @@ -479,8 +480,8 @@ pub fn check_node() -> Result { #[tauri::command] pub fn write_env_file(path: String, config: String) -> Result<(), String> { - let expanded = if path.starts_with("~/") { - dirs::home_dir().unwrap_or_default().join(&path[2..]) + let expanded = if let Some(stripped) = path.strip_prefix("~/") { + dirs::home_dir().unwrap_or_default().join(stripped) } else { PathBuf::from(&path) }; diff --git a/src-tauri/src/commands/device.rs b/src-tauri/src/commands/device.rs index 10e5285..5f338f3 100644 --- a/src-tauri/src/commands/device.rs +++ b/src-tauri/src/commands/device.rs @@ -46,7 +46,7 @@ fn get_or_create_key() -> Result<(String, String, SigningKey), String> { let device_id = { let mut hasher = Sha256::new(); - hasher.update(&pub_bytes); + hasher.update(pub_bytes); hex::encode(hasher.finalize()) }; let pub_b64 = base64_url_encode(&pub_bytes); @@ -77,7 +77,7 @@ mod hex { data.as_ref().iter().map(|b| format!("{b:02x}")).collect() } pub fn decode(s: &str) -> Result, String> { - if s.len() % 2 != 0 { + if !s.len().is_multiple_of(2) { return Err("奇数长度".into()); } (0..s.len()) diff --git a/src-tauri/src/commands/logs.rs b/src-tauri/src/commands/logs.rs index e12c539..60e6b98 100644 --- a/src-tauri/src/commands/logs.rs +++ b/src-tauri/src/commands/logs.rs @@ -40,11 +40,7 @@ pub fn read_log_tail(log_name: String, lines: Option) -> Result 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}"))?; diff --git a/src-tauri/src/commands/service.rs b/src-tauri/src/commands/service.rs index 60efd1f..acaac25 100644 --- a/src-tauri/src/commands/service.rs +++ b/src-tauri/src/commands/service.rs @@ -465,15 +465,24 @@ pub async fn get_services_status() -> Result, String> { #[tauri::command] pub async fn start_service(label: String) -> Result<(), String> { + #[cfg(target_os = "macos")] + return platform::start_service_impl(&label); + #[cfg(not(target_os = "macos"))] platform::start_service_impl(&label).await } #[tauri::command] pub async fn stop_service(label: String) -> Result<(), String> { + #[cfg(target_os = "macos")] + return platform::stop_service_impl(&label); + #[cfg(not(target_os = "macos"))] platform::stop_service_impl(&label).await } #[tauri::command] pub async fn restart_service(label: String) -> Result<(), String> { + #[cfg(target_os = "macos")] + return platform::restart_service_impl(&label); + #[cfg(not(target_os = "macos"))] platform::restart_service_impl(&label).await }