Files
DevFlow/docs/01-技术文档/Tauri-IPC模式-2026-06-12.md

50 lines
1.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Tauri IPC 模式
> 创建: 2026-06-10 | 状态: 初稿
> ⚠️ **已归档2026-06-15**:本文档为初稿,多处过时(:8「仅 greet 示例」→ 实际 68 commands:16-23 待实施 5 项全落地;:35 `frontend/src/` → 实际 `src/`)。实际 IPC 模式见 [ARCHITECTURE.md](../../ARCHITECTURE.md) §三,本文件不再更新,原文保留作历史。
---
## 概述
Tauri v2 的 IPC 机制是 DevFlow 前后端通信的核心桥梁。本文档描述 DevFlow 中 Tauri IPC 的设计模式。
## 当前状态
- Tauri Commands: 仅 `greet` 示例命令
- 业务 IPC: **待实施**
## 设计要点
### 待实施内容
1. **Command 定义** — 在 `src-tauri/src/commands/` 下按模块组织
2. **序列化约定** — Rust 结构体 derive `Serialize`/`Deserialize`
3. **错误传递**`Result<T, String>` 返回给前端
4. **流式支持** — AI 输出、Shell 输出的流式推送
5. **状态注入** — 通过 `tauri::State` 共享 Rust 运行时状态
### IPC 层次
```
Vue Component
→ Pinia Store (Action)
→ @tauri-apps/api (invoke)
→ Tauri Command (Rust)
→ Crate 业务逻辑
→ df-storage (SQLite)
```
### 命名约定
- Rust command: `#[tauri::command] fn get_projects(...)`
- 前端调用: `invoke("get_projects", { ... })`
- Store action: `async fetchProjects()`
## 相关文件
- `src-tauri/src/main.rs` — Tauri 入口
- `src-tauri/src/commands/` — IPC 命令目录
- `frontend/src/stores/` — Pinia Store