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 }