新增: Tauri IPC 命令 + useStore 统一接口(B4)
- commands.rs: exec_op/undo/redo/can_undo/can_redo/get_deck/set_navigation/save_file Rust AppState 持有 deck + 历史栈,所有写操作通过 Op Log - bridge.ts: 安全 Tauri IPC 调用层(动态 import,Web 模式 mock) - useStore.ts: 统一 store 接口,检测 __TAURI__ 环境 Web 模式直接调 TS store;Tauri 模式走 invoke - 50 个测试全部通过,前后端编译零错误
This commit is contained in:
@@ -1,46 +1,36 @@
|
||||
/* =====================================================================
|
||||
* lib.rs — Tauri 应用入口
|
||||
*
|
||||
* B0: 脚手架 + ping IPC
|
||||
* B1: 数据模型(model.rs)+ 颜色纯函数(color.rs)
|
||||
* B2: store 迁移(待实现)
|
||||
* B3: AI 引擎迁移(待实现)
|
||||
* ===================================================================== */
|
||||
|
||||
mod ai;
|
||||
mod color;
|
||||
mod commands;
|
||||
mod model;
|
||||
mod op;
|
||||
|
||||
/// IPC 验证命令
|
||||
#[tauri::command]
|
||||
fn ping() -> String {
|
||||
"pong".to_string()
|
||||
}
|
||||
|
||||
/// 返回应用版本信息
|
||||
#[tauri::command]
|
||||
fn app_info() -> serde_json::Value {
|
||||
serde_json::json!({
|
||||
"name": "u-ppt",
|
||||
"version": env!("CARGO_PKG_VERSION"),
|
||||
"platform": std::env::consts::OS,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn run() {
|
||||
let app_state = commands::AppState::new();
|
||||
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![ping, app_info])
|
||||
.manage(app_state)
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
commands::ping,
|
||||
commands::app_info,
|
||||
commands::exec_op,
|
||||
commands::undo,
|
||||
commands::redo,
|
||||
commands::can_undo,
|
||||
commands::can_redo,
|
||||
commands::get_deck,
|
||||
commands::set_navigation,
|
||||
commands::save_file,
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use super::commands;
|
||||
|
||||
#[test]
|
||||
fn test_ping() {
|
||||
assert_eq!(ping(), "pong");
|
||||
assert_eq!(commands::ping(), "pong");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user