// 跨平台入口: 桌面从这里走, Android 走 mobile_entry_point 宏 // 启动流程: // 1) Windows 外壳能力注册 (单实例 / 自启动 / 托盘 / 吸附悬浮球, 见 src/shell) // 2) 初始化 tauri-plugin-hotswap (前端 OTA 升级插件) // - 必须在 build 之前调用, 插件会替换 tauri::generate_context! 的 asset provider, // 后续可被 tauri::Builder 消费 // 3) 业务初始化 #[cfg(all(desktop, target_os = "windows"))] mod shell; #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { // 生成 context, 交给 hotswap 包装 (替换 Assets provider, 让 tauri://localhost 资源 // 优先从本地覆盖目录读, 走不到时回退到内置 dist) let context = tauri::generate_context!(); let (hotswap, context) = tauri_plugin_hotswap::init(context) .expect("failed to initialize tauri-plugin-hotswap"); let mut builder = tauri::Builder::default() .invoke_handler(tauri::generate_handler![ dock_hover_start, dock_hover_end, dock_click, dock_drag_start, dock_drag_move, dock_drag_end, ]) .on_window_event(on_window_event); #[cfg(all(desktop, target_os = "windows"))] { builder = builder // 单实例必须最先注册 (W-TRY-07): 二次启动唤回已有实例 .plugin(tauri_plugin_single_instance::init(|app, _argv, _cwd| { shell::activate_primary(app); })) .plugin(tauri_plugin_autostart::init( tauri_plugin_autostart::MacosLauncher::LaunchAgent, Some(vec!["--autostart"]), )) .setup(|app| shell::setup(app)); } builder .plugin(hotswap) .run(context) .expect("error while running iBoard"); } fn on_window_event(window: &tauri::Window, event: &tauri::WindowEvent) { #[cfg(all(desktop, target_os = "windows"))] shell::on_window_event(window, event); #[cfg(not(all(desktop, target_os = "windows")))] { let _ = (window, event); } } // —— 悬浮球 IPC (dock.html → Rust); 非 Windows 桌面平台为 no-op —— #[tauri::command] fn dock_hover_start(app: tauri::AppHandle) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_hover_start(&app); #[cfg(not(all(desktop, target_os = "windows")))] let _ = app; } #[tauri::command] fn dock_hover_end(app: tauri::AppHandle) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_hover_end(&app); #[cfg(not(all(desktop, target_os = "windows")))] let _ = app; } #[tauri::command] fn dock_click(app: tauri::AppHandle) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_click(&app); #[cfg(not(all(desktop, target_os = "windows")))] let _ = app; } #[tauri::command] fn dock_drag_start(app: tauri::AppHandle) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_drag_start(&app); #[cfg(not(all(desktop, target_os = "windows")))] let _ = app; } #[tauri::command] fn dock_drag_move(app: tauri::AppHandle, dx: i32, dy: i32) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_drag_move(&app, dx, dy); #[cfg(not(all(desktop, target_os = "windows")))] { let _ = (app, dx, dy); } } #[tauri::command] fn dock_drag_end(app: tauri::AppHandle) { #[cfg(all(desktop, target_os = "windows"))] shell::dock_drag_end(&app); #[cfg(not(all(desktop, target_os = "windows")))] let _ = app; }