doc: update docs/tauri.md (#610)
This commit is contained in:
		@@ -40,7 +40,7 @@ Quick Reference
 | 
			
		||||
[Chown](./docs/chown.md)<!--rehype:style=background: rgb(12 75 51/var(\-\-bg\-opacity));&class=contributing-->  
 | 
			
		||||
[R 语言](./docs/r.md)<!--rehype:style=background: rgb(39 108 192);&class=contributing-->  
 | 
			
		||||
[Elixir](./docs/elixir.md)<!--rehype:style=background: rgb(124 26 156);&class=contributing tag&data-lang=Elixir-->   
 | 
			
		||||
[Tauri](./docs/tauri.md)
 | 
			
		||||
[Tauri](./docs/tauri.md)<!--rehype:style=background: rgb(103 214 237);&class=contributing-->
 | 
			
		||||
<!--rehype:class=home-card-->
 | 
			
		||||
 | 
			
		||||
## 编程
 | 
			
		||||
@@ -102,6 +102,7 @@ Quick Reference
 | 
			
		||||
[React Native](./docs/react-native.md)<!--rehype:style=background: rgb(34 143 173);&class=tag&data-lang=React-->  
 | 
			
		||||
[RegEx 正则表达式](./docs/regex.md)<!--rehype:style=background: rgb(149 36 155);-->  
 | 
			
		||||
[TypeScript](./docs/typescript.md)<!--rehype:style=background: rgb(49 120 198);-->  
 | 
			
		||||
[Tauri](./docs/tauri.md)<!--rehype:style=background: rgb(103 214 237);&class=contributing-->  
 | 
			
		||||
[Vue 2](./docs/vue2.md)<!--rehype:style=background: rgb(64 184 131);-->  
 | 
			
		||||
[Vue 3](./docs/vue.md)<!--rehype:style=background: rgb(64 184 131);&class=contributing-->  
 | 
			
		||||
[</> htmx](./docs/htmx.md)<!--rehype:style=background: rgb(52 101 164);&class=contributing-->  
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								assets/tauri.svg
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								assets/tauri.svg
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
<svg viewBox="0 0 256 289" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid" height="1em" width="1em">
 | 
			
		||||
  <path d="M178.497 104.93c0 15.155-12.285 27.44-27.44 27.44-15.153 0-27.438-12.285-27.438-27.44 0-15.153 12.285-27.438 27.439-27.438s27.439 12.285 27.439 27.439Z" fill="#FFC131"/>
 | 
			
		||||
  <circle fill="#24C8DB" transform="rotate(180 104.91 183.505)" cx="104.911" cy="183.505" r="27.439"/>
 | 
			
		||||
  <path d="M207.93 192.86a104.766 104.766 0 0 1-36.168 14.717 73.586 73.586 0 0 0 3.617-33.176c29.953-10.472 49.82-38.964 49.292-70.69-.53-31.727-21.336-59.542-51.622-69.008-30.286-9.467-63.23 1.546-81.733 27.324a122.227 122.227 0 0 0-40.16 11.723C64.86 29.536 105.956-.445 152.244.005c46.288.45 86.794 31.224 99.636 75.697 12.841 44.473-5.026 92.103-43.95 117.157ZM52.404 92.832l25.693 3.118a73.586 73.586 0 0 1 3.243-14.593 104.766 104.766 0 0 0-28.936 11.475Z" fill="#FFC131"/>
 | 
			
		||||
  <path d="M47.913 95.577a104.766 104.766 0 0 1 36.419-14.842 73.46 73.46 0 0 0-4.116 33.3c-29.847 10.619-49.549 39.148-48.906 70.822.642 31.673 21.484 59.38 51.738 68.78 30.253 9.399 63.127-1.62 81.604-27.352a122.227 122.227 0 0 0 40.16-11.6c-13.736 44.169-54.812 74.1-101.064 73.645-46.252-.453-86.733-31.184-99.602-75.612-12.87-44.427 4.92-92.037 43.768-117.141Zm155.528 100.026-.5.25.5-.25Z" fill="#24C8DB"/>
 | 
			
		||||
</svg>
 | 
			
		||||
| 
		 After Width: | Height: | Size: 1.3 KiB  | 
							
								
								
									
										280
									
								
								docs/tauri.md
									
									
									
									
									
								
							
							
						
						
									
										280
									
								
								docs/tauri.md
									
									
									
									
									
								
							@@ -3,20 +3,278 @@ tauri 备忘清单
 | 
			
		||||
 | 
			
		||||
这个 [tauri](https://tauri.app/) 快速参考备忘单显示了它的常用命令使用清单
 | 
			
		||||
 | 
			
		||||
常用命令
 | 
			
		||||
----
 | 
			
		||||
<!--rehype:body-class=cols-2-->
 | 
			
		||||
命令 | 描述
 | 
			
		||||
:- |:-
 | 
			
		||||
`npm create tauri-app@latest`                      | 创建一个新项目
 | 
			
		||||
`npm install`                      | 安装依赖
 | 
			
		||||
`npm run tauri dev`                      | 应用预览
 | 
			
		||||
入门
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
### 快速开始
 | 
			
		||||
<!--rehype:wrap-class=row-span-3-->
 | 
			
		||||
 | 
			
		||||
Bash
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
sh <(curl https://create.tauri.app/sh)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
PowerShell
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
C:\> irm https://create.tauri.app/ps | iex
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Cargo
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ cargo install create-tauri-app --locked
 | 
			
		||||
$ cargo create-tauri-app
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
npm/yarn/pnpm/bunx
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ npm create tauri-app@latest
 | 
			
		||||
$ yarn create tauri-app
 | 
			
		||||
$ pnpm create tauri-app
 | 
			
		||||
$ bunx create-tauri-app
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### 依赖环境
 | 
			
		||||
 | 
			
		||||
依赖环境
 | 
			
		||||
----
 | 
			
		||||
<!--rehype:body-class=cols-2-->
 | 
			
		||||
软件 | 描述
 | 
			
		||||
:- |:-
 | 
			
		||||
[rust](https://www.rust-lang.org/tools/install)| rust安装
 | 
			
		||||
[nodejs](https://nodejs.org/en)| nodejs安装
 | 
			
		||||
[Build Tools](https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/)| Microsoft C++ 生成工具 (for windows)
 | 
			
		||||
 | 
			
		||||
### 启动 Tauri 开发窗口
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ npm run tauri dev
 | 
			
		||||
$ yarn tauri dev
 | 
			
		||||
$ pnpm tauri dev
 | 
			
		||||
$ bunx tauri dev
 | 
			
		||||
$ cargo tauri dev
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 检测最新版本的 Tauri
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ npm outdated @tauri-apps/cli
 | 
			
		||||
$ yarn outdated @tauri-apps/cli
 | 
			
		||||
$ pnpm add -D @tauri-apps/cli
 | 
			
		||||
$ npm outdated @tauri-apps/cli
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 更新 npm 包
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ npm install @tauri-apps/cli@latest @tauri-apps/api@latest
 | 
			
		||||
$ yarn upgrade @tauri-apps/cli @tauri-apps/api --latest
 | 
			
		||||
$ yarn up @tauri-apps/cli @tauri-apps/api
 | 
			
		||||
$ pnpm update @tauri-apps/cli @tauri-apps/api --latest
 | 
			
		||||
$ bun update @tauri-apps/cli @tauri-apps/api
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 更新 Cargo 包
 | 
			
		||||
 | 
			
		||||
打开 `src-tauri/Cargo.toml` 并更改 `tauri` 和 `tauri-build`
 | 
			
		||||
 | 
			
		||||
```ini
 | 
			
		||||
[build-dependencies]
 | 
			
		||||
tauri-build = "%version%"
 | 
			
		||||
 | 
			
		||||
[dependencies]
 | 
			
		||||
tauri = { version = "%version%" }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
其中 `%version%` 是上面相应的版本号
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ cd src-tauri
 | 
			
		||||
$ cargo update
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 应用程序调试
 | 
			
		||||
 | 
			
		||||
代码中输出日志方法
 | 
			
		||||
 | 
			
		||||
```rust
 | 
			
		||||
println!("Message from Rust: {}", msg);
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
在 Linux 和 macOS 上通过下面命令重新运行
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
RUST_BACKTRACE=1 tauri dev
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Window 上这样开启
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
set RUST_BACKTRACE=1 
 | 
			
		||||
tauri dev
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 以编程方式打开 Devtools
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```rust
 | 
			
		||||
use tauri::Manager;
 | 
			
		||||
tauri::Builder::default()
 | 
			
		||||
  .setup(|app| {
 | 
			
		||||
    #[cfg(debug_assertions)] // 仅在调试构建时包含此代码
 | 
			
		||||
    {
 | 
			
		||||
      let window = app.get_window("main").unwrap();
 | 
			
		||||
      window.open_devtools();
 | 
			
		||||
      window.close_devtools();
 | 
			
		||||
    }
 | 
			
		||||
    Ok(())
 | 
			
		||||
  });
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 在生产中使用检查器
 | 
			
		||||
 | 
			
		||||
```bash
 | 
			
		||||
$ npm run tauri build -- --debug
 | 
			
		||||
$ yarn tauri build --debug
 | 
			
		||||
$ pnpm tauri build --debug
 | 
			
		||||
$ bunx tauri build --debug
 | 
			
		||||
$ cargo tauri build --debug
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### 启用开发工具功能
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
```ini
 | 
			
		||||
[dependencies]
 | 
			
		||||
tauri = { version = "...", features = ["...", "devtools"] }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
在文件 `src-tauri/Cargo.toml` 中启用 `devtools Cargo` 功能
 | 
			
		||||
 | 
			
		||||
配置
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
### 配置结构
 | 
			
		||||
<!--rehype:wrap-class=row-span-2-->
 | 
			
		||||
 | 
			
		||||
默认配置 `tauri.conf.json`,还支持 `tauri.conf.json5` 和 `Tauri.toml`
 | 
			
		||||
 | 
			
		||||
-- | --
 | 
			
		||||
:--- | ---
 | 
			
		||||
`package` | 包设置
 | 
			
		||||
`tauri` | Tauri 配置
 | 
			
		||||
`build` | 构建配置
 | 
			
		||||
`plugins` | 插件配置
 | 
			
		||||
 | 
			
		||||
下面配置能与主配置进行合并
 | 
			
		||||
 | 
			
		||||
- `tauri.linux.conf.json` 或 `Tauri.linux.conf.toml`
 | 
			
		||||
- `tauri.windows.conf.json` 或 `Tauri.windows.conf.toml`
 | 
			
		||||
- `tauri.macos.conf.json` 或 `Tauri.macos.conf.toml`
 | 
			
		||||
 | 
			
		||||
示例
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{
 | 
			
		||||
  "build": { ... },
 | 
			
		||||
  "package": { ... },
 | 
			
		||||
  "tauri": { ... }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Tauri 配置
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
配置 | Type | 描述
 | 
			
		||||
:--- | --- | ---
 | 
			
		||||
`pattern` | [PatternKind](#patternkind) | 应用程序名称
 | 
			
		||||
`version` | [WindowConfig\[\]](#windowconfig) | 应用程序版本
 | 
			
		||||
`cli` | [CliConfig](#cliconfig) | CLI 配置
 | 
			
		||||
`bundle` | BundleConfig | 打包器配置
 | 
			
		||||
`allowlist` | AllowlistConfig | 允许列表配置
 | 
			
		||||
`security` | SecurityConfig | 安全配置
 | 
			
		||||
`updater` | UpdaterConfig | 更新程序配置
 | 
			
		||||
`systemTray` | [SystemTrayConfig](#systemtrayconfig) | 配置应用系统托盘
 | 
			
		||||
`macOSPrivateApi` | boolean | macOS 私有API配置
 | 
			
		||||
<!--rehype:className=left-align-->
 | 
			
		||||
 | 
			
		||||
### CliConfig
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
配置 | Type | 描述
 | 
			
		||||
:--- | --- | ---
 | 
			
		||||
`description` | string? | 将显示在帮助信息中
 | 
			
		||||
`longDescription` | string? | 将显示在帮助信息中
 | 
			
		||||
`beforeHelp` | string? | 该信息显示在自动生成的帮助信息之前。这通常用于标题信息
 | 
			
		||||
`afterHelp` | string? | 显示在自动生成的帮助信息之后。通常用于描述如何使用参数,或者需要注意的注意事项
 | 
			
		||||
`args` | array? | 命令的参数列表
 | 
			
		||||
`subcommands` | object? | 该命令的子命令列表
 | 
			
		||||
<!--rehype:className=left-align-->
 | 
			
		||||
 | 
			
		||||
描述 CLI 配置
 | 
			
		||||
 | 
			
		||||
### Package 配置
 | 
			
		||||
 | 
			
		||||
配置 | 描述
 | 
			
		||||
:--- | ---
 | 
			
		||||
`productName` | 应用程序名称
 | 
			
		||||
`version` | 应用程序版本
 | 
			
		||||
 | 
			
		||||
### WindowConfig
 | 
			
		||||
<!--rehype:wrap-class=col-span-2 row-span-2-->
 | 
			
		||||
 | 
			
		||||
窗口配置对象
 | 
			
		||||
 | 
			
		||||
配置 | Type | 默认值 | 描述
 | 
			
		||||
:--- | --- | --- | ---
 | 
			
		||||
`label` | string | null | 窗口标识符
 | 
			
		||||
`url` | [WindowUrl](#windowurl) | view | 窗口的 webview URL
 | 
			
		||||
`userAgent` | userAgent? | null | webview 的用户代理
 | 
			
		||||
`fileDropEnabled` | boolean | true | 是否在 Web 视图上启用文件放置
 | 
			
		||||
`center` | boolean | false | 窗口是否开始居中
 | 
			
		||||
`x` | number? | null | 窗口左上角的水平位置
 | 
			
		||||
`y` | number? | null | 窗口左上角的水平位置
 | 
			
		||||
`width` | number | 800 | 窗口宽度
 | 
			
		||||
`height` | number | 600 | 窗口高度
 | 
			
		||||
`minWidth` | number | null | 最小窗口宽度
 | 
			
		||||
`minHeight` | number | null | 最小窗口高度
 | 
			
		||||
 | 
			
		||||
### PatternKind
 | 
			
		||||
 | 
			
		||||
应用模式。可以是以下类型中的任意一种:
 | 
			
		||||
 | 
			
		||||
#### 棕地模式
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{ "use": "brownfield" }
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### 隔离模式。建议出于安全目的
 | 
			
		||||
 | 
			
		||||
```json
 | 
			
		||||
{ 
 | 
			
		||||
  "use": "isolation",
 | 
			
		||||
  "options": { "dir": string }
 | 
			
		||||
}
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### WindowUrl
 | 
			
		||||
 | 
			
		||||
要在 Tauri Web 视图窗口中打开的 URL。可以是以下任何一种类型:
 | 
			
		||||
 | 
			
		||||
- `string` (format: `uri`):外部 URL。
 | 
			
		||||
- `string`:应用程序 URL 的路径部分。例如,要加载 `tauri://localhost/users/john`,只需在此配置中提供 `users/john`
 | 
			
		||||
 | 
			
		||||
### SystemTrayConfig
 | 
			
		||||
<!--rehype:wrap-class=col-span-2-->
 | 
			
		||||
 | 
			
		||||
配置 | Type | 默认值 | 描述
 | 
			
		||||
:--- | --- | --- | ---
 | 
			
		||||
`iconPath` | string(必填) | null | 系统托盘上使用的默认图标的路径
 | 
			
		||||
`iconAsTemplate` | boolean | false | 用于确定图像是否代表 macOS 上的[模板](https://developer.apple.com/documentation/appkit/nsimage/1520017-template?language=objc)图像
 | 
			
		||||
`menuOnLeftClick` | boolean | true | 确定在 macOS 上托盘图标收到左键点击时菜单是否应该出现
 | 
			
		||||
`title` | string? | null | MacOS 托盘标题
 | 
			
		||||
<!--rehype:className=left-align-->
 | 
			
		||||
 | 
			
		||||
应用程序系统托盘图标的配置
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user