D4nm4ku 项目教程
D4nm4ku使用 Tauri 写一个弹幕姬(已停止更新,或许会在几年后重写)项目地址:https://gitcode.com/gh_mirrors/d4/D4nm4ku
1. 项目的目录结构及介绍
D4nm4ku 项目的目录结构如下:
D4nm4ku/
├── index.html
├── src/
│ ├── main.rs
│ ├── lib.rs
│ └── ...
├── package.json
├── pnpm-lock.yaml
├── tauri.conf.json
└── ...
目录结构介绍
- index.html: 项目的入口 HTML 文件。
- src/: 包含项目的 Rust 源代码文件。
- main.rs: 主程序入口文件。
- lib.rs: 库文件,可能包含项目的核心逻辑。
- package.json: Node.js 项目的配置文件,定义了项目的依赖和脚本。
- pnpm-lock.yaml: 锁定文件,确保依赖版本的一致性。
- tauri.conf.json: Tauri 配置文件,定义了应用的配置选项。
2. 项目的启动文件介绍
main.rs
main.rs
是项目的启动文件,负责初始化应用并启动主进程。以下是 main.rs
的基本结构:
fn main() {
tauri::Builder::default()
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
启动流程
- 初始化 Tauri 应用: 使用
tauri::Builder::default()
初始化 Tauri 应用。 - 生成上下文: 调用
tauri::generate_context!()
生成应用上下文。 - 运行应用: 调用
.run()
方法启动应用,并处理可能的错误。
3. 项目的配置文件介绍
tauri.conf.json
tauri.conf.json
是 Tauri 应用的配置文件,定义了应用的各种配置选项。以下是配置文件的基本结构:
{
"build": {
"distDir": "../dist",
"devPath": "http://localhost:3000",
"beforeDevCommand": "npm run dev",
"beforeBuildCommand": "npm run build"
},
"ctx": {},
"tauri": {
"bundle": {
"identifier": "com.example.app",
"icon": ["icons/32x32.png", "icons/128x128.png"]
},
"allowlist": {
"all": true
},
"windows": [
{
"title": "D4nm4ku",
"width": 800,
"height": 600,
"resizable": true,
"fullscreen": false
}
]
}
}
配置项介绍
- build: 定义构建相关的配置。
- distDir: 构建输出目录。
- devPath: 开发模式下的前端资源路径。
- beforeDevCommand: 开发模式前执行的命令。
- beforeBuildCommand: 构建前执行的命令。
- tauri: 定义 Tauri 应用的配置。
- bundle: 应用打包配置。
- identifier: 应用的唯一标识符。
- icon: 应用图标。
- allowlist: 权限白名单配置。
- windows: 定义应用窗口的配置。
- title: 窗口标题。
- width: 窗口宽度。
- height: 窗口高度。
- resizable: 窗口是否可调整大小。
- fullscreen: 是否全屏启动。
- bundle: 应用打包配置。
通过以上配置,可以灵活地调整 D4nm4ku 应用的行为和外观。
D4nm4ku使用 Tauri 写一个弹幕姬(已停止更新,或许会在几年后重写)项目地址:https://gitcode.com/gh_mirrors/d4/D4nm4ku