[Tauri] Configuring Permissions for Custom Title Bars in Tauri v2
How to Set Window Permissions in Tauri v2
The Problem
While building a terminal app with Tauri, I tried to implement a Custom Title Bar by setting "decorations": false in tauri.conf.json.
{
"title": "penterm-rust",
"width": 800,
"height": 600,
"decorations": false,
"resizable": true,
"maximizable": true,
"minimizable": true
}
I implemented the minimize, maximize, and close buttons using Tauri's Window API in the frontend, but clicking them did absolutely nothing.
import { getCurrentWindow } from '@tauri-apps/api/window';
const appWindow = getCurrentWindow();
await appWindow.minimize(); // Doesn't work
await appWindow.toggleMaximize(); // Doesn't work
await appWindow.close(); // Doesn't work
The Cause
Starting with Tauri v2, a Capability-based permission system was introduced to enhance security.
By default, the core:default permission is not enough to use window control APIs. You must explicitly grant permissions for each specific function.
The Solution
Add the necessary permissions to your src-tauri/capabilities/default.json file.
{
"$schema": "../gen/schemas/desktop-schema.json",
"identifier": "default",
"description": "Capability for the main window",
"windows": ["main"],
"permissions": [
"core:default",
"core:window:allow-minimize",
"core:window:allow-toggle-maximize",
"core:window:allow-close",
"core:window:allow-is-maximized",
"opener:default"
]
}
Key Permission Descriptions
core:window:allow-minimize: Allows minimizing the window.core:window:allow-toggle-maximize: Allows toggling between maximized and restored states.core:window:allow-close: Allows closing the window.core:window:allow-is-maximized: Allows checking the current maximization state.
After adding these permissions and rebuilding the project, the buttons will function correctly.
Additional Notes
Tauri v2's permission system follows the principle of least privilege for security purposes.
Before using any API, it is recommended to check the schema files in the src-tauri/gen/schemas/ directory or consult the official documentation to find and add the required permissions.
When implementing a Custom Title Bar, make sure to include all window-related permissions beforehand.