IPC
编译器派生的 Tauri commands、绑定与类型化事件。
Tauri 用很小的编译器类型化 command surface 替代 Electron preload。Webview
调用 tauri.<domain>.<method>() 或 useTauri();特权工作始终在 Rust 中完成。
UI 没有 Node API,也没有手写的 Zod IPC schema。
管线
src-tauri/src/commands/ 中的函数同时标注 #[tauri::command] 和
#[specta::specta],再由 lib.rs 的 collect_commands![] 注册。tauri-specta
据此生成并提交 src/lib/bindings.ts;src/lib/tauri/ 的小型 wrapper 提供更易用的
domain API。
pnpm dev 会在 debug 模式重新生成绑定;cargo test --manifest-path src-tauri/Cargo.toml 中的 export_bindings 测试也会生成它,CI 会拒绝漂移。不要手改
bindings.ts。
已提供的 surface
15 个 command 分布在 app(version/platform/open external)、secure
(get/set/delete)、logs(path/tail/open folder)、window(system menu)、
diagnostics 和 update(status/check/download/install)等 domain 中。
import { tauri } from '@/lib/tauri'
const report = await tauri.diagnostics.get()onTauriEvent() 类型化了 single-instance、settings-changed 与
update-status。旧的 use-conveyor.ts 仍被端口迁移组件使用;它适配真正的 Tauri
模块,但 setLocale() 和 windowSetTitlebarDark() 是 no-op,新代码应使用
tauri / useTauri。
添加 command
- 编写带 Tauri 与 Specta attribute 的窄类型 Rust 函数。
- 加入
collect_commands![],它已连接到invoke_handler。 - 运行 dev 或 cargo test,提交生成的 bindings。
- 若使用 plugin API,在 capability 中添加最窄权限,并创建 domain wrapper。
未获授权的 plugin 调用会在实现运行前被 Tauri 拒绝;不要用 wildcard 绕过它。 详见 Capabilities。
