Positioner
Position your windows at well-known locations.
This plugin is a port of electron-positioner for Tauri.
Supported Platforms
- Windows
- Linux
- macOS
Setup
This plugin requires a Rust version of at least 1.75
Install the positioner plugin to get started.
Use your project’s package manager to add the dependency:
npm run tauri add positioneryarn run tauri add positionerpnpm tauri add positionerbun tauri add positionercargo tauri add positioner-
Install the positioner plugin by adding the following to your
Cargo.tomlfile:src-tauri/Cargo.toml [dependencies]tauri-plugin-positioner = "2.0.0-rc"# alternatively with Git:tauri-plugin-positioner = { git = "https://github.com/tauri-apps/plugins-workspace", branch = "v2" } -
Modify
lib.rsto initialize the plugin:src-tauri/src/lib.rs fn run() {tauri::Builder::default().plugin(tauri_plugin_positioner::init()).run(tauri::generate_context!()).expect("error while running tauri application");} -
Install the JavaScript Guest bindings using your preferred JavaScript package manager:
npm install @tauri-apps/plugin-positioneryarn add @tauri-apps/plugin-positionerpnpm add @tauri-apps/plugin-positionerbun add @tauri-apps/plugin-positioner
Additional setup is required to get tray-relative positions to work.
-
Add
tray-iconfeature to yourCargo.tomlfile:src-tauri/Cargo.toml [dependencies]tauri-plugin-positioner = { version = "2.0.0-rc", features = ["tray-icon"] } -
Setup
on_tray_eventfor positioner plugin:src-tauri/src/lib.rs fn run() {tauri::Builder::default().plugin(tauri_plugin_positioner::init())// This is required to get tray-relative positions to work.setup(|app| {TrayIconBuilder::new().on_tray_icon_event(|app, event| {tauri_plugin_positioner::on_tray_event(app.app_handle(), &event);}).build(app)?;Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");}
Usage
The plugin’s APIs are available through the JavaScript guest bindings:
import { moveWindow, Position } from '@tauri-apps/plugin-positioner';// when using `"withGlobalTauri": true`, you may use// const { moveWindow, Position } = window.__TAURI_PLUGIN_POSITIONER__;
moveWindow(Position.TopRight);You can import and use the Window trait extension directly through Rust:
use tauri_plugin_positioner::{WindowExt, Position};
let mut win = app.get_webview_window("main").unwrap();let _ = win.as_ref().window().move_window(Position::TopRight);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.
{ "permissions": [ ..., "positioner:default", ]}| Permission | Description |
|---|---|
positioner:allow-move-window | Enables the move_window command without any pre-configured scope. |
positioner:deny-move-window | Denies the move_window command without any pre-configured scope. |
positioner:default | Allows the move_window command. |
© 2024 Tauri Contributors. CC-BY / MIT