Skip to content

Commit

Permalink
Merge branch 'v2' into renovate/jsdom-26.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dreyfus92 authored Jan 14, 2025
2 parents 60e75bd + 80e0421 commit fecc9aa
Show file tree
Hide file tree
Showing 17 changed files with 1,423 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/awesome-tauri
Submodule awesome-tauri updated 1 files
+1 −1 LICENSE
1 change: 1 addition & 0 deletions packages/js-api-generator/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ async function generator() {
'log',
'nfc',
'notification',
'opener',
'os',
'positioner',
'process',
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins-workspace
Submodule plugins-workspace updated 61 files
+0 −7 .changes/updater-builder-header.md
+239 −269 Cargo.lock
+2 −3 Cargo.toml
+14 −0 examples/api/CHANGELOG.md
+23 −23 examples/api/package.json
+23 −0 examples/api/src-tauri/CHANGELOG.md
+6 −6 examples/api/src-tauri/Cargo.toml
+1 −1 examples/api/src-tauri/src/tray.rs
+6 −6 package.json
+1 −1 plugins/clipboard-manager/api-iife.js
+2 −2 plugins/deep-link/Cargo.toml
+2 −2 plugins/deep-link/examples/app/package.json
+2 −2 plugins/fs/Cargo.toml
+1 −1 plugins/fs/api-iife.js
+1 −1 plugins/fs/guest-js/index.ts
+9 −0 plugins/geolocation/CHANGELOG.md
+6 −3 plugins/geolocation/Cargo.toml
+1 −1 plugins/geolocation/api-iife.js
+1 −1 plugins/geolocation/package.json
+0 −5 plugins/geolocation/src/commands.rs
+2 −2 plugins/geolocation/src/error.rs
+0 −42 plugins/geolocation/src/lib.rs
+12 −7 plugins/geolocation/src/models.rs
+1 −1 plugins/global-shortcut/api-iife.js
+9 −0 plugins/haptics/CHANGELOG.md
+6 −3 plugins/haptics/Cargo.toml
+1 −1 plugins/haptics/package.json
+0 −4 plugins/haptics/src/commands.rs
+2 −2 plugins/haptics/src/error.rs
+0 −41 plugins/haptics/src/lib.rs
+6 −4 plugins/haptics/src/models.rs
+4 −0 plugins/notification/CHANGELOG.md
+1 −1 plugins/notification/Cargo.toml
+1 −1 plugins/notification/api-iife.js
+1 −1 plugins/notification/package.json
+8 −0 plugins/opener/CHANGELOG.md
+2 −2 plugins/opener/Cargo.toml
+1 −1 plugins/opener/package.json
+4 −0 plugins/opener/src/open.rs
+1 −1 plugins/shell/api-iife.js
+4 −0 plugins/single-instance/CHANGELOG.md
+1 −1 plugins/single-instance/Cargo.toml
+1 −1 plugins/single-instance/examples/vanilla/package.json
+1 −1 plugins/store/api-iife.js
+1 −1 plugins/store/examples/AppSettingsManager/package.json
+4 −0 plugins/updater/CHANGELOG.md
+1 −1 plugins/updater/Cargo.toml
+1 −1 plugins/updater/api-iife.js
+1 −1 plugins/updater/package.json
+1 −1 plugins/upload/api-iife.js
+5 −0 plugins/websocket/CHANGELOG.md
+2 −2 plugins/websocket/Cargo.toml
+1 −1 plugins/websocket/api-iife.js
+1 −1 plugins/websocket/examples/tauri-app/package.json
+1 −1 plugins/websocket/examples/tauri-app/src-tauri/Cargo.toml
+28 −2 plugins/websocket/guest-js/index.ts
+1 −1 plugins/websocket/package.json
+52 −24 plugins/websocket/src/lib.rs
+1 −1 plugins/window-state/api-iife.js
+556 −552 pnpm-lock.yaml
+5 −2 renovate.json
191 changes: 191 additions & 0 deletions 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 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.
198 changes: 198 additions & 0 deletions public/d2/docs/zh-cn/concept/architecture-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
197 changes: 197 additions & 0 deletions public/d2/docs/zh-cn/concept/process-model-0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/content/docs/develop/state-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ It's a good idea to read the linked documentation fully to understand the trade-

It's common to see [`Arc`] used in Rust to share ownership of a value across multiple threads (usually paired with a [`Mutex`] in the form of `Arc<Mutex<T>>`). However, you don't need to use [`Arc`] for things stored in [`State`] because Tauri will do this for you.

In case `State`'s lifetime requirements prevent you from moving your state into a new thread you can instead move an `AppHandle` into the thread and then retrieve your state as shown below in the "[Access state with the Manager trait](#access-state-with-the-manager-trait)" section. `AppHandle`s are deliberately cheap to clone for use-cases like this.

## Accessing State

### Access state in commands
Expand Down
29 changes: 26 additions & 3 deletions src/content/docs/distribute/Sign/linux.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,35 @@ Note that you need to change the $APPNAME and $VERSION values with the correct o
**The signature is not verified**

AppImage does not validate the signature, so you can't rely on it to check whether the file has been tampered with or not.
To validate the signature, you must provide an external tool for your users.
This requires you to publish your public key on an authenticated channel (e.g. your website served via TLS),
so the end user can download and verify.
The user must manually verify the signature using the AppImage validate tool.
This requires you to publish your key ID on an authenticated channel (e.g. your website served via TLS),
so the end user can view and verify.

See [the official AppImage documentation] for additional information.

:::

[the official appimage documentation]: https://docs.appimage.org/packaging-guide/optional/signatures.html

### Validate the signature

The AppImage validate tool can be downloaded from [here](https://github.com/AppImageCommunity/AppImageUpdate/releases/tag/continuous).
Select one of the `validate-$PLATFORM.AppImage` files.

Run the following command to validate the signature:

```shell
chmod +x validate-$PLATFORM.AppImage
./validate-$PLATFORM.AppImage $TAURI_OUTPUT.AppImage
```

If the signature is valid, the output will be:

```
Validation result: validation successful
Signatures found with key fingerprints: $KEY_ID
====================
Validator report:
Signature checked for key with fingerprint $KEY_ID:
Validation successful
```
136 changes: 136 additions & 0 deletions src/content/docs/plugin/opener.mdx
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} />
8 changes: 6 additions & 2 deletions src/content/docs/plugin/shell.mdx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Shell
description: Access the system shell to manage files and URLs using their default application and to spawn child processes.
description: Access the system shell to spawn child processes.
plugin: shell
---

Expand All @@ -13,12 +13,16 @@ import PluginPermissions from '@components/PluginPermissions.astro';

<PluginLinks plugin={frontmatter.plugin} />

Access the system shell. Allows you to spawn child processes and manage files and URLs using their default application.
Access the system shell. Allows you to spawn child processes.

## Supported Platforms

<Compatibility plugin={frontmatter.plugin} />

## Opener

If you're looking for documentation for the `shell.open` API, check out the new [Opener plugin](../opener/) instead.

## Setup

Install the shell plugin to get started.
Expand Down
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
Loading

0 comments on commit fecc9aa

Please sign in to comment.