5.6 KiB
@tauri-apps/api / window
Module: window
Provides APIs to create windows, communicate with other windows and manipulate the current window.
This package is also accessible with window.__TAURI__.window when build.withGlobalTauri in tauri.conf.json is set to true.
The APIs must be added to tauri.allowlist.window in tauri.conf.json:
{
"tauri": {
"allowlist": {
"window": {
"all": true, // enable all window APIs
"create": true, // enable window creation
"center": true,
"requestUserAttention": true,
"setResizable": true,
"setTitle": true,
"maximize": true,
"unmaximize": true,
"minimize": true,
"unminimize": true,
"show": true,
"hide": true,
"close": true,
"setDecorations": true,
"setAlwaysOnTop": true,
"setSize": true,
"setMinSize": true,
"setMaxSize": true,
"setPosition": true,
"setFullscreen": true,
"setFocus": true,
"setIcon": true,
"setSkipTaskbar": true,
"setCursorGrab": true,
"setCursorVisible": true,
"setCursorIcon": true,
"setCursorPosition": true,
"startDragging": true,
"print": true
}
}
}
}
It is recommended to allowlist only the APIs you use for optimal bundle size and security.
Window events
Events can be listened using appWindow.listen:
import { appWindow } from "@tauri-apps/api/window";
appWindow.listen("my-window-event", ({ event, payload }) => { });
Enumerations
Classes
- CloseRequestedEvent
- LogicalPosition
- LogicalSize
- PhysicalPosition
- PhysicalSize
- WebviewWindow
- WebviewWindowHandle
- WindowManager
Interfaces
Type Aliases
CursorIcon
CursorIcon: "default" | "crosshair" | "hand" | "arrow" | "move" | "text" | "wait" | "help" | "progress" | "notAllowed" | "contextMenu" | "cell" | "verticalText" | "alias" | "copy" | "noDrop" | "grab" | "grabbing" | "allScroll" | "zoomIn" | "zoomOut" | "eResize" | "nResize" | "neResize" | "nwResize" | "sResize" | "seResize" | "swResize" | "wResize" | "ewResize" | "nsResize" | "neswResize" | "nwseResize" | "colResize" | "rowResize"
Defined in
FileDropEvent
FileDropEvent: { paths: string[] ; type: "hover" } | { paths: string[] ; type: "drop" } | { type: "cancel" }
The file drop event types.
Defined in
Theme
Theme: "light" | "dark"
Defined in
Variables
appWindow
appWindow: WebviewWindow
The WebviewWindow for the current window.
Defined in
Functions
availableMonitors
availableMonitors(): Promise<Monitor[]>
Returns the list of all the monitors available on the system.
Example
import { availableMonitors } from '@tauri-apps/api/window';
const monitors = availableMonitors();
Returns
Promise<Monitor[]>
currentMonitor
currentMonitor(): Promise<Monitor | null>
Returns the monitor on which the window currently resides.
Returns null if current monitor can't be detected.
Example
import { currentMonitor } from '@tauri-apps/api/window';
const monitor = currentMonitor();
Returns
Promise<Monitor | null>
getAll
getAll(): WebviewWindow[]
Gets an instance of WebviewWindow for all available webview windows.
Returns
The list of WebviewWindow.
getCurrent
getCurrent(): WebviewWindow
Get an instance of WebviewWindow for the current webview window.
Returns
The current WebviewWindow.
primaryMonitor
primaryMonitor(): Promise<Monitor | null>
Returns the primary monitor of the system.
Returns null if it can't identify any monitor as a primary one.
Example
import { primaryMonitor } from '@tauri-apps/api/window';
const monitor = primaryMonitor();
Returns
Promise<Monitor | null>