[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
Tauri v2 introduced a Capability-based permission system.
The window permissions included in core:default (core:window:default) are mostly state queries like is-maximized and inner-size. Commands that change the window, such as minimize, maximize, and close, aren't included, so you have to add a permission for each one.
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 (already included incore:default, so you can leave it out).
After adding these permissions and rebuilding, the buttons worked.
Additional Notes
Tauri v2's permission system grants only minimal permissions by default.
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.
To drag the window by a custom title bar, use data-tauri-drag-region or call startDragging(); that also needs core:window:allow-start-dragging.