Capabilities for Different Windows and Platforms
This guide will help you customize the capabilities of your Tauri app.
Content of this guide
- Create multiple windows in a Tauri app
- Use different capabilities for different windows
- Use platform-specific capabilities
Prerequisites
This exercise is meant to be read after completing Using Plugin Permissions
.
Guide
-
Here we create an app with two windows labelled
first
andsecond
. There are multiple ways to create windows in your Tauri application.In the Tauri configuration file, usually named
tauri.conf.json
:Create Windows Programatically
In the Rust code to create a Tauri app:
-
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 andsecond
only needs dialog functionalities.It is recommended to separate the capability files per category of actions they enable.
JSON files in the
src-tauri/capabilities
will be taken into account for the capability system. Here we separate capabilities related to the filesystem and dialog window intofilesystem.json
anddialog.json
.filetree of the Tauri project:
Give filesystem capabilities to the
first
windowWe give the
first
window the capability to have read access to the content of the$HOME
directory.Use the
windows
field in a capability file with one or multiple window labels.Give dialog capabilities to the
first
andsecond
windowWe give to
first
andsecond
windows the capability to create a “Yes/No” dialogUse the
windows
field in a capability file with one or multiple window labels. -
We now want to customize the capabilities to be active only on certain platforms. We make our filesystem capabilities only active on
linux
andwindows
.Use the
platforms
field in a capability file to make it platform-specific.The currently available platforms are
linux
,windows
,macos
,android
, andios
.
Conclusion and Resources
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.
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.
© 2024 Tauri Contributors. CC-BY / MIT