Skip to content

Commit c229c47

Browse files
committed
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.
1 parent 6c477a6 commit c229c47

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src-tauri/src/auto_launch.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
use crate::error::AppError;
2-
use auto_launch::AutoLaunch;
2+
use auto_launch::{AutoLaunch, AutoLaunchBuilder};
33

44
/// 初始化 AutoLaunch 实例
55
fn get_auto_launch() -> Result<AutoLaunch, AppError> {
66
let app_name = "CC Switch";
77
let app_path =
88
std::env::current_exe().map_err(|e| AppError::Message(format!("无法获取应用路径: {e}")))?;
99

10-
// Windows 平台的 AutoLaunch::new 只接受 3 个参数
11-
// Linux/macOS 平台需要 4 个参数(包含 hidden 参数)
12-
#[cfg(target_os = "windows")]
13-
let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), &[] as &[&str]);
14-
15-
#[cfg(not(target_os = "windows"))]
16-
let auto_launch = AutoLaunch::new(app_name, &app_path.to_string_lossy(), false, &[] as &[&str]);
10+
// 使用 AutoLaunchBuilder 消除平台差异
11+
// Windows/Linux: new() 接受 3 参数
12+
// macOS: new() 接受 4 参数(含 hidden 参数)
13+
// Builder 模式自动处理这些差异
14+
let auto_launch = AutoLaunchBuilder::new()
15+
.set_app_name(app_name)
16+
.set_app_path(&app_path.to_string_lossy())
17+
.build()
18+
.map_err(|e| AppError::Message(format!("创建 AutoLaunch 失败: {e}")))?;
1719

1820
Ok(auto_launch)
1921
}

0 commit comments

Comments
 (0)