Files
yaoayanui/.cursor/rules/tauri-desktop.mdc
fengchuanhn@gmail.com 584d4c47a1 1
2026-05-15 17:51:47 +08:00

46 lines
1.4 KiB
Plaintext
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.
---
description: Tauri 2 桌面壳、窗口与单例规范
globs: src-tauri/**/*
alwaysApply: false
---
# Tauri 桌面规范
## 窗口配置(`tauri.conf.json`
- 主窗口 `label`: `"main"`(单例回调中通过此 label 获取窗口)
- `decorations: false` — 无边框;`resizable: true`
- `identifier`: `com.aiclient.desktop`(避免以 `.app` 结尾)
## 单例运行
- 插件:`tauri-plugin-single-instance`
- 二次启动时:对 `main` 窗口 `unminimize` → `show` → `set_focus`**不**新建窗口
- 注册于 `src-tauri/src/lib.rs`,需 `use tauri::Manager`
```rust
.plugin(tauri_plugin_single_instance::init(|app, _args, _cwd| {
if let Some(window) = app.get_webview_window("main") {
let _ = window.unminimize();
let _ = window.show();
let _ = window.set_focus();
}
}))
```
## 权限(`capabilities/default.json`
- 拖动窗口需:`core:window:allow-start-dragging`
- 前端标题栏元素使用 `data-tauri-drag-region`(在 `AppTitlebar.vue`
## Rust 约定
- 入口逻辑在 `src/lib.rs``main.rs` 仅调用 `tauri_app_lib::run()`
- 新增 Tauri 命令:在 `lib.rs` 用 `#[tauri::command]` 定义,并在 `invoke_handler` 注册
- 前端调用:`import { invoke } from "@tauri-apps/api/core"`
## 开发注意
- Vite 固定端口 `1420`(见 `vite.config.js`),与 `tauri.conf.json` 的 `devUrl` 一致
- 修改 capabilities 或插件后需重新 `tauri dev` / `tauri build`