下载/主界面优化
This commit is contained in:
+35
-24
@@ -19,7 +19,7 @@
|
||||
src/modules/<module-name>/
|
||||
├── index.ts # 模块配置(ModuleConfig)
|
||||
├── ModuleComponent.vue # 前端组件
|
||||
src-tauri/src/commands/ # Rust 命令(可选)
|
||||
src-tauri/src/ # Rust 后端逻辑(按功能分文件/模块目录)
|
||||
```
|
||||
|
||||
#### 模块配置类型
|
||||
@@ -167,10 +167,10 @@ onUnmounted(() => {
|
||||
|
||||
### Rust 命令模板
|
||||
|
||||
创建 `src-tauri/src/commands/<name>.rs`:
|
||||
在 `src-tauri/src/` 中创建模块文件(如 `src-tauri/src/my_module.rs` 或 `src-tauri/src/my_module/` 目录),并在 `lib.rs` 中注册:
|
||||
|
||||
```rust
|
||||
// commands/module_name.rs
|
||||
// src-tauri/src/my_module.rs
|
||||
use serde::Serialize;
|
||||
use tauri::State;
|
||||
|
||||
@@ -230,9 +230,9 @@ fn save_data(data: &str) -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
```rust
|
||||
// lib.rs
|
||||
mod commands;
|
||||
mod my_module;
|
||||
|
||||
use commands::module_name::{module_get_data, module_set_data};
|
||||
use my_module::{module_get_data, module_set_data};
|
||||
|
||||
#[tauri::command]
|
||||
fn greet(name: &str) -> String {
|
||||
@@ -254,18 +254,19 @@ pub fn run() {
|
||||
|
||||
## 常用 Tauri 插件
|
||||
|
||||
| 插件 | 用途 | 安装命令 |
|
||||
|------|------|----------|
|
||||
| `tauri-plugin-autostart` | 开机自启 | `cargo add tauri-plugin-autostart` |
|
||||
| `tauri-plugin-tray` | 系统托盘 | `cargo add tauri-plugin-tray` |
|
||||
| `tauri-plugin-log` | 日志系统 | `cargo add tauri-plugin-log` |
|
||||
| `tauri-plugin-shell` | 执行命令 | `cargo add tauri-plugin-shell` |
|
||||
| `tauri-plugin-clipboard-manager` | 剪贴板 | `cargo add tauri-plugin-clipboard-manager` |
|
||||
| `tauri-plugin-window-state` | 窗口状态 | `cargo add tauri-plugin-window-state` |
|
||||
项目当前使用的 Tauri 插件(见 `Cargo.toml`):
|
||||
|
||||
| 插件 | 用途 |
|
||||
|------|------|
|
||||
| `tauri-plugin-autostart` | 开机自启 |
|
||||
| `tauri-plugin-opener` | 打开文件/目录/URL(绕过 IPC scope 限制) |
|
||||
| `tauri-plugin-dialog` | 文件/目录选择对话框 |
|
||||
|
||||
> 系统托盘(tray)和窗口效果(mica/acrylic)是 Tauri 2 内置能力,无需额外插件。日志系统为自建(`src-tauri/src/logger.rs`),未使用 `tauri-plugin-log`。
|
||||
|
||||
## 进程管理
|
||||
|
||||
对于需要管理外部进程的模块(如 mihomo、aria2),使用内置的 `ProcessManager`:
|
||||
对于需要管理外部子进程的模块(如 mihomo),使用内置的 `ProcessManager`。下载器模块使用进程内自建下载引擎(`src-tauri/src/download_engine/`),不涉及外部子进程:
|
||||
|
||||
### 架构
|
||||
|
||||
@@ -349,21 +350,31 @@ rusqlite = { version = "0.30", features = ["bundled"] }
|
||||
|
||||
## 权限配置
|
||||
|
||||
在 `src-tauri/capabilities/default.json` 中配置权限:
|
||||
在 `src-tauri/capabilities/default.json` 中配置权限(实际项目配置):
|
||||
|
||||
```json
|
||||
{
|
||||
"$schema": "../node_modules/@tauri-apps/cli/schemas/desktop-capability.json",
|
||||
"$schema": "../gen/schemas/desktop-schema.json",
|
||||
"identifier": "default",
|
||||
"description": "Default capabilities for the app",
|
||||
"description": "Capability for the main window",
|
||||
"windows": ["main"],
|
||||
"permissions": [
|
||||
"core:default",
|
||||
"shell:allow-execute",
|
||||
"shell:allow-spawn",
|
||||
"path:allow-app-data-dir",
|
||||
"path:allow-read",
|
||||
"path:allow-write"
|
||||
"opener:default",
|
||||
"opener:allow-reveal-item-in-dir",
|
||||
"opener:allow-open-path",
|
||||
"dialog:default",
|
||||
"core:window:allow-minimize",
|
||||
"core:window:allow-maximize",
|
||||
"core:window:allow-close",
|
||||
"core:window:allow-toggle-maximize",
|
||||
"core:window:allow-hide",
|
||||
"core:window:allow-show",
|
||||
"core:window:allow-set-focus",
|
||||
"core:window:allow-start-dragging",
|
||||
"core:window:allow-set-effects",
|
||||
"core:window:allow-set-background-color",
|
||||
"core:window:allow-set-theme"
|
||||
]
|
||||
}
|
||||
```
|
||||
@@ -425,8 +436,8 @@ let path = Path::new("data").join("config.json");
|
||||
# 创建前端模块目录
|
||||
mkdir -p src/modules/new-module
|
||||
|
||||
# 创建 Rust 命令文件
|
||||
touch src-tauri/src/commands/new_module.rs
|
||||
# 创建 Rust 模块文件
|
||||
touch src-tauri/src/new_module.rs
|
||||
```
|
||||
|
||||
### 模板文件
|
||||
|
||||
Reference in New Issue
Block a user