feat(0.2.1): 合并 Windows 外壳 + 离线编辑, 版本 0.2.1, 正式域名 https://iboard.honor3.com

This commit is contained in:
jif2.zhang
2026-10-26 20:53:38 +08:00
parent e689e44923
commit eef296942f
74 changed files with 2734 additions and 437 deletions
+94 -3
View File
@@ -1,9 +1,14 @@
// 跨平台入口: 桌面从这里走, Android 走 mobile_entry_point 宏
// 启动流程:
// 1) 初始化 tauri-plugin-hotswap (前端 OTA 升级插件)
// 1) Windows 外壳能力注册 (单实例 / 自启动 / 托盘 / 吸附悬浮球, 见 src/shell)
// 2) 初始化 tauri-plugin-hotswap (前端 OTA 升级插件)
// - 必须在 build 之前调用, 插件会替换 tauri::generate_context! 的 asset provider,
// 后续可被 tauri::Builder 消费
// 2) 业务初始化
// 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 资源
@@ -12,8 +17,94 @@ pub fn run() {
let (hotswap, context) = tauri_plugin_hotswap::init(context)
.expect("failed to initialize tauri-plugin-hotswap");
tauri::Builder::default()
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;
}