Window State
Save window positions and sizes and restore them when the app is reopened.
Supported Platforms
- Windows
- Linux
- macOS
Setup
This plugin requires a Rust version of at least 1.75
Install the window-state plugin to get started.
Use your project’s package manager to add the dependency:
-
Run the following command in the
src-tauri
folder to add the plugin to the project’s dependencies inCargo.toml
: -
Modify
lib.rs
to initialize the plugin: -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
Usage
After adding the all windows will remember their state when the app is being closed and will restore to their previous state on the next launch.
You can also access the window-state plugin in both JavaScript and Rust.
JavaScript
You can use saveWindowState
to manually save the window state:
Similarly you can manually restore a window’s state from disk:
Rust
You can use the save_window_state()
method exposed by the AppHandleExt
trait:
Similarly you can manually restore a window’s state from disk using the restore_state()
method exposed by the WindowExt
trait:
Permissions
By default all potentially dangerous plugin commands and scopes are blocked and cannot be accessed. You must modify the permissions in your capabilities
configuration to enable these.
See the Capabilities Overview for more information and the step by step guide to use plugin permissions.
Default Permission
This permission set configures what kind of operations are available from the window state plugin.
Granted Permissions
All operations are enabled by default.
allow-filename
allow-restore-state
allow-save-window-state
Permission Table
Identifier | Description |
---|---|
|
Enables the filename command without any pre-configured scope. |
|
Denies the filename command without any pre-configured scope. |
|
Enables the restore_state command without any pre-configured scope. |
|
Denies the restore_state command without any pre-configured scope. |
|
Enables the save_window_state command without any pre-configured scope. |
|
Denies the save_window_state command without any pre-configured scope. |
© 2024 Tauri Contributors. CC-BY / MIT