新增: Rust 数据模型 + 颜色纯函数 + ts-rs 类型同步(B1)
- model.rs: 全部数据结构(Deck/Slide/Element/Style/Theme/AiCfg/LibItem/PageTemplate/ChatMessage/Op/RichSegment) 所有结构体 derive Serialize/Deserialize/TS,自动生成 TS 类型到 bindings/types.ts - color.rs: 颜色解析纯函数(resolve_color/resolve_bg/is_dark_bg/shade/hex_to_rgb) 对应 store.ts 的颜色逻辑,23 个单元测试全部通过 - lib.rs: 新增 app_info IPC 命令 - ts-rs 自动生成的 bindings/types.ts 与手写 types.ts 类型一致
This commit is contained in:
@@ -1,19 +1,44 @@
|
||||
/* =====================================================================
|
||||
* lib.rs — Tauri 应用入口(B0 脚手架)
|
||||
* lib.rs — Tauri 应用入口
|
||||
*
|
||||
* 当前阶段:Vue 前端原样跑在 WebView 里,Rust 端只有 ping 验证 IPC。
|
||||
* 后续 B1-B5 逐步迁移核心逻辑到 Rust。
|
||||
* B0: 脚手架 + ping IPC
|
||||
* B1: 数据模型(model.rs)+ 颜色纯函数(color.rs)
|
||||
* B2: store 迁移(待实现)
|
||||
* B3: AI 引擎迁移(待实现)
|
||||
* ===================================================================== */
|
||||
|
||||
/// IPC 验证命令:前端 invoke('ping') → 返回 'pong'
|
||||
mod color;
|
||||
mod model;
|
||||
|
||||
/// 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() {
|
||||
tauri::Builder::default()
|
||||
.invoke_handler(tauri::generate_handler![ping])
|
||||
.invoke_handler(tauri::generate_handler![ping, app_info])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_ping() {
|
||||
assert_eq!(ping(), "pong");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user