Skip to main content

Provides APIs to create windows, communicate with other windows and manipulate the current window.

This package is also accessible with window.__TAURI__.window when tauri.conf.json > build > withGlobalTauri is set to true.

The APIs must be allowlisted on tauri.conf.json:

{
  "tauri": {
    "allowlist": {
      "window": {
        "all": true, // enable all window APIs
        "create": true // enable window creation
      }
    }
  }
}

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('tauri://move', ({ event, payload }) => {
  const { x, y } = payload // payload here is a `PhysicalPosition`
})

Window-specific events emitted by the backend:

'tauri://resize'#

Emitted when the size of the window has changed. EventPayload:

type ResizePayload = PhysicalSize

'tauri://move'#

Emitted when the position of the window has changed. EventPayload:

type MovePayload = PhysicalPosition

'tauri://close-requested'#

Emitted when the user requests the window to be closed.

'tauri://destroyed'#

Emitted after the window is closed.

'tauri://focus'#

Emitted when the window gains focus.

'tauri://blur'#

Emitted when the window loses focus.

'tauri://scale-change'#

Emitted when the window's scale factor has changed. The following user actions can cause DPI changes:

  • Changing the display's resolution.
  • Changing the display's scale factor (e.g. in Control Panel on Windows).
  • Moving the window to a display with a different scale factor. Event payload:
interface ScaleFactorChanged {
  scaleFactor: number
  size: PhysicalSize
}

'tauri://menu'#

Emitted when a menu item is clicked. EventPayload:

type MenuClicked = string

Enumerations#

Classes#

Interfaces#

Variables#

appWindow#

Const appWindow: WebviewWindow

The WebviewWindow for the current window.

Defined in#

window.ts:1132

Functions#

availableMonitors#

availableMonitors(): Promise<Monitor[]>

Returns the list of all the monitors available on the system.

Returns#

Promise<Monitor[]>

Defined in#

window.ts:1220


currentMonitor#

currentMonitor(): Promise<Monitor | null>

Returns the monitor on which the window currently resides. Returns null if current monitor can't be detected.

Returns#

Promise<Monitor | null>

Defined in#

window.ts:1187


getAll#

getAll(): WebviewWindow[]

Gets an instance of WebviewWindow for all available webview windows.

Returns#

WebviewWindow[]

The list of WebviewWindow.

Defined in#

window.ts:209


getCurrent#

getCurrent(): WebviewWindow

Get an instance of WebviewWindow for the current webview window.

Returns#

WebviewWindow

The current WebviewWindow.

Defined in#

window.ts:197


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.

Returns#

Promise<Monitor | null>

Defined in#

window.ts:1205