From c229c47c00c283f5bc8eea4c54cfdc40e5e675ee Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 28 Nov 2025 22:59:09 +0800 Subject: [PATCH] fix(auto-launch): use AutoLaunchBuilder for cross-platform compatibility The auto-launch crate has different API signatures on each platform: - Windows/Linux: AutoLaunch::new() takes 3 arguments - macOS: AutoLaunch::new() takes 4 arguments (includes hidden param) The previous code used #[cfg(not(target_os = "windows"))] which incorrectly applied macOS's 4-argument signature to Linux, causing build failures. Switch to AutoLaunchBuilder which handles platform differences internally. --- src-tauri/src/auto_launch.rs | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src-tauri/src/auto_launch.rs b/src-tauri/src/auto_launch.rs index cf677cd50..bdb7748af 100644 --- a/src-tauri/src/auto_launch.rs +++ b/src-tauri/src/auto_launch.rs @@ -1,5 +1,5 @@ use crate::error::AppError; -use auto_launch::AutoLaunch; +use auto_launch::{AutoLaunch, AutoLaunchBuilder}; /// 初始化 AutoLaunch 实例 fn get_auto_launch() -> Result { @@ -7,13 +7,15 @@ fn get_auto_launch() -> Result { let app_path = std::env::current_exe().map_err(|e| AppError::Message(format!("无法获取应用路径: {e}")))?; - // Windows 平台的 AutoLaunch::new 只接受 3 个参数 - // Linux/macOS 平台需要 4 个参数(包含 hidden 参数) - #[cfg(target_os = "windows")] - let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), &[] as &[&str]); - - #[cfg(not(target_os = "windows"))] - let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), false, &[] as &[&str]); + // 使用 AutoLaunchBuilder 消除平台差异 + // Windows/Linux: new() 接受 3 参数 + // macOS: new() 接受 4 参数(含 hidden 参数) + // Builder 模式自动处理这些差异 + let auto_launch = AutoLaunchBuilder::new() + .set_app_name(app_name) + .set_app_path(&app_path.to_string_lossy()) + .build() + .map_err(|e| AppError::Message(format!("创建 AutoLaunch 失败: {e}")))?; Ok(auto_launch) }