-
Notifications
You must be signed in to change notification settings - Fork 659
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i18n(zh-cn): translate
features/process.mdx
and `features/clipboard…
….mdx` (#1902) * translate `features/process.mdx` to zh_CN * translate features/clipboard.mdx to zh_CN * update `features/clipboard.mdx` * translate features/localhost.mdx to zh_CN * translate features/autostart.mdx to zh_CN * update clipboard.mdx * Update src/content/docs/zh-cn/features/autostart.mdx Co-authored-by: DK Liao <[email protected]> * Update src/content/docs/zh-cn/features/localhost.mdx Co-authored-by: DK Liao <[email protected]> * Update src/content/docs/zh-cn/features/process.mdx Co-authored-by: DK Liao <[email protected]> * Update src/content/docs/zh-cn/features/autostart.mdx Co-authored-by: DK Liao <[email protected]> * Update src/content/docs/zh-cn/features/process.mdx Co-authored-by: DK Liao <[email protected]> --------- Co-authored-by: DK Liao <[email protected]>
- Loading branch information
Showing
4 changed files
with
405 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
--- | ||
title: 自动启动 | ||
description: 在系统启动时自动启动应用程序。 | ||
--- | ||
|
||
import PluginLinks from '@components/PluginLinks.astro'; | ||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import CommandTabs from '@components/CommandTabs.astro'; | ||
|
||
<PluginLinks plugin="autostart" /> | ||
|
||
在系统启动时自动启动应用程序。 | ||
|
||
## 支持的平台 | ||
|
||
- Windows | ||
- Mac(通过 AppleScript 或启动代理) | ||
- Linux | ||
|
||
## 设置 | ||
|
||
请安装 autostart 插件。 | ||
|
||
<Tabs> | ||
<TabItem label="自动"> | ||
|
||
使用项目的包管理器来添加依赖。 | ||
|
||
{' '} | ||
|
||
<CommandTabs | ||
npm="npm run tauri add autostart" | ||
yarn="yarn run tauri add autostart" | ||
pnpm="pnpm tauri add autostart" | ||
cargo="cargo tauri add autostart" | ||
/> | ||
|
||
</TabItem> | ||
<TabItem label="手动"> | ||
|
||
1. 运行 `cargo add tauri-plugin-autostart` 命令,将插件添加到项目的 `Cargo.toml` 依赖中。 | ||
|
||
2. 修改 `lib.rs` 来初始化插件。 | ||
|
||
```rust title="lib.rs" ins={1, 6} | ||
use tauri_plugin_autostart::MacosLauncher; | ||
|
||
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
fn run() { | ||
tauri::Builder::default() | ||
.plugin(tauri_plugin_autostart::init(MacosLauncher::LaunchAgent, Some(vec!["--flag1", "--flag2"]) /* arbitrary number of args to pass to your app */)) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` | ||
|
||
3. 你可以使用你喜欢的 JavaScript 包管理器来安装 JavaScript Guest 绑定。 | ||
|
||
<CommandTabs | ||
npm="npm install @tauri-apps/plugin-autostart" | ||
yarn="yarn add @tauri-apps/plugin-autostart" | ||
pnpm="pnpm add @tauri-apps/plugin-autostart" | ||
/> | ||
</TabItem> | ||
</Tabs> | ||
|
||
## 用法 | ||
|
||
autostart 插件有 JavaScript 和 Rust 两种版本。 | ||
|
||
<Tabs> | ||
<TabItem label="JavaScript"> | ||
|
||
```js | ||
import { enable, isEnabled, disable } from '@tauri-apps/plugin-autostart'; | ||
|
||
// 启用 autostart | ||
await enable(); | ||
// 检查 enable 状态 | ||
console.log(`registered for autostart? ${await isEnabled()}`); | ||
// 禁用 autostart | ||
disable(); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem label="Rust"> | ||
|
||
```rust | ||
use tauri_plugin_autostart::MacosLauncher; | ||
use tauri_plugin_autostart::ManagerExt; | ||
|
||
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
fn run() { | ||
tauri::Builder::default() | ||
.plugin(tauri_plugin_autostart::init( | ||
MacosLauncher::LaunchAgent, | ||
Some(vec!["--flag1", "--flag2"]), | ||
)) | ||
.setup(|app| { | ||
// Get the autostart manager | ||
let autostart_manager = app.autolaunch(); | ||
// 启用 autostart | ||
let _ = autostart_manager.enable(); | ||
// 检查 enable 状态 | ||
println!("registered for autostart? {}", autostart_manager.is_enabled().unwrap()); | ||
// 禁用 autostart | ||
let _ = autostart_manager.disable(); | ||
Ok(()) | ||
}) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` | ||
|
||
</TabItem> | ||
</Tabs> | ||
|
||
## 权限 | ||
|
||
默认情况下,所有插件命令都被阻止,无法访问。 | ||
你必须在你的 `capabilities` 配置中定义一个权限列表。 | ||
|
||
更多信息请参见 [Access Control List](/references/v2/acl)。 | ||
|
||
```json title="src-tauri/capabilities/main.json" | ||
{ | ||
"permissions": [ | ||
..., | ||
"autostart:allow-enable", | ||
"autostart:allow-disable", | ||
"autostart:allow-is-enabled" | ||
] | ||
} | ||
``` | ||
|
||
| 权限 | 描述 | | ||
| ---------------------------- | ------------------------------------------ | | ||
| `autostart:allow-disable` | 启用 disable 命令,不需要预先配置作用域。 | | ||
| `autostart:deny-disable` | 拒绝没有预先配置作用域的 disable 命令。 | | ||
| `autostart:allow-enable` | 启用 enable 命令,不需要预先配置作用域。 | | ||
| `autostart:deny-enable` | 拒绝使用没有预先配置作用域的 enable 命令。 | | ||
| `autostart:allow-is-enabled` | 启用没有预先配置作用域的 is_enabled 命令。 | | ||
| `autostart:deny-is-enabled` | 拒绝没有预先配置作用域的 is_enabled 命令。 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
--- | ||
title: 剪切板 | ||
description: 读取和写入系统剪贴板。 | ||
--- | ||
|
||
import Stub from '@components/Stub.astro'; | ||
import PluginLinks from '@components/PluginLinks.astro'; | ||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import CommandTabs from '@components/CommandTabs.astro'; | ||
|
||
<PluginLinks plugin="clipboard-manager" /> | ||
|
||
使用剪贴板插件读取和写入系统剪贴板。 | ||
|
||
## 设置 | ||
|
||
请安装剪贴板插件。 | ||
|
||
<Tabs> | ||
<TabItem label="自动"> | ||
|
||
使用项目的包管理器来添加依赖: | ||
|
||
<CommandTabs npm="npm run tauri add clipboard-manager" | ||
yarn="yarn run tauri add clipboard-manager" | ||
pnpm="pnpm tauri add clipboard-manager" | ||
cargo="cargo tauri add clipboard-manager" /> | ||
|
||
</TabItem> | ||
<TabItem label="手动"> | ||
|
||
1. 运行 `cargo add tauri-plugin-clipboard-manager` 命令,将插件添加到项目的 `Cargo.toml` 依赖中。 | ||
|
||
2. 修改 `lib.rs` 来初始化插件。 | ||
|
||
```rust | ||
// lib.rs | ||
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
pub fn run() { | ||
tauri::Builder::default() | ||
// Initialize the plugin | ||
.plugin(tauri_plugin_clipboard_manager::init()) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` | ||
|
||
3. 如果你想用 JavaScript 管理剪贴板,还需要安装 npm 包。 | ||
|
||
<CommandTabs | ||
npm="npm install @tauri-apps/plugin-clipboard-manager" | ||
yarn="yarn add @tauri-apps/plugin-clipboard-manager" | ||
pnpm="pnpm add @tauri-apps/plugin-clipboard-manager" | ||
/> | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
## 用法 | ||
|
||
{/* TODO: Link to which language to use, frontend vs. backend guide when it's made */} | ||
|
||
剪贴板插件有 JavaScript 和 Rust 两种版本。 | ||
|
||
<Tabs> | ||
<TabItem label="JavaScript"> | ||
|
||
```js | ||
import { writeText, readText } from '@tauri-apps/plugin-clipboard-manager'; | ||
|
||
// 将内容写到剪贴板 | ||
await writeText('Tauri is awesome!'); | ||
|
||
// 从剪贴板读取内容 | ||
const content = await readText(); | ||
console.log(content); | ||
// Prints "Tauri is awesome!" to the console | ||
``` | ||
|
||
</TabItem> | ||
<TabItem label="Rust"> | ||
|
||
```rust | ||
use tauri_plugin_clipboard_manager::ClipboardExt; | ||
|
||
// 将内容写到剪贴板 | ||
let clipboard_content = tauri_plugin_clipboard_manager::ClipKind::PlainText { | ||
label: Some("Label".to_string()), | ||
text: "Tauri is awesome!".to_string(), | ||
}; | ||
app.clipboard().write(clipboard_content).unwrap(); | ||
|
||
// 从剪贴板读取内容 | ||
let content = app.clipboard().read(); | ||
println!("{:?}", content.unwrap()); | ||
// Prints "Tauri is awesome!" to the terminal | ||
|
||
|
||
``` | ||
|
||
</TabItem> | ||
</Tabs> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
--- | ||
title: Localhost | ||
description: 在生产环境中使用 localhost 服务器。 | ||
--- | ||
|
||
import PluginLinks from '@components/PluginLinks.astro'; | ||
import { Tabs, TabItem } from '@astrojs/starlight/components'; | ||
import CommandTabs from '@components/CommandTabs.astro'; | ||
|
||
<PluginLinks plugin="localhost" showJsLinks={false} /> | ||
|
||
通过 localhost 服务器而不是默认的自定义协议公开你的应用资源。 | ||
|
||
:::caution | ||
这个插件带来了相当大的安全风险,你只应该在知道你在做什么的情况下使用它。如果有疑问,请使用默认的自定义协议实现。 | ||
::: | ||
|
||
## 支持的平台 | ||
|
||
- Windows | ||
- Linux | ||
- macOS | ||
|
||
## 设置 | ||
|
||
_这个插件要求 Rust 版本至少是 **1.75**_ | ||
|
||
1. 通过将以下内容添加到 `Cargo.toml` 中来安装 localhost 插件。 | ||
|
||
```toml title="src-tauri/Cargo.toml" | ||
[dependencies] | ||
tauri-plugin-localhost = "2.0.0-beta" | ||
# alternatively with Git: | ||
tauri-plugin-localhost = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } | ||
``` | ||
|
||
2. 修改 `lib.rs` 来初始化插件。 | ||
|
||
```rust title="src-tauri/src/lib.rs" ins={3} | ||
fn run() { | ||
tauri::Builder::default() | ||
.plugin(tauri_plugin_localhost::Builder::new().build()) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` | ||
|
||
## 用法 | ||
|
||
Rust 提供了 localhost 插件。 | ||
|
||
```rust title="src-tauri/src/lib.rs" {4} {7-14} | ||
use tauri::{webview::WebviewWindowBuilder, WebviewUrl}; | ||
|
||
fn run() { | ||
let port: u16 = 9527; | ||
|
||
tauri::Builder::default() | ||
.plugin(tauri_plugin_localhost::Builder::new(port).build()) | ||
.setup(move |app| { | ||
let url = format!("http://localhost:{}", port).parse().unwrap(); | ||
WebviewWindowBuilder::new(app, "main".to_string(), WebviewUrl::External(url)) | ||
.title("Localhost Example") | ||
.build()?; | ||
Ok(()) | ||
}) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` |
Oops, something went wrong.