Skip to content
Tauri 中文网

适用于不同 Windows 和平台的功能

本指南将帮助你自定义 Tauri 应用的功能。

🌐 This guide will help you customize the capabilities of your Tauri app.

🌐 Content of this guide

  • 在 Tauri 应用中创建多个窗口
  • 对不同的窗口使用不同的功能
  • 使用平台特定功能

🌐 Prerequisites

此练习应在完成 Using Plugin Permissions 后阅读。

🌐 This exercise is meant to be read after completing Using Plugin Permissions.

🌐 Guide

  1. 在这里,我们创建了一个带有两个窗口的应用,分别标记为 firstsecond。在你的 Tauri 应用中,有多种方法可以创建窗口。

    在 Tauri 配置文件中,通常命名为 tauri.conf.json

    在用于创建 Tauri 应用的 Rust 代码中:

  2. Tauri 应用的窗口可以使用 Tauri 后端的不同功能或插件。 为了更好的安全性,建议只为每个窗口提供必要的功能。 我们模拟一个场景,其中 first 窗口使用文件系统和对话框功能,而 second 只需要对话框功能。

    建议根据它们所支持的操作类别来分开能力文件。

    我们赋予 first 窗口对 $HOME 目录内容的读取访问权限。

    我们为 firstsecond 窗口提供创建“是/否”对话框的功能

  3. 我们现在希望将功能定制为仅在某些平台上生效。我们让我们的文件系统功能仅在 linuxwindows 上生效。

🌐 Conclusion and Resources

我们已经学习了如何在 Tauri 应用中创建多个窗口并赋予它们特定的功能。此外,这些功能也可以针对某些平台进行设置。

🌐 We have learned how to create multiple windows in a Tauri app and give them specific capabilities. Furthermore these capabilities can also be targeted to certain platforms.

一个使用窗口功能的示例应用可以在 Tauri Github 仓库api 示例 中找到。可以在功能文件中使用的字段列在 Capability 参考中。

🌐 An example application that used window capabilities can be found in the api example of the Tauri Github repository. The fields that can be used in a capability file are listed in the Capability reference.


Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站