-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'v2' into renovate/jsdom-26.x
- Loading branch information
Showing
17 changed files
with
1,423 additions
and
8 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 |
---|---|---|
|
@@ -43,7 +43,7 @@ | |
"starlight-blog": "^0.15.0", | ||
"starlight-links-validator": "^0.13.0" | ||
}, | ||
"packageManager": "[email protected].3", | ||
"packageManager": "[email protected].4", | ||
"engines": { | ||
"pnpm": "^9.0.0" | ||
}, | ||
|
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 |
---|---|---|
|
@@ -73,6 +73,7 @@ async function generator() { | |
'log', | ||
'nfc', | ||
'notification', | ||
'opener', | ||
'os', | ||
'positioner', | ||
'process', | ||
|
Submodule plugins-workspace
updated
61 files
191 changes: 191 additions & 0 deletions
191
public/d2/docs/zh-cn/concept/Inter-Process Communication/index-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
194 changes: 194 additions & 0 deletions
194
public/d2/docs/zh-cn/concept/Inter-Process Communication/index-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
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,136 @@ | ||
--- | ||
title: Opener | ||
description: Open files and URLs in external applications. | ||
plugin: opener | ||
--- | ||
|
||
import PluginLinks from '@components/PluginLinks.astro'; | ||
import Compatibility from '@components/plugins/Compatibility.astro'; | ||
|
||
import { Tabs, TabItem, Steps } from '@astrojs/starlight/components'; | ||
import CommandTabs from '@components/CommandTabs.astro'; | ||
import PluginPermissions from '@components/PluginPermissions.astro'; | ||
|
||
<PluginLinks plugin={frontmatter.plugin} /> | ||
|
||
This plugin allows you to open files and URLs in a specified, or the default, application. It also supports "revealing" files in the system's file explorer. | ||
|
||
## Supported Platforms | ||
|
||
<Compatibility plugin={frontmatter.plugin} /> | ||
|
||
## Setup | ||
|
||
Install the opener plugin to get started. | ||
|
||
<Tabs> | ||
<TabItem label="Automatic" > | ||
Use your project's package manager to add the dependency: | ||
|
||
{ ' ' } | ||
|
||
<CommandTabs | ||
npm="npm run tauri add opener" | ||
yarn="yarn run tauri add opener" | ||
pnpm="pnpm tauri add opener" | ||
deno="deno task tauri add opener" | ||
bun="bun tauri add opener" | ||
cargo="cargo tauri add opener" | ||
/> | ||
</TabItem> | ||
<TabItem label = "Manual"> | ||
<Steps> | ||
1. Run the following command in the `src-tauri` folder to add the plugin to the project's dependencies in `Cargo.toml`: | ||
|
||
```sh frame=none | ||
cargo add tauri-plugin-opener | ||
``` | ||
|
||
2. Modify `lib.rs` to initialize the plugin: | ||
|
||
```rust title="src-tauri/src/lib.rs" ins={4} | ||
#[cfg_attr(mobile, tauri::mobile_entry_point)] | ||
pub fn run() { | ||
tauri::Builder::default() | ||
.plugin(tauri_plugin_opener::init()) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} | ||
``` | ||
|
||
3. Install the JavaScript Guest bindings using your preferred JavaScript package manager: | ||
|
||
<CommandTabs | ||
npm = "npm install @tauri-apps/plugin-opener" | ||
yarn = "yarn add @tauri-apps/plugin-opener" | ||
pnpm = "pnpm add @tauri-apps/plugin-opener" | ||
deno = "deno add npm:@tauri-apps/plugin-opener" | ||
bun = "bun add @tauri-apps/plugin-opener" | ||
/> | ||
</Steps> | ||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
## Usage | ||
|
||
The shell plugin is available in both JavaScript and Rust. | ||
|
||
<Tabs syncKey="lang"> | ||
<TabItem label="JavaScript" > | ||
|
||
```javascript | ||
import { openPath } from '@tauri-apps/plugin-opener'; | ||
// when using `"withGlobalTauri": true`, you may use | ||
// const { openPath } = window.__TAURI__.opener; | ||
|
||
// opens a file using the default program: | ||
await openPath('/path/to/file'); | ||
// opens a file using `vlc` command on Windows: | ||
await openPath('C:/path/to/file', 'vlc'); | ||
``` | ||
|
||
</TabItem> | ||
<TabItem label = "Rust" > | ||
|
||
Note that `app` is an instance of `App` or [`AppHandle`](https://docs.rs/tauri/2.0.0/tauri/struct.AppHandle.html). | ||
|
||
```rust | ||
use tauri_plugin_opener::OpenerExt; | ||
|
||
// opens a file using the default program: | ||
app.opener().open_path("/path/to/file", None::<&str>); | ||
// opens a file using `vlc` command on Windows: | ||
app.opener().open_path("C:/path/to/file", Some("vlc")); | ||
``` | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
## Permissions | ||
|
||
By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your `capabilities` configuration to enable these. | ||
|
||
See the [Capabilities Overview](/security/capabilities/) for more information and the [step by step guide](/learn/security/using-plugin-permissions/) to use plugin permissions. | ||
|
||
```json title="src-tauri/capabilities/default.json" ins={6-15} | ||
{ | ||
"$schema": "../gen/schemas/desktop-schema.json", | ||
"identifier": "main-capability", | ||
"description": "Capability for the main window", | ||
"windows": ["main"], | ||
"permissions": [ | ||
{ | ||
"identifier": "opener:allow-open-path", | ||
"allow": [ | ||
{ | ||
"path": "/path/to/file" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
``` | ||
|
||
<PluginPermissions plugin={frontmatter.plugin} /> |
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
93 changes: 93 additions & 0 deletions
93
src/content/docs/zh-cn/concept/Inter-Process Communication/index.mdx
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,93 @@ | ||
--- | ||
title: 进程间通信 | ||
sidebar: | ||
label: 概述 | ||
order: 1 | ||
i18nReady: true | ||
--- | ||
|
||
import { CardGrid, LinkCard } from '@astrojs/starlight/components'; | ||
|
||
进程间通信(IPC)允许隔离的进程安全地进行通信,是构建更复杂应用程序的关键。 | ||
|
||
在以下指南中了解特定的 IPC 模式: | ||
|
||
<CardGrid> | ||
<LinkCard | ||
title="Brownfield" | ||
href="/concept/inter-process-communication/brownfield/" | ||
/> | ||
<LinkCard | ||
title="Isolation" | ||
href="/concept/inter-process-communication/isolation/" | ||
/> | ||
</CardGrid> | ||
|
||
Tauri 使用一种特定风格的进程间通信,称为[异步消息传递],其中进程通过一些简单的数据表示交换*请求*和*响应*。对于任何有 Web 开发经验的人来说,消息传递应该听起来很熟悉,因为这种范式用于互联网的客户端-服务器通信。 | ||
|
||
消息传递是一种比共享内存或直接函数访问更安全的技术,因为接收方可以自由地拒绝或丢弃请求。例如,如果Tauri核心进程确定某个请求是恶意的,它将简单地丢弃该请求,并且不会执行相应的函数。 | ||
|
||
接下来,我们将更详细地解释 Tauri 的两个 IPC 原语——`事件`和`命令`。 | ||
|
||
## 事件 | ||
|
||
事件是一次性、单向的 IPC 消息,最适合用于通信生命周期事件和状态变化。与[命令](#命令)不同,事件可以由前端*和* Tauri 核心发出。 | ||
|
||
<figure> | ||
|
||
```d2 sketch pad=50 | ||
shape: sequence_diagram | ||
Frontend: { | ||
shape: rectangle | ||
label: "Webview\nFrontend" | ||
} | ||
Core: { | ||
shape: rectangle | ||
label: "Core\nBackend" | ||
} | ||
Frontend -> Core: "Event"{style.animated: true} | ||
Core -> Frontend: "Event"{style.animated: true} | ||
``` | ||
|
||
<figcaption>在核心和 Webview 之间发送的事件。</figcaption> | ||
</figure> | ||
|
||
## 命令 | ||
|
||
Tauri 还提供了一种类似于[外部函数接口]的抽象,建立在IPC消息之上[^1]。主要 API `invoke` 类似于浏览器的`fetch` API,允许前端调用 Rust 函数、传递参数并接收数据。 | ||
|
||
由于该机制在底层使用类似 [JSON-RPC] 的协议来序列化请求和响应,因此所有参数和返回数据必须能够序列化为 JSON。 | ||
|
||
<figure> | ||
|
||
```d2 sketch pad=50 | ||
shape: sequence_diagram | ||
Frontend: { | ||
label: "Webview\nFrontend" | ||
} | ||
Core: { | ||
label: "Core\nBackend" | ||
} | ||
InvokeHandler: { | ||
label: "Invoke\nHandler" | ||
} | ||
Frontend -> Core: "IPC Request"{style.animated: true} | ||
Core -> InvokeHandler: "Invoke command"{style.animated: true} | ||
InvokeHandler -> Core: "Serialize return"{style.animated: true} | ||
Core -> Frontend: "Response"{style.animated: true} | ||
``` | ||
|
||
<figcaption>命令调用中涉及的 IPC 消息。</figcaption> | ||
</figure> | ||
|
||
[^1]: 由于命令在底层仍然使用消息传递,因此它们没有真实 FFI 接口所面临的安全隐患。 | ||
|
||
[异步消息传递]: https://en.wikipedia.org/wiki/Message_passing#Asynchronous_message_passing | ||
[json-rpc]: https://www.jsonrpc.org | ||
[外部函数接口]: https://en.wikipedia.org/wiki/Foreign_function_interface |
Oops, something went wrong.