Skip to content
Tauri
Releases

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,
"setMaximizable": true,
"setMinimizable": true,
"setClosable": true,
"setTitle": true,
"maximize": true,
"unmaximize": true,
"minimize": true,
"unminimize": true,
"show": true,
"hide": true,
"close": true,
"setDecorations": true,
"setAlwaysOnTop": true,
"setContentProtected": 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,
"setIgnoreCursorEvents": 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 to using appWindow.listen:

import { appWindow } from '@tauri-apps/api/window';
appWindow.listen('my-window-event', ({ event, payload }) => {});

Enumerations

UserAttentionType

Attention type to request on a window.

Since

1.0.0

Enumeration Members

Critical
Critical: 1;

Platform-specific

  • macOS: Bounces the dock icon until the application is in focus.
  • Windows: Flashes both the window and the taskbar button until the application is in focus.

Source: window.ts:228


Informational
Informational: 2;

Platform-specific

  • macOS: Bounces the dock icon once.
  • Windows: Flashes the taskbar button until the application is in focus.

Source: window.ts:234

Classes

CloseRequestedEvent

Since

1.0.2

Constructors

constructor()
new CloseRequestedEvent(event): CloseRequestedEvent
Parameters
ParameterType
eventEvent< null >
Returns

CloseRequestedEvent

Source: window.ts:2179

Properties

PropertyTypeDescription
private _preventDefaultboolean-
eventEventNameEvent name
idnumberEvent identifier used to unlisten
windowLabelstringThe label of the window that emitted this event.

Methods

isPreventDefault()
isPreventDefault(): boolean
Returns

boolean

Source: window.ts:2189


preventDefault()
preventDefault(): void
Returns

void

Source: window.ts:2185


LogicalPosition

A position represented in logical pixels.

Since

1.0.0

Constructors

constructor()
new LogicalPosition(x, y): LogicalPosition
Parameters
ParameterType
xnumber
ynumber
Returns

LogicalPosition

Source: window.ts:166

Properties

PropertyType
typestring
xnumber
ynumber

LogicalSize

A size represented in logical pixels.

Since

1.0.0

Constructors

constructor()
new LogicalSize(width, height): LogicalSize
Parameters
ParameterType
widthnumber
heightnumber
Returns

LogicalSize

Source: window.ts:120

Properties

PropertyType
heightnumber
typestring
widthnumber

PhysicalPosition

A position represented in physical pixels.

Since

1.0.0

Constructors

constructor()
new PhysicalPosition(x, y): PhysicalPosition
Parameters
ParameterType
xnumber
ynumber
Returns

PhysicalPosition

Source: window.ts:182

Properties

PropertyType
typestring
xnumber
ynumber

Methods

toLogical()
toLogical(scaleFactor): LogicalPosition

Converts the physical position to a logical one.

Example
import { appWindow } from '@tauri-apps/api/window';
const factor = await appWindow.scaleFactor();
const position = await appWindow.innerPosition();
const logical = position.toLogical(factor);
Parameters
ParameterType
scaleFactornumber
Returns

LogicalPosition

Source: window.ts:197


PhysicalSize

A size represented in physical pixels.

Since

1.0.0

Constructors

constructor()
new PhysicalSize(width, height): PhysicalSize
Parameters
ParameterType
widthnumber
heightnumber
Returns

PhysicalSize

Source: window.ts:136

Properties

PropertyType
heightnumber
typestring
widthnumber

Methods

toLogical()
toLogical(scaleFactor): LogicalSize

Converts the physical size to a logical one.

Example
import { appWindow } from '@tauri-apps/api/window';
const factor = await appWindow.scaleFactor();
const size = await appWindow.innerSize();
const logical = size.toLogical(factor);
Parameters
ParameterType
scaleFactornumber
Returns

LogicalSize

Source: window.ts:151


WebviewWindow

Create new webview windows and get a handle to existing ones.

Windows are identified by a label a unique identifier that can be used to reference it later. It may only contain alphanumeric characters a-zA-Z plus the following special characters -, /, : and _.

Example

// loading embedded asset:
const webview = new WebviewWindow('theUniqueLabel', {
url: 'path/to/page.html',
});
// alternatively, load a remote URL:
const webview = new WebviewWindow('theUniqueLabel', {
url: 'https://github.com/tauri-apps/tauri',
});
webview.once('tauri://created', function () {
// webview window successfully created
});
webview.once('tauri://error', function (e) {
// an error happened creating the webview window
});
// emit an event to the backend
await webview.emit('some event', 'data');
// listen to an event from the backend
const unlisten = await webview.listen('event name', (e) => {});
unlisten();

Since

1.0.2

Extends

  • WindowManager

Constructors

constructor()
new WebviewWindow(label, options = {}): WebviewWindow

Creates a new WebviewWindow.

Example
import { WebviewWindow } from '@tauri-apps/api/window';
const webview = new WebviewWindow('my-label', {
url: 'https://github.com/tauri-apps/tauri',
});
webview.once('tauri://created', function () {
// webview window successfully created
});
webview.once('tauri://error', function (e) {
// an error happened creating the webview window
});
Parameters
ParameterTypeDescription
labelstringThe unique webview window label. Must be alphanumeric: a-zA-Z-/:_.
optionsWindowOptions-
Returns

WebviewWindow

The WebviewWindow instance to communicate with the webview.

Overrides

WindowManager.constructor

Source: window.ts:2247

Properties

PropertyTypeDescription
labelstringThe window label. It is a unique identifier for the window, can be used to reference it later.
listenersRecord< string, EventCallback< any >[] >Local event listeners.

Methods

center()
center(): Promise< void >

Centers the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.center();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.center

Source: window.ts:926


close()
close(): Promise< void >

Closes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.close();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.close

Source: window.ts:1326


emit()
emit(event, payload?): Promise< void >

Emits an event to the backend and all Tauri windows. The event will have this window’s label as source window label.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.emit('window-loaded', { loggedIn: true, token: 'authToken' });

This function can also be used to communicate between windows:

import { appWindow } from '@tauri-apps/api/window';
await appWindow.listen('sync-data', (event) => {});
// on another window...
import { WebviewWindow } from '@tauri-apps/api/window';
const otherWindow = WebviewWindow.getByLabel('other');
await otherWindow.emit('sync-data');

Global listeners are also triggered:

import { appWindow } from '@tauri-apps/api/window';
import { listen } from '@tauri-apps/api/event';
await listen('ping', (event) => {});
await appWindow.emit('ping');
Parameters
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.
Returns

Promise< void >

Inherited from

WindowManager.emit

Source: window.ts:430


hide()
hide(): Promise< void >

Sets the window visibility to false.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.hide();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.hide

Source: window.ts:1301


innerPosition()
innerPosition(): Promise< PhysicalPosition >

The position of the top-left hand corner of the window’s client area relative to the top-left hand corner of the desktop.

Example
import { appWindow } from '@tauri-apps/api/window';
const position = await appWindow.innerPosition();
Returns

Promise< PhysicalPosition >

The window’s inner position.

Inherited from

WindowManager.innerPosition

Source: window.ts:500


innerSize()
innerSize(): Promise< PhysicalSize >

The physical size of the window’s client area. The client area is the content of the window, excluding the title bar and borders.

Example
import { appWindow } from '@tauri-apps/api/window';
const size = await appWindow.innerSize();
Returns

Promise< PhysicalSize >

The window’s inner size.

Inherited from

WindowManager.innerSize

Source: window.ts:551


isClosable()
isClosable(): Promise< boolean >

Gets the window’s native close button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
const closable = await appWindow.isClosable();
Returns

Promise< boolean >

Whether the window’s native close button is enabled or not.

Inherited from

WindowManager.isClosable

Source: window.ts:819


isDecorated()
isDecorated(): Promise< boolean >

Gets the window’s current decorated state.

Example
import { appWindow } from '@tauri-apps/api/window';
const decorated = await appWindow.isDecorated();
Returns

Promise< boolean >

Whether the window is decorated or not.

Inherited from

WindowManager.isDecorated

Source: window.ts:704


isFocused()
isFocused(): Promise< boolean >

Gets the window’s current focus state.

Example
import { appWindow } from '@tauri-apps/api/window';
const focused = await appWindow.isFocused();
Since

1.4

Returns

Promise< boolean >

Whether the window is focused or not.

Inherited from

WindowManager.isFocused

Source: window.ts:679


isFullscreen()
isFullscreen(): Promise< boolean >

Gets the window’s current fullscreen state.

Example
import { appWindow } from '@tauri-apps/api/window';
const fullscreen = await appWindow.isFullscreen();
Returns

Promise< boolean >

Whether the window is in fullscreen mode or not.

Inherited from

WindowManager.isFullscreen

Source: window.ts:602


isMaximizable()
isMaximizable(): Promise< boolean >

Gets the window’s native maximize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
const maximizable = await appWindow.isMaximizable();
Returns

Promise< boolean >

Whether the window’s native maximize button is enabled or not.

Inherited from

WindowManager.isMaximizable

Source: window.ts:759


isMaximized()
isMaximized(): Promise< boolean >

Gets the window’s current maximized state.

Example
import { appWindow } from '@tauri-apps/api/window';
const maximized = await appWindow.isMaximized();
Returns

Promise< boolean >

Whether the window is maximized or not.

Inherited from

WindowManager.isMaximized

Source: window.ts:652


isMinimizable()
isMinimizable(): Promise< boolean >

Gets the window’s native minimize button state.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
const minimizable = await appWindow.isMinimizable();
Returns

Promise< boolean >

Whether the window’s native minimize button is enabled or not.

Inherited from

WindowManager.isMinimizable

Source: window.ts:789


isMinimized()
isMinimized(): Promise< boolean >

Gets the window’s current minimized state.

Example
import { appWindow } from '@tauri-apps/api/window';
const minimized = await appWindow.isMinimized();
Since

1.3.0

Returns

Promise< boolean >

Inherited from

WindowManager.isMinimized

Source: window.ts:627


isResizable()
isResizable(): Promise< boolean >

Gets the window’s current resizable state.

Example
import { appWindow } from '@tauri-apps/api/window';
const resizable = await appWindow.isResizable();
Returns

Promise< boolean >

Whether the window is resizable or not.

Inherited from

WindowManager.isResizable

Source: window.ts:729


isVisible()
isVisible(): Promise< boolean >

Gets the window’s current visible state.

Example
import { appWindow } from '@tauri-apps/api/window';
const visible = await appWindow.isVisible();
Returns

Promise< boolean >

Whether the window is visible or not.

Inherited from

WindowManager.isVisible

Source: window.ts:844


listen()
listen<T>(event, handler): Promise< UnlistenFn >

Listen to an event emitted by the backend or webview. The event must either be a global event or an event targetting this window.

See emit for more information.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.listen<string>('state-changed', (event) => {
console.log(`Got error: ${payload}`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Type parameters
Parameter
T
Parameters
ParameterTypeDescription
eventEventNameEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback< T >Event handler.
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event.

Inherited from

WindowManager.listen

Source: window.ts:351


maximize()
maximize(): Promise< void >

Maximizes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.maximize();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.maximize

Source: window.ts:1151


minimize()
minimize(): Promise< void >

Minimizes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.minimize();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.minimize

Source: window.ts:1226


onCloseRequested()
onCloseRequested(handler): Promise< UnlistenFn >

Listen to window close requested. Emitted when the user requests to closes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
import { confirm } from '@tauri-apps/api/dialog';
const unlisten = await appWindow.onCloseRequested(async (event) => {
const confirmed = await confirm('Are you sure?');
if (!confirmed) {
// user did not confirm closing the window; let's prevent it
event.preventDefault();
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handler(event) => void | Promise< void >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onCloseRequested

Source: window.ts:1978


onFileDropEvent()
onFileDropEvent(handler): Promise< UnlistenFn >

Listen to a file drop event. The listener is triggered when the user hovers the selected files on the window, drops the files or cancels the operation.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onFileDropEvent((event) => {
if (event.payload.type === 'hover') {
console.log('User hovering', event.payload.paths);
} else if (event.payload.type === 'drop') {
console.log('User dropped', event.payload.paths);
} else {
console.log('File drop cancelled');
}
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< FileDropEvent >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onFileDropEvent

Source: window.ts:2112


onFocusChanged()
onFocusChanged(handler): Promise< UnlistenFn >

Listen to window focus change.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onFocusChanged(({ payload: focused }) => {
console.log('Focus changed, window is focused? ' + focused);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< boolean >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onFocusChanged

Source: window.ts:2011


onMenuClicked()
onMenuClicked(handler): Promise< UnlistenFn >

Listen to the window menu item click. The payload is the item id.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onMenuClicked(({ payload: menuId }) => {
console.log('Menu clicked: ' + menuId);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< string >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onMenuClicked

Source: window.ts:2081


onMoved()
onMoved(handler): Promise< UnlistenFn >

Listen to window move.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onMoved(({ payload: position }) => {
console.log('Window moved', position);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< PhysicalPosition >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onMoved

Source: window.ts:1946


onResized()
onResized(handler): Promise< UnlistenFn >

Listen to window resize.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onResized(({ payload: size }) => {
console.log('Window resized', size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< PhysicalSize >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onResized

Source: window.ts:1920


onScaleChanged()
onScaleChanged(handler): Promise< UnlistenFn >

Listen to window 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.
Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onScaleChanged(({ payload }) => {
console.log('Scale changed', payload.scaleFactor, payload.size);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< ScaleFactorChanged >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onScaleChanged

Source: window.ts:2053


onThemeChanged()
onThemeChanged(handler): Promise< UnlistenFn >

Listen to the system theme change.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.onThemeChanged(({ payload: theme }) => {
console.log('New theme: ' + theme);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();
Since

1.0.2

Parameters
ParameterType
handlerEventCallback< Theme >
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Inherited from

WindowManager.onThemeChanged

Source: window.ts:2162


once()
once<T>(event, handler): Promise< UnlistenFn >

Listen to an one-off event. See listen for more information.

Example
import { appWindow } from '@tauri-apps/api/window';
const unlisten = await appWindow.once<null>('initialized', (event) => {
console.log(`Window initialized!`);
});
// you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
unlisten();

Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

Type parameters
Parameter
T
Parameters
ParameterTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
handlerEventCallback< T >Event handler.
Returns

Promise< UnlistenFn >

A promise resolving to a function to unlisten to the event.

Inherited from

WindowManager.once

Source: window.ts:386


outerPosition()
outerPosition(): Promise< PhysicalPosition >

The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.

Example
import { appWindow } from '@tauri-apps/api/window';
const position = await appWindow.outerPosition();
Returns

Promise< PhysicalPosition >

The window’s outer position.

Inherited from

WindowManager.outerPosition

Source: window.ts:525


outerSize()
outerSize(): Promise< PhysicalSize >

The physical size of the entire window. These dimensions include the title bar and borders. If you don’t want that (and you usually don’t), use inner_size instead.

Example
import { appWindow } from '@tauri-apps/api/window';
const size = await appWindow.outerSize();
Returns

Promise< PhysicalSize >

The window’s outer size.

Inherited from

WindowManager.outerSize

Source: window.ts:577


requestUserAttention()
requestUserAttention(requestType): Promise< void >

Requests user attention to the window, this has no effect if the application is already focused. How requesting for user attention manifests is platform dependent, see UserAttentionType for details.

Providing null will unset the request for user attention. Unsetting the request for user attention might not be done automatically by the WM when the window receives input.

Platform-specific

  • macOS: null has no effect.
  • Linux: Urgency levels have the same effect.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.requestUserAttention();
Parameters
ParameterTypeDescription
requestTypenull | UserAttentionType
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.requestUserAttention

Source: window.ts:962


scaleFactor()
scaleFactor(): Promise< number >

The scale factor that can be used to map physical pixels to logical pixels.

Example
import { appWindow } from '@tauri-apps/api/window';
const factor = await appWindow.scaleFactor();
Returns

Promise< number >

The window’s monitor scale factor.

Inherited from

WindowManager.scaleFactor

Source: window.ts:475


setAlwaysOnTop()
setAlwaysOnTop(alwaysOnTop): Promise< void >

Whether the window should always be on top of other windows.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setAlwaysOnTop(true);
Parameters
ParameterTypeDescription
alwaysOnTopbooleanWhether the window should always be on top of other windows or not.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setAlwaysOnTop

Source: window.ts:1379


setClosable()
setClosable(closable): Promise< void >

Sets whether the window’s native close button is enabled or not.

Platform-specific

  • Linux: GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
  • iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setClosable(false);
Parameters
ParameterTypeDescription
closableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setClosable

Source: window.ts:1098


setContentProtected()
setContentProtected(protected_): Promise< void >

Prevents the window contents from being captured by other apps.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setContentProtected(true);
Since

1.2.0

Parameters
ParameterType
protected_boolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setContentProtected

Source: window.ts:1407


setCursorGrab()
setCursorGrab(grab): Promise< void >

Grabs the cursor, preventing it from leaving the window.

There’s no guarantee that the cursor will be hidden. You should hide it by yourself if you want so.

Platform-specific

  • Linux: Unsupported.
  • macOS: This locks the cursor in a fixed location, which looks visually awkward.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorGrab(true);
Parameters
ParameterTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setCursorGrab

Source: window.ts:1727


setCursorIcon()
setCursorIcon(icon): Promise< void >

Modifies the cursor icon of the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorIcon('help');
Parameters
ParameterTypeDescription
iconCursorIconThe new cursor icon.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setCursorIcon

Source: window.ts:1787


setCursorPosition()
setCursorPosition(position): Promise< void >

Changes the position of the cursor in window coordinates.

Example
import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setCursorPosition(new LogicalPosition(600, 300));
Parameters
ParameterTypeDescription
positionPhysicalPosition | LogicalPositionThe new cursor position.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setCursorPosition

Source: window.ts:1814


setCursorVisible()
setCursorVisible(visible): Promise< void >

Modifies the cursor’s visibility.

Platform-specific

  • Windows: The cursor is only hidden within the confines of the window.
  • macOS: The cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorVisible(false);
Parameters
ParameterTypeDescription
visiblebooleanIf false, this will hide the cursor. If true, this will show the cursor.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setCursorVisible

Source: window.ts:1760


setDecorations()
setDecorations(decorations): Promise< void >

Whether the window should have borders and bars.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setDecorations(false);
Parameters
ParameterTypeDescription
decorationsbooleanWhether the window should have borders and bars.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setDecorations

Source: window.ts:1352


setFocus()
setFocus(): Promise< void >

Bring the window to front and focus.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setFocus();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setFocus

Source: window.ts:1625


setFullscreen()
setFullscreen(fullscreen): Promise< void >

Sets the window fullscreen state.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setFullscreen(true);
Parameters
ParameterTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setFullscreen

Source: window.ts:1599


setIcon()
setIcon(icon): Promise< void >

Sets the window icon.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setIcon('/tauri/awesome.png');

Note that you need the icon-ico or icon-png Cargo features to use this API. To enable it, change your Cargo.toml file:

[dependencies]
tauri = { version = "...", features = ["...", "icon-png"] }
Parameters
ParameterTypeDescription
iconstring | Uint8ArrayIcon bytes or path to the icon file.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setIcon

Source: window.ts:1658


setIgnoreCursorEvents()
setIgnoreCursorEvents(ignore): Promise< void >

Changes the cursor events behavior.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setIgnoreCursorEvents(true);
Parameters
ParameterTypeDescription
ignorebooleantrue to ignore the cursor events; false to process them as usual.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setIgnoreCursorEvents

Source: window.ts:1858


setMaxSize()
setMaxSize(size): Promise< void >

Sets the window maximum inner size. If the size argument is undefined, the constraint is unset.

Example
import { appWindow, LogicalSize } from '@tauri-apps/api/window';
await appWindow.setMaxSize(new LogicalSize(600, 500));
Parameters
ParameterTypeDescription
sizeundefined | null | PhysicalSize | LogicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setMaxSize

Source: window.ts:1514


setMaximizable()
setMaximizable(maximizable): Promise< void >

Sets whether the window’s native maximize button is enabled or not. If resizable is set to false, this setting is ignored.

Platform-specific

  • macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
  • Linux / iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setMaximizable(false);
Parameters
ParameterTypeDescription
maximizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setMaximizable

Source: window.ts:1033


setMinSize()
setMinSize(size): Promise< void >

Sets the window minimum inner size. If the size argument is not provided, the constraint is unset.

Example
import { appWindow, PhysicalSize } from '@tauri-apps/api/window';
await appWindow.setMinSize(new PhysicalSize(600, 500));
Parameters
ParameterTypeDescription
sizeundefined | null | PhysicalSize | LogicalSizeThe logical or physical inner size, or null to unset the constraint.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setMinSize

Source: window.ts:1472


setMinimizable()
setMinimizable(minimizable): Promise< void >

Sets whether the window’s native minimize button is enabled or not.

Platform-specific

  • Linux / iOS / Android: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setMinimizable(false);
Parameters
ParameterTypeDescription
minimizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setMinimizable

Source: window.ts:1065


setPosition()
setPosition(position): Promise< void >

Sets the window outer position.

Example
import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setPosition(new LogicalPosition(600, 500));
Parameters
ParameterTypeDescription
positionPhysicalPosition | LogicalPositionThe new position, in logical or physical pixels.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setPosition

Source: window.ts:1556


setResizable()
setResizable(resizable): Promise< void >

Updates the window resizable flag.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setResizable(false);
Parameters
ParameterTypeDescription
resizableboolean
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setResizable

Source: window.ts:999


setSize()
setSize(size): Promise< void >

Resizes the window with a new inner size.

Example
import { appWindow, LogicalSize } from '@tauri-apps/api/window';
await appWindow.setSize(new LogicalSize(600, 500));
Parameters
ParameterTypeDescription
sizePhysicalSize | LogicalSizeThe logical or physical inner size.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setSize

Source: window.ts:1434


setSkipTaskbar()
setSkipTaskbar(skip): Promise< void >

Whether the window icon should be hidden from the taskbar or not.

Platform-specific

  • macOS: Unsupported.
Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setSkipTaskbar(true);
Parameters
ParameterTypeDescription
skipbooleantrue to hide window icon, false to show it.
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setSkipTaskbar

Source: window.ts:1692


setTitle()
setTitle(title): Promise< void >

Sets the window title.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.setTitle('Tauri');
Parameters
ParameterTypeDescription
titlestringThe new title
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.setTitle

Source: window.ts:1125


show()
show(): Promise< void >

Sets the window visibility to true.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.show();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.show

Source: window.ts:1276


startDragging()
startDragging(): Promise< void >

Starts dragging the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.startDragging();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.startDragging

Source: window.ts:1884


theme()
theme(): Promise< null | Theme >

Gets the window’s current theme.

Platform-specific

  • macOS: Theme was introduced on macOS 10.14. Returns light on macOS 10.13 and below.
Example
import { appWindow } from '@tauri-apps/api/window';
const theme = await appWindow.theme();
Returns

Promise< null | Theme >

The window theme.

Inherited from

WindowManager.theme

Source: window.ts:899


title()
title(): Promise< string >

Gets the window’s current title.

Example
import { appWindow } from '@tauri-apps/api/window';
const title = await appWindow.title();
Since

1.3.0

Returns

Promise< string >

Inherited from

WindowManager.title

Source: window.ts:869


toggleMaximize()
toggleMaximize(): Promise< void >

Toggles the window maximized state.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.toggleMaximize();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.toggleMaximize

Source: window.ts:1201


unmaximize()
unmaximize(): Promise< void >

Unmaximizes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.unmaximize();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.unmaximize

Source: window.ts:1176


unminimize()
unminimize(): Promise< void >

Unminimizes the window.

Example
import { appWindow } from '@tauri-apps/api/window';
await appWindow.unminimize();
Returns

Promise< void >

A promise indicating the success or failure of the operation.

Inherited from

WindowManager.unminimize

Source: window.ts:1251


getByLabel()
static getByLabel(label): null | WebviewWindow

Gets the WebviewWindow for the webview associated with the given label.

Example
import { WebviewWindow } from '@tauri-apps/api/window';
const mainWindow = WebviewWindow.getByLabel('main');
Parameters
ParameterTypeDescription
labelstringThe webview window label.
Returns

null | WebviewWindow

The WebviewWindow instance to communicate with the webview or null if the webview doesn’t exist.

Source: window.ts:2279


getFocusedWindow()
static getFocusedWindow(): Promise< null | WebviewWindow >

Gets the focused window.

Example
import { WebviewWindow } from '@tauri-apps/api/window';
const focusedWindow = WebviewWindow.getFocusedWindow();
Since

1.4

Returns

Promise< null | WebviewWindow >

The WebviewWindow instance to communicate with the webview or undefined if there is not any focused window.

Source: window.ts:2299

Interfaces

Monitor

Allows you to retrieve information about a given monitor.

Since

1.0.0

Properties

PropertyTypeDescription
namenull | stringHuman-readable name of the monitor
positionPhysicalPositionthe Top-left corner position of the monitor relative to the larger full screen area.
scaleFactornumberThe scale factor that can be used to map physical pixels to logical pixels.
sizePhysicalSizeThe monitor’s resolution.

ScaleFactorChanged

The payload for the scaleChange event.

Since

1.0.2

Properties

PropertyTypeDescription
scaleFactornumberThe new window scale factor.
sizePhysicalSizeThe new window size

WindowOptions

Configuration for the window to create.

Since

1.0.0

Properties

PropertyTypeDescription
acceptFirstMouse?booleanWhether clicking an inactive window also clicks through to the webview on macOS.
alwaysOnTop?booleanWhether the window should always be on top of other windows or not.
center?booleanShow window in the center of the screen..
closable?booleanWhether the window’s native close button is enabled or not. Defaults to true.
contentProtected?booleanPrevents the window contents from being captured by other apps.
decorations?booleanWhether the window should have borders and bars or not.
fileDropEnabled?booleanWhether the file drop is enabled or not on the webview. By default it is enabled.

Disabling it is required to use drag and drop on the frontend on Windows.
focus?booleanWhether the window will be initially focused or not.
fullscreen?booleanWhether the window is in fullscreen mode or not.
height?numberThe initial height.
hiddenTitle?booleanIf true, sets the window title to be hidden on macOS.
maxHeight?numberThe maximum height. Only applies if maxWidth is also set.
maxWidth?numberThe maximum width. Only applies if maxHeight is also set.
maximizable?booleanWhether the window’s native maximize button is enabled or not. Defaults to true.
maximized?booleanWhether the window should be maximized upon creation or not.
minHeight?numberThe minimum height. Only applies if minWidth is also set.
minWidth?numberThe minimum width. Only applies if minHeight is also set.
minimizable?booleanWhether the window’s native minimize button is enabled or not. Defaults to true.
resizable?booleanWhether the window is resizable or not.
skipTaskbar?booleanWhether or not the window icon should be added to the taskbar.
tabbingIdentifier?stringDefines the window tabbing identifier on macOS.

Windows with the same tabbing identifier will be grouped together.
If the tabbing identifier is not set, automatic tabbing will be disabled.
theme?ThemeThe initial window theme. Defaults to the system theme.

Only implemented on Windows and macOS 10.14+.
title?stringWindow title.
titleBarStyle?TitleBarStyleThe style of the macOS title bar.
transparent?booleanWhether the window is transparent or not.
Note that on macOS this requires the macos-private-api feature flag, enabled under tauri.conf.json > tauri > macOSPrivateApi.
WARNING: Using private APIs on macOS prevents your application from being accepted to the App Store.
url?stringRemote URL or local file path to open.

- URL such as https://github.com/tauri-apps is opened directly on a Tauri window.
- data: URL such as data:text/html,<html>... is only supported with the window-data-url Cargo feature for the tauri dependency.
- local file path or route such as /path/to/page.html or /users is appended to the application URL (the devServer URL on development, or tauri://localhost/ and https://tauri.localhost/ on production).
userAgent?stringThe user agent for the webview.
visible?booleanWhether the window should be immediately visible upon creation or not.
width?numberThe initial width.
x?numberThe initial vertical position. Only applies if y is also set.
y?numberThe initial horizontal position. Only applies if x is also set.

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';

Source: window.ts:237


FileDropEvent

FileDropEvent: {paths: string[]; type: "hover";} | {paths: string[]; type: "drop";} | {type: "cancel";}

The file drop event types.

Source: window.ts:105


Theme

Theme: 'light' | 'dark';

Source: window.ts:73


TitleBarStyle

TitleBarStyle: 'visible' | 'transparent' | 'overlay';

Source: window.ts:74

Variables

appWindow

let appWindow: WebviewWindow;

The WebviewWindow for the current window.

Source: window.ts:2310

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();

Since

1.0.0

Returns

Promise< Monitor[] >

Source: window.ts:2515


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();

Since

1.0.0

Returns

Promise< Monitor | null >

Source: window.ts:2466


getAll()

getAll(): WebviewWindow[]

Gets a list of instances of WebviewWindow for all available webview windows.

Since

1.0.0

Returns

WebviewWindow[]

Source: window.ts:295


getCurrent()

getCurrent(): WebviewWindow

Get an instance of WebviewWindow for the current webview window.

Since

1.0.0

Returns

WebviewWindow

Source: window.ts:283


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();

Since

1.0.0

Returns

Promise< Monitor | null >

Source: window.ts:2491


© 2024 Tauri Contributors. CC-BY / MIT