Skip to content
Tauri 中文网

Tauri 架构

简介

¥Introduction

Tauri 是一个多语言和通用工具包,非常可组合,允许工程师制作各种各样的应用。它用于使用 Rust 工具和在 Webview 中渲染的 HTML 组合为台式计算机构建应用。使用 Tauri 构建的应用可以附带任意数量的可选 JS API 和 Rust API,以便 webviews 可以通过消息传递来控制系统。开发者可以使用自己的功能扩展默认 API,并轻松连接 Webview 和基于 Rust 的后端。

¥Tauri is a polyglot and generic toolkit that is very composable and allows engineers to make a wide variety of applications. It is used for building applications for desktop computers using a combination of Rust tools and HTML rendered in a Webview. Apps built with Tauri can ship with any number of pieces of an optional JS API and Rust API so that webviews can control the system via message passing. Developers can extend the default API with their own functionality and bridge the Webview and Rust-based backend easily.

Tauri 应用可以拥有 托盘类型界面。它们可以是 updated,并由用户的操作系统按预期进行管理。它们非常小,因为它们使用操作系统的 webview。它们不附带运行时,因为最终的二进制文件是从 Rust 编译而来的。这构成了 逆转 Tauri 应用并非易事

¥Tauri apps can have tray-type interfaces. They can be updated and are managed by the user’s operating system as expected. They are very small because they use the OS’s webview. They do not ship a runtime since the final binary is compiled from Rust. This makes the reversing of Tauri apps not a trivial task.

Tauri 不是什么

¥What Tauri is Not

Tauri 不是轻量级内核封装器。相反,它直接使用 WRYTAO 来完成对操作系统进行系统调用的繁重工作。

¥Tauri is not a lightweight kernel wrapper. Instead, it directly uses WRY and TAO to do the heavy lifting in making system calls to the OS.

Tauri 不是 VM 或虚拟化环境。相反,它是一个允许制作 Webview OS 应用的应用工具包。

¥Tauri is not a VM or virtualized environment. Instead, it is an application toolkit that allows making Webview OS applications.

核心生态系统

¥Core Ecosystem

Diagram
Simplified representation of the Tauri architecture.

tauri

在 GitHub 上查看

¥View on GitHub

这是将所有内容整合在一起的主要包。它将运行时、宏、实用程序和 API 整合到一个最终产品中。它在编译时读取 tauri.conf.json 文件以引入功能并进行应用的实际配置(甚至是项目文件夹中的 Cargo.toml 文件)。它在运行时处理脚本注入(用于 polyfill/原型修订),托管用于系统交互的 API,甚至管理更新过程。

¥This is the major crate that holds everything together. It brings the runtimes, macros, utilities and API into one final product. It reads the tauri.conf.json file at compile time to bring in features and undertake the actual configuration of the app (and even the Cargo.toml file in the project’s folder). It handles script injection (for polyfills / prototype revision) at runtime, hosts the API for systems interaction, and even manages the updating process.

tauri-runtime

在 GitHub 上查看

¥View on GitHub

Tauri 本身和更底层的 webview 库之间的粘合层。

¥The glue layer between Tauri itself and lower-level webview libraries.

tauri-macros

在 GitHub 上查看

¥View on GitHub

利用 tauri-codegen 包为上下文、处理程序和命令创建宏。

¥Creates macros for the context, handler, and commands by leveraging the tauri-codegen crate.

tauri-utils

在 GitHub 上查看

¥View on GitHub

在许多地方重复使用的通用代码,并提供有用的实用程序,如解析配置文件、检测平台三元组、注入 CSP 和管理资源。

¥Common code that is reused in many places and offers useful utilities like parsing configuration files, detecting platform triples, injecting the CSP, and managing assets.

tauri-build

在 GitHub 上查看

¥View on GitHub

在构建时应用宏来装配 cargo 所需的一些特殊功能。

¥Applies the macros at build-time to rig some special features needed by cargo.

tauri-codegen

在 GitHub 上查看

¥View on GitHub

嵌入、散列和压缩资源,包括应用图标以及系统托盘。在编译时解析 tauri.conf.json 并生成 Config 结构。

¥Embeds, hashes, and compresses assets, including icons for the app as well as the system tray. Parses tauri.conf.json at compile time and generates the Config struct.

tauri-runtime-wry

在 GitHub 上查看

¥View on GitHub

此包专门为 WRY 开启了直接的系统级交互,例如打印、监视器检测和其他与窗口相关的任务。

¥This crate opens up direct systems-level interactions specifically for WRY, such as printing, monitor detection, and other windowing-related tasks.

Tauri 工具

¥Tauri Tooling

API(JavaScript / TypeScript)

在 GitHub 上查看

¥View on GitHub

一个 typescript 库,可创建 cjsesm JavaScript 端点,供你导入到前端框架中,以便 Webview 可以调用和监听后端活动。还以纯 typescript 形式提供,因为对于某些框架来说,这是更理想的。它使用 webview 向其主机传递消息。

¥A typescript library that creates cjs and esm JavaScript endpoints for you to import into your frontend framework so that the Webview can call and listen to backend activity. Also ships in pure typescript, because for some frameworks this is more optimal. It uses the message passing of webviews to their hosts.

打包器 (Rust / Shell)

¥Bundler (Rust / Shell)

在 GitHub 上查看

¥View on GitHub

为其检测到或被告知的平台构建 Tauri 应用的库。目前支持 macOS、Windows 和 Linux - 但在不久的将来也会支持移动平台。可在 Tauri 项目之外使用。

¥A library that builds a Tauri app for the platform it detects or is told. Currently supports macOS, Windows and Linux - but in the near future will support mobile platforms as well. May be used outside of Tauri projects.

cli.rs (Rust)

在 GitHub 上查看

¥View on GitHub

此 Rust 可执行文件提供了 CLI 所需的所有必需活动的完整接口。它可以运行在 macOS、Windows 和 Linux 上。

¥This Rust executable provides the full interface to all of the required activities for which the CLI is required. It runs on macOS, Windows, and Linux.

cli.js (JavaScript)

在 GitHub 上查看

¥View on GitHub

使用 napi-rs 封装 cli.rs 以为每个平台生成 npm 包。

¥Wrapper around cli.rs using napi-rs to produce npm packages for each platform.

create-tauri-app (JavaScript)

在 GitHub 上查看

¥View on GitHub

一个工具包,使工程团队能够使用他们选择的前端框架(只要已配置)快速搭建新的 tauri-apps 项目。

¥A toolkit that will enable engineering teams to rapidly scaffold out a new tauri-apps project using the frontend framework of their choice (as long as it has been configured).

上游板条箱

¥Upstream Crates

Tauri-Apps 组织维护来自 Tauri 的两个 “upstream” 包,即用于创建和管理应用窗口的 TAO,以及用于与窗口内的 Webview 交互的 WRY。

¥The Tauri-Apps organization maintains two “upstream” crates from Tauri, namely TAO for creating and managing application windows, and WRY for interfacing with the Webview that lives within the window.

TAO

在 GitHub 上查看

¥View on GitHub

Rust 中的跨平台应用窗口创建库,支持所有主要平台,如 Windows、macOS、Linux、iOS 和 Android。用 Rust 编写,它是 winit 的一个分支,我们根据自己的需要对其进行了扩展 - 如菜单栏和系统托盘。

¥Cross-platform application window creation library in Rust that supports all major platforms like Windows, macOS, Linux, iOS and Android. Written in Rust, it is a fork of winit that we have extended for our own needs - like menu bar and system tray.

WRY

在 GitHub 上查看

¥View on GitHub

WRY 是一个 Rust 中的跨平台 WebView 渲染库,支持所有主流桌面平台,如 Windows、macOS 和 Linux。Tauri 使用 WRY 作为抽象层,负责确定使用哪个 webview(以及如何进行交互)。

¥WRY is a cross-platform WebView rendering library in Rust that supports all major desktop platforms like Windows, macOS, and Linux. Tauri uses WRY as the abstract layer responsible to determine which webview is used (and how interactions are made).

其他工具

¥Additional Tooling

tauri-action

在 GitHub 上查看

¥View on GitHub

为所有平台构建 Tauri 二进制文件的 GitHub 工作流程。即使未设置 Tauri,也可以创建(非常基本的)Tauri 应用。

¥GitHub workflow that builds Tauri binaries for all platforms. Even allows creating a (very basic) Tauri app even if Tauri is not set up.

tauri-vscode

在 GitHub 上查看

¥View on GitHub

该项目通过几个不错的功能增强了 Visual Studio Code 界面。

¥This project enhances the Visual Studio Code interface with several nice-to-have features.

vue-cli-plugin-tauri

在 GitHub 上查看

¥View on GitHub

允许你在 vue-cli 项目中非常快速地安装 Tauri。

¥Allows you to very quickly install Tauri in a vue-cli project.

插件

¥Plugins

Tauri 插件指南

¥Tauri Plugin Guide

一般来说,插件是由第三方编写的(即使可能有官方支持的插件)。插件通常做 3 件事:

¥Generally speaking, plugins are authored by third parties (even though there may be official, supported plugins). A plugin generally does 3 things:

  1. 启用 Rust 代码执行 “something”。

    ¥Enables Rust code to do “something”.

  2. 提供接口粘合剂,使其易于集成到应用中。

    ¥Provides interface glue to make it easy to integrate into an app.

  3. 提供用于与 Rust 代码交互的 JavaScript API。

    ¥Provides a JavaScript API for interfacing with the Rust code.

以下是一些 Tauri 插件的示例:

¥Here are some examples of Tauri Plugins:

许可证

¥License

Tauri 本身是根据 MIT 或 Apache-2.0 许可的。如果你重新打包并修改任何源代码,你有责任验证你是否遵守所有上游许可证。Tauri 按原样提供,没有明确声明适用于任何用途。

¥Tauri itself is licensed under MIT or Apache-2.0. If you repackage it and modify any source code, it is your responsibility to verify that you are complying with all upstream licenses. Tauri is provided AS-IS with no explicit claim for suitability for any purpose.

你可以在此处仔细阅读我们的 软件物料清单

¥Here you may peruse our Software Bill of Materials.


Tauri 中文网 - 粤ICP备13048890号