Skip to content

Commit c096ba1

Browse files
committed
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
1 parent 7cd6bb9 commit c096ba1

4 files changed

Lines changed: 15 additions & 9 deletions

File tree

src-tauri/src/commands/config.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ fn detect_installed_source() -> String {
259259
}
260260
return "official".into();
261261
}
262+
return "official".into();
262263
}
263264
// Windows: 优先通过文件系统检测,避免 npm list 阻塞
264265
#[cfg(target_os = "windows")]
@@ -479,8 +480,8 @@ pub fn check_node() -> Result<Value, String> {
479480

480481
#[tauri::command]
481482
pub fn write_env_file(path: String, config: String) -> Result<(), String> {
482-
let expanded = if path.starts_with("~/") {
483-
dirs::home_dir().unwrap_or_default().join(&path[2..])
483+
let expanded = if let Some(stripped) = path.strip_prefix("~/") {
484+
dirs::home_dir().unwrap_or_default().join(stripped)
484485
} else {
485486
PathBuf::from(&path)
486487
};

src-tauri/src/commands/device.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn get_or_create_key() -> Result<(String, String, SigningKey), String> {
4646

4747
let device_id = {
4848
let mut hasher = Sha256::new();
49-
hasher.update(&pub_bytes);
49+
hasher.update(pub_bytes);
5050
hex::encode(hasher.finalize())
5151
};
5252
let pub_b64 = base64_url_encode(&pub_bytes);
@@ -77,7 +77,7 @@ mod hex {
7777
data.as_ref().iter().map(|b| format!("{b:02x}")).collect()
7878
}
7979
pub fn decode(s: &str) -> Result<Vec<u8>, String> {
80-
if s.len() % 2 != 0 {
80+
if !s.len().is_multiple_of(2) {
8181
return Err("奇数长度".into());
8282
}
8383
(0..s.len())

src-tauri/src/commands/logs.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ pub fn read_log_tail(log_name: String, lines: Option<u32>) -> Result<String, Str
4040

4141
// 最多从尾部读取 1MB,避免 OOM
4242
let max_read: u64 = 1024 * 1024;
43-
let start_pos = if file_len > max_read {
44-
file_len - max_read
45-
} else {
46-
0
47-
};
43+
let start_pos = file_len.saturating_sub(max_read);
4844

4945
file.seek(SeekFrom::Start(start_pos))
5046
.map_err(|e| format!("Seek 失败: {e}"))?;

src-tauri/src/commands/service.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,15 +465,24 @@ pub async fn get_services_status() -> Result<Vec<ServiceStatus>, String> {
465465

466466
#[tauri::command]
467467
pub async fn start_service(label: String) -> Result<(), String> {
468+
#[cfg(target_os = "macos")]
469+
return platform::start_service_impl(&label);
470+
#[cfg(not(target_os = "macos"))]
468471
platform::start_service_impl(&label).await
469472
}
470473

471474
#[tauri::command]
472475
pub async fn stop_service(label: String) -> Result<(), String> {
476+
#[cfg(target_os = "macos")]
477+
return platform::stop_service_impl(&label);
478+
#[cfg(not(target_os = "macos"))]
473479
platform::stop_service_impl(&label).await
474480
}
475481

476482
#[tauri::command]
477483
pub async fn restart_service(label: String) -> Result<(), String> {
484+
#[cfg(target_os = "macos")]
485+
return platform::restart_service_impl(&label);
486+
#[cfg(not(target_os = "macos"))]
478487
platform::restart_service_impl(&label).await
479488
}

0 commit comments

Comments
 (0)