Skip to content
Tauri 中文网

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

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

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

本指南的内容

¥Content of this guide

  • 在 Tauri 应用中创建多个窗口

    ¥Create multiple windows in a Tauri app

  • 对不同的窗口使用不同的功能

    ¥Use different capabilities for different windows

  • 使用平台特定功能

    ¥Use platform-specific capabilities

先决条件

¥Prerequisites

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

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

指南

¥Guide

  1. Here we create an app with two windows labelled first and second. There are multiple ways to create windows in your Tauri application.

    In the Tauri configuration file, usually named tauri.conf.json:

    Create Windows Programmatically

    In the Rust code to create a Tauri app:

  2. The windows of a Tauri app can use different features or plugins of the Tauri backend. For better security it is recommended to only give the necessary capabilities to each window. We simulate a scenario where the first windows uses filesystem and dialog functionalities and second only needs dialog functionalities.

    It is recommended to separate the capability files per category of actions they enable.

    Give filesystem capabilities to the first window

    We give the first window the capability to have read access to the content of the $HOME directory.

    Give dialog capabilities to the first and second window

    We give to first and second windows the capability to create a “Yes/No” dialog

  3. We now want to customize the capabilities to be active only on certain platforms. We make our filesystem capabilities only active on linux and windows.

结论和资源

¥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 示例 中找到使用窗口功能的示例应用。功能文件中使用的字段在 功能 参考中列出。

¥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号