mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-28 20:00:20 +08:00
fix: 修复 CI 编译错误与 Clippy 警告
- 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
This commit is contained in:
@@ -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<Value, String> {
|
||||
|
||||
#[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)
|
||||
};
|
||||
|
||||
@@ -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<Vec<u8>, String> {
|
||||
if s.len() % 2 != 0 {
|
||||
if !s.len().is_multiple_of(2) {
|
||||
return Err("奇数长度".into());
|
||||
}
|
||||
(0..s.len())
|
||||
|
||||
@@ -40,11 +40,7 @@ pub fn read_log_tail(log_name: String, lines: Option<u32>) -> Result<String, Str
|
||||
|
||||
// 最多从尾部读取 1MB,避免 OOM
|
||||
let max_read: u64 = 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}"))?;
|
||||
|
||||
@@ -465,15 +465,24 @@ pub async fn get_services_status() -> Result<Vec<ServiceStatus>, 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user