Positioner(ウィンドウ配置)
Plugin 説明内容の英語表記部分について Plugin の各章は、原文データからページ内容の一部が自動生成されているため、英語表記のままの部分があります。
ウィンドウをよく知られた場所に配置します。
このプラグインは、electron-positioner を Tauri に移植したものです。
This plugin requires a Rust version of at least 1.77.2
| Platform | Level | Notes |
|---|---|---|
| windows | ||
| linux | ||
| macos | ||
| android | | |
| ios | |
はじめに、「positioner」プラグインをインストールしてください。
自分のプロジェクトのパッケージ・マネージャーを使用して依存関係を追加します:
npm run tauri add positioneryarn run tauri add positionerpnpm tauri add positionerdeno task tauri add positionerbun tauri add positionercargo tauri add positioner-
src-tauriフォルダで次のコマンドを実行して、このプラグインをCargo.toml内のプロジェクトの依存関係に追加します:cargo add tauri-plugin-positioner --target 'cfg(any(target_os = "macos", windows, target_os = "linux"))' -
追加したプラグインを初期化するために
lib.rsを修正します:src-tauri/src/lib.rs #[cfg_attr(mobile, tauri::mobile_entry_point)]pub fn run() {tauri::Builder::default().setup(|app| {#[cfg(desktop)]app.handle().plugin(tauri_plugin_positioner::init());Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");} -
お好みの JavaScript パッケージ・マネージャーを使用して、「JavaScript Guest」バインディングをインストールします:
npm install @tauri-apps/plugin-positioneryarn add @tauri-apps/plugin-positionerpnpm add @tauri-apps/plugin-positionerdeno add npm:@tauri-apps/plugin-positionerbun add @tauri-apps/plugin-positioner
「トレイの相対配置」を機能させるには追加の設定が必要です。
-
Cargo.tomlファイルにtray-icon機能を追加します:src-tauri/Cargo.toml [dependencies]tauri-plugin-positioner = { version = "2.0.0", features = ["tray-icon"] } -
「positioner」プラグインに
on_tray_eventを設定します:src-tauri/src/lib.rs pub fn run() {tauri::Builder::default()// これは「トレイ相対配置」を機能させるために必要です.setup(|app| {#[cfg(desktop)]{app.handle().plugin(tauri_plugin_positioner::init());tauri::tray::TrayIconBuilder::new().on_tray_icon_event(|tray_handle, event| {tauri_plugin_positioner::on_tray_event(tray_handle.app_handle(), &event);}).build(app)?;}Ok(())}).run(tauri::generate_context!()).expect("error while running tauri application");}
このプラグインの API は、「JavaScript Guest」バインディングを通じて利用できます:
import { moveWindow, Position } from '@tauri-apps/plugin-positioner';// `"withGlobalTauri": true` を使用する場合は、// const { moveWindow, Position } = window.__TAURI__.positioner; を使用できます
moveWindow(Position.TopRight);Rust を通して Window 特性拡張(trait extention)を直接インポートして使用することができます:
use tauri_plugin_positioner::{WindowExt, Position};
let mut win = app.get_webview_window("main").unwrap();let _ = win.as_ref().window().move_window(Position::TopRight);デフォルトでは、潜在的に危険なプラグイン・コマンドとそのスコープ(有効範囲)はすべてブロックされており、アクセスできません。これらを有効にするには、capabilities 設定でアクセス権限を変更する必要があります。
詳細については「セキュリティ・レベル Capabilities」の章を参照してください。また、プラグインのアクセス権限を設定するには「プライグン・アクセス権の使用」の章のステップ・バイ・ステップ・ガイドを参照してください。
{ "permissions": [ ..., "positioner:default", ]}Default Permission
Allows the moveWindow and handleIconState APIs
This default permission set includes the following:
allow-move-windowallow-move-window-constrainedallow-set-tray-icon-state
Permission Table
| Identifier | Description |
|---|---|
|
|
Enables the move_window command without any pre-configured scope. |
|
|
Denies the move_window command without any pre-configured scope. |
|
|
Enables the move_window_constrained command without any pre-configured scope. |
|
|
Denies the move_window_constrained command without any pre-configured scope. |
|
|
Enables the set_tray_icon_state command without any pre-configured scope. |
|
|
Denies the set_tray_icon_state command without any pre-configured scope. |
【※ この日本語版は、「Feb 22, 2025 英語版」に基づいています】
© 2025 Tauri Contributors. CC-BY / MIT