# How to Handle Window Management (Minimize, Maximize, Close) in Tauri

> Learn to handle window management in Tauri apps. Control minimize, maximize, and close actions using JavaScript and Rust APIs for native OS integration. Get started today.

- Repository: [Tauri/tauri](https://github.com/tauri-apps/tauri)
- Tags: how-to-guide
- Published: 2026-02-26

---

**Tauri provides a built-in window plugin that exposes native window operations through JavaScript commands and Rust APIs, delegating platform-specific handling to OS-native dispatchers.**

The `tauri-apps/tauri` repository implements window management through a plugin architecture that bridges frontend JavaScript with native OS window managers. This system allows developers to control window states programmatically from both the frontend and backend, handling minimize, maximize, and close operations across desktop platforms.

## Core Window Management Architecture

Tauri’s window management follows a four-step command flow that abstracts platform differences while providing consistent APIs.

### The Command Dispatch Flow

1. **Window Identification** – Obtain a `Window<R>` handle using `WebviewWindowBuilder` during creation or `app.get_webview_window(label)` for existing windows (as seen in [[`examples/api/src-tauri/src/tray.rs`](https://github.com/tauri-apps/tauri/blob/main/examples/api/src-tauri/src/tray.rs)](https://github.com/tauri-apps/tauri/blob/dev/examples/api/src-tauri/src/tray.rs#L73-L77)).

2. **JavaScript Invocation** – The frontend calls `window.tauri.invoke('plugin:window|minimize', { label })`, which routes through the window plugin registered in [[`crates/tauri/src/window/plugin.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/plugin.rs)](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/plugin.rs#L39-L46).

3. **Rust Method Execution** – The plugin resolves the target window via `get_window` and calls the corresponding method (`minimize()`, `maximize()`, `close()`) on the `Window<R>` struct defined in [[`crates/tauri/src/window/mod.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/mod.rs)](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1759-L1762).

4. **Platform Delegation** – The dispatcher forwards calls to OS-specific backends (Win32, Cocoa, GTK), returning `Result<()>` to JavaScript as a Promise.

### Label Resolution Logic

The `get_window` helper in [`plugin.rs`](https://github.com/tauri-apps/tauri/blob/main/plugin.rs) determines which window receives the command:

```rust
fn get_window<R: Runtime>(window: Window<R>, label: Option<String>) -> crate::Result<Window<R>> {
    match label {
        Some(l) if !l.is_empty() => window.manager().get_window(&l)
                                        .ok_or(crate::Error::WindowNotFound),
        _ => Ok(window),
    }
}

```

If the `label` parameter is omitted or empty, the command targets the window that invoked it.

## Implementing Window Controls in Rust

The Rust API provides direct methods on the `Window` struct for state management. All methods return `crate::Result<()>` and propagate errors (such as missing windows or unsupported platforms) to the caller.

### Minimize and Unminimize

To minimize a window and later restore it:

```rust
// Minimize the window to the taskbar/dock
if let Some(win) = app.get_webview_window("main") {
    win.minimize()?;    // Calls dispatcher.minimize()
    
    // Later: restore from minimized state
    win.unminimize()?;  // Calls dispatcher.unminimize()
}

```

Source implementations: [`minimize`](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1759-L1762) and [`unminimize`](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1665-L1668) in [`crates/tauri/src/window/mod.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/mod.rs).

### Maximize and Unmaximize

Toggle between maximized and windowed states:

```rust
if let Some(win) = app.get_webview_window("main") {
    // Expand to fill screen
    win.maximize()?;    // Dispatcher: maximize()
    
    // Restore previous dimensions
    win.unmaximize()?;  // Dispatcher: unmaximize()
}

```

Source implementations: [`maximize`](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1750-L1752) and [`unmaximize`](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1753-L1755).

### Closing Windows

Gracefully close a window, which first emits `RunEvent::CloseRequested`:

```rust
if let Some(win) = app.get_webview_window("main") {
    win.close()?;       // Dispatcher: close()
}

```

Source: [`close`](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/mod.rs#L1780-L1782).

## JavaScript API Integration

The frontend accesses these capabilities through Tauri’s command system using the `plugin:window` namespace.

### Basic Window Operations

```javascript
import { invoke } from '@tauri-apps/api/core';

// Minimize current window
await invoke('plugin:window|minimize');

// Maximize specific window by label
await invoke('plugin:window|maximize', { label: 'main' });

// Close the window
await invoke('plugin:window|close');

```

These commands map directly to the setter macros defined in [[`crates/tauri/src/window/plugin.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/plugin.rs)](https://github.com/tauri-apps/tauri/blob/dev/crates/tauri/src/window/plugin.rs#L14-L15), which register the JavaScript-accessible endpoints.

## Real-World Implementation: Tray Integration

The official API example demonstrates practical window management from system tray interactions. When handling tray clicks, the application restores minimized windows before focusing them:

```rust
// Inside tray click handler (examples/api/src-tauri/src/tray.rs)
if let Some(window) = app.get_webview_window("main") {
    let _ = window.unminimize();   // Restore if minimized
    let _ = window.show();         // Ensure visibility
    let _ = window.set_focus();    // Bring to foreground
}

```

This pattern ensures the window is interactable regardless of its previous state.

## Summary

- **Window Plugin Architecture** – Tauri exposes native operations via `plugin:window` commands defined in [`crates/tauri/src/window/plugin.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/plugin.rs), bridging JavaScript and Rust.
- **Label-Based Targeting** – Commands accept an optional `label` parameter; omitting it targets the invoking window through the `get_window` helper.
- **Cross-Platform Dispatch** – Methods in [`crates/tauri/src/window/mod.rs`](https://github.com/tauri-apps/tauri/blob/main/crates/tauri/src/window/mod.rs) delegate to OS-specific backends, returning `Result<()>` for error handling.
- **Tray Integration** – Real-world usage often combines `unminimize()`, `show()`, and `set_focus()` to handle window restoration from system tray events.

## Frequently Asked Questions

### How do I target a specific window instead of the current one?

Pass the window `label` as a parameter in your JavaScript invocation: `await invoke('plugin:window|minimize', { label: 'secondary' })`. In Rust, use `app.get_webview_window("secondary")` to obtain the handle. If the label is omitted or empty, the command acts on the window that invoked it.

### Why does my window close immediately without triggering CloseRequested?

Direct calls to `window.close()` emit `RunEvent::CloseRequested` before closing, but if your event loop doesn't handle this event or if the window is force-closed at the OS level, the event may not fire. Ensure your Tauri application implements a `RunEvent` handler in the main loop to intercept close requests.

### Are these window methods supported on mobile platforms?

No. The window management plugin is designed for desktop environments (Windows, macOS, Linux). Calls to minimize, maximize, or close windows will return errors or be no-ops on mobile platforms, as the underlying window dispatchers are not implemented for iOS or Android.

### What is the difference between unminimize and show?

`unminimize()` restores a window from the minimized state (taskbar/dock) to its previous windowed state, while `show()` makes a hidden window visible. In tray applications, you typically call both: `unminimize()` to restore from the taskbar, then `show()` to ensure visibility, followed by `set_focus()` to activate the window.