Skip to main content

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,
"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 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​

NameTypeDescriptionDefined in
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.
window.ts:224
2#### Platform-specific
- macOS: Bounces the dock icon once.
- Windows: Flashes the taskbar button until the application is in focus.
window.ts:230

Classes​

CloseRequestedEvent​

Since: 1.0.2

Constructors​

constructor​

new CloseRequestedEvent(event: Event<null>): CloseRequestedEvent

Parameters

NameType
eventEvent<null>

Defined in: window.ts:1843

Properties​

event​

event: string

Event name

Defined in: window.ts:1836

id​

id: number

Event identifier used to unlisten

Defined in: window.ts:1840

windowLabel​

windowLabel: string

The label of the window that emitted this event.

Defined in: window.ts:1838

Methods​

isPreventDefault​

isPreventDefault(): boolean

Returns: boolean

preventDefault​

preventDefault(): void

Returns: void

LogicalPosition​

A position represented in logical pixels.

Since: 1.0.0

Constructors​

constructor​

new LogicalPosition(x: number, y: number): LogicalPosition

Parameters

NameType
xnumber
ynumber

Defined in: window.ts:162

Properties​

type​

type: string = 'Logical'

Defined in: window.ts:158

x​

x: number

Defined in: window.ts:159

y​

y: number

Defined in: window.ts:160

LogicalSize​

A size represented in logical pixels.

Since: 1.0.0

Constructors​

constructor​

new LogicalSize(width: number, height: number): LogicalSize

Parameters

NameType
widthnumber
heightnumber

Defined in: window.ts:116

Properties​

height​

height: number

Defined in: window.ts:114

type​

type: string = 'Logical'

Defined in: window.ts:112

width​

width: number

Defined in: window.ts:113

PhysicalPosition​

A position represented in physical pixels.

Since: 1.0.0

Constructors​

constructor​

new PhysicalPosition(x: number, y: number): PhysicalPosition

Parameters

NameType
xnumber
ynumber

Defined in: window.ts:178

Properties​

type​

type: string = 'Physical'

Defined in: window.ts:174

x​

x: number

Defined in: window.ts:175

y​

y: number

Defined in: window.ts:176

Methods​

toLogical​

toLogical(scaleFactor: number): 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

NameType
scaleFactornumber

Returns: LogicalPosition

PhysicalSize​

A size represented in physical pixels.

Since: 1.0.0

Constructors​

constructor​

new PhysicalSize(width: number, height: number): PhysicalSize

Parameters

NameType
widthnumber
heightnumber

Defined in: window.ts:132

Properties​

height​

height: number

Defined in: window.ts:130

type​

type: string = 'Physical'

Defined in: window.ts:128

width​

width: number

Defined in: window.ts:129

Methods​

toLogical​

toLogical(scaleFactor: number): 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

NameType
scaleFactornumber

Returns: LogicalSize

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

Hierarchy

Constructors​

constructor​

new WebviewWindow(label: string, options?: WindowOptions): 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

NameTypeDescription
labelstringThe unique webview window label. Must be alphanumeric: a-zA-Z-/:_.
optionsWindowOptions-

Overrides: WindowManager.constructor

Defined in: window.ts:1911

Properties​

label​

label: string

The window label. It is a unique identifier for the window, can be used to reference it later.

Inherited from: WindowManager.label

Defined in: window.ts:313

listeners​

listeners: { [key: string]: EventCallback<any>[]; }

Local event listeners.

Inherited from: WindowManager.listeners

Defined in: window.ts:315

Methods​

_handleTauriEvent​

_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean

Type parameters

  • T

Parameters

NameType
eventstring
handlerEventCallback<T>

Returns: boolean

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.

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.

emit​

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

Emits an event to the backend, tied to the webview window.

Example

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

Parameters

NameTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.

Returns: Promise<void>

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.

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.

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.

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.

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.

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.

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.

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.

listen​

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

Listen to an event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

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.

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.

onCloseRequested​

onCloseRequested(handler: fn): 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

NameType
handler(event: CloseRequestedEvent) => 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.

onFileDropEvent​

onFileDropEvent(handler: EventCallback<FileDropEvent>): 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

NameType
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.

onFocusChanged​

onFocusChanged(handler: EventCallback<boolean>): 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

NameType
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.

onMenuClicked​

onMenuClicked(handler: EventCallback<string>): 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

NameType
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.

onMoved​

onMoved(handler: EventCallback<PhysicalPosition>): 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

NameType
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.

onResized​

onResized(handler: EventCallback<PhysicalSize>): 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

NameType
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.

onScaleChanged​

onScaleChanged(handler: EventCallback<ScaleFactorChanged>): 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

NameType
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.

onThemeChanged​

onThemeChanged(handler: EventCallback<Theme>): 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

NameType
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.

once​

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

Listen to an one-off event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

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.

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.

requestUserAttention​

requestUserAttention(requestType: null | UserAttentionType): 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

NameType
requestTypenull | UserAttentionType

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

setAlwaysOnTop​

setAlwaysOnTop(alwaysOnTop: boolean): 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

NameTypeDescription
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.

setCursorGrab​

setCursorGrab(grab: boolean): 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

NameTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorIcon​

setCursorIcon(icon: CursorIcon): Promise<void>

Modifies the cursor icon of the window.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorIcon('help');

Parameters

NameTypeDescription
iconCursorIconThe new cursor icon.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorPosition​

setCursorPosition(position: PhysicalPosition | LogicalPosition): 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

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new cursor position.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorVisible​

setCursorVisible(visible: boolean): 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

NameTypeDescription
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.

setDecorations​

setDecorations(decorations: boolean): Promise<void>

Whether the window should have borders and bars.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setDecorations(false);

Parameters

NameTypeDescription
decorationsbooleanWhether the window should have borders and bars.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

setFullscreen​

setFullscreen(fullscreen: boolean): Promise<void>

Sets the window fullscreen state.

Example

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

Parameters

NameTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setIcon​

setIcon(icon: string | Uint8Array): 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

NameTypeDescription
iconstring | Uint8ArrayIcon bytes or path to the icon file.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setIgnoreCursorEvents​

setIgnoreCursorEvents(ignore: boolean): Promise<void>

Changes the cursor events behavior.

Example

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

Parameters

NameTypeDescription
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.

setMaxSize​

setMaxSize(size: undefined | null | PhysicalSize | LogicalSize): 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

NameTypeDescription
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.

setMinSize​

setMinSize(size: undefined | null | PhysicalSize | LogicalSize): 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

NameTypeDescription
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.

setPosition​

setPosition(position: PhysicalPosition | LogicalPosition): Promise<void>

Sets the window outer position.

Example

import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setPosition(new LogicalPosition(600, 500));

Parameters

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new position, in logical or physical pixels.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setResizable​

setResizable(resizable: boolean): Promise<void>

Updates the window resizable flag.

Example

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

Parameters

NameType
resizableboolean

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setSize​

setSize(size: PhysicalSize | LogicalSize): 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

NameTypeDescription
sizePhysicalSize | LogicalSizeThe logical or physical inner size.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setSkipTaskbar​

setSkipTaskbar(skip: boolean): 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

NameTypeDescription
skipbooleantrue to hide window icon, false to show it.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setTitle​

setTitle(title: string): Promise<void>

Sets the window title.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setTitle('Tauri');

Parameters

NameTypeDescription
titlestringThe new title

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

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.

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.

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.

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.

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.

getByLabel​

Static getByLabel(label: string): 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

NameTypeDescription
labelstringThe webview window label.

Returns: null | WebviewWindow

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

WebviewWindowHandle​

A webview window handle allows emitting and listening to events from the backend that are tied to the window.

Since: 1.0.0

Hierarchy

Constructors​

constructor​

new WebviewWindowHandle(label: string): WebviewWindowHandle

Parameters

NameType
labelstring

Defined in: window.ts:317

Properties​

label​

label: string

The window label. It is a unique identifier for the window, can be used to reference it later.

Defined in: window.ts:313

listeners​

listeners: { [key: string]: EventCallback<any>[]; }

Local event listeners.

Defined in: window.ts:315

Methods​

_handleTauriEvent​

_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean

Type parameters

  • T

Parameters

NameType
eventstring
handlerEventCallback<T>

Returns: boolean

emit​

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

Emits an event to the backend, tied to the webview window.

Example

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

Parameters

NameTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.

Returns: Promise<void>

listen​

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

Listen to an event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

once​

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

Listen to an one-off event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

WindowManager​

Manage the current window object.

Since: 1.0.0

Hierarchy

Constructors​

constructor​

new WindowManager(label: string): WindowManager

Parameters

NameType
labelstring

Inherited from: WebviewWindowHandle.constructor

Defined in: window.ts:317

Properties​

label​

label: string

The window label. It is a unique identifier for the window, can be used to reference it later.

Inherited from: WebviewWindowHandle.label

Defined in: window.ts:313

listeners​

listeners: { [key: string]: EventCallback<any>[]; }

Local event listeners.

Inherited from: WebviewWindowHandle.listeners

Defined in: window.ts:315

Methods​

_handleTauriEvent​

_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean

Type parameters

  • T

Parameters

NameType
eventstring
handlerEventCallback<T>

Returns: boolean

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.

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.

emit​

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

Emits an event to the backend, tied to the webview window.

Example

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

Parameters

NameTypeDescription
eventstringEvent name. Must include only alphanumeric characters, -, /, : and _.
payload?unknownEvent payload.

Returns: Promise<void>

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.

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.

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.

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.

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.

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.

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.

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.

listen​

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

Listen to an event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

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.

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.

onCloseRequested​

onCloseRequested(handler: fn): 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

NameType
handler(event: CloseRequestedEvent) => 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.

onFileDropEvent​

onFileDropEvent(handler: EventCallback<FileDropEvent>): 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

NameType
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.

onFocusChanged​

onFocusChanged(handler: EventCallback<boolean>): 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

NameType
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.

onMenuClicked​

onMenuClicked(handler: EventCallback<string>): 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

NameType
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.

onMoved​

onMoved(handler: EventCallback<PhysicalPosition>): 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

NameType
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.

onResized​

onResized(handler: EventCallback<PhysicalSize>): 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

NameType
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.

onScaleChanged​

onScaleChanged(handler: EventCallback<ScaleFactorChanged>): 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

NameType
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.

onThemeChanged​

onThemeChanged(handler: EventCallback<Theme>): 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

NameType
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.

once​

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

Listen to an one-off event emitted by the backend that is tied to the webview window.

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

Type parameters

  • T

Parameters

NameTypeDescription
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. Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.

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.

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.

requestUserAttention​

requestUserAttention(requestType: null | UserAttentionType): 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

NameType
requestTypenull | UserAttentionType

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

setAlwaysOnTop​

setAlwaysOnTop(alwaysOnTop: boolean): 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

NameTypeDescription
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.

setCursorGrab​

setCursorGrab(grab: boolean): 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

NameTypeDescription
grabbooleantrue to grab the cursor icon, false to release it.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorIcon​

setCursorIcon(icon: CursorIcon): Promise<void>

Modifies the cursor icon of the window.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setCursorIcon('help');

Parameters

NameTypeDescription
iconCursorIconThe new cursor icon.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorPosition​

setCursorPosition(position: PhysicalPosition | LogicalPosition): 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

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new cursor position.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setCursorVisible​

setCursorVisible(visible: boolean): 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

NameTypeDescription
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.

setDecorations​

setDecorations(decorations: boolean): Promise<void>

Whether the window should have borders and bars.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setDecorations(false);

Parameters

NameTypeDescription
decorationsbooleanWhether the window should have borders and bars.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

setFullscreen​

setFullscreen(fullscreen: boolean): Promise<void>

Sets the window fullscreen state.

Example

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

Parameters

NameTypeDescription
fullscreenbooleanWhether the window should go to fullscreen or not.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setIcon​

setIcon(icon: string | Uint8Array): 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

NameTypeDescription
iconstring | Uint8ArrayIcon bytes or path to the icon file.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setIgnoreCursorEvents​

setIgnoreCursorEvents(ignore: boolean): Promise<void>

Changes the cursor events behavior.

Example

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

Parameters

NameTypeDescription
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.

setMaxSize​

setMaxSize(size: undefined | null | PhysicalSize | LogicalSize): 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

NameTypeDescription
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.

setMinSize​

setMinSize(size: undefined | null | PhysicalSize | LogicalSize): 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

NameTypeDescription
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.

setPosition​

setPosition(position: PhysicalPosition | LogicalPosition): Promise<void>

Sets the window outer position.

Example

import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
await appWindow.setPosition(new LogicalPosition(600, 500));

Parameters

NameTypeDescription
positionPhysicalPosition | LogicalPositionThe new position, in logical or physical pixels.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setResizable​

setResizable(resizable: boolean): Promise<void>

Updates the window resizable flag.

Example

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

Parameters

NameType
resizableboolean

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setSize​

setSize(size: PhysicalSize | LogicalSize): 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

NameTypeDescription
sizePhysicalSize | LogicalSizeThe logical or physical inner size.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setSkipTaskbar​

setSkipTaskbar(skip: boolean): 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

NameTypeDescription
skipbooleantrue to hide window icon, false to show it.

Returns: Promise<void>

A promise indicating the success or failure of the operation.

setTitle​

setTitle(title: string): Promise<void>

Sets the window title.

Example

import { appWindow } from '@tauri-apps/api/window';
await appWindow.setTitle('Tauri');

Parameters

NameTypeDescription
titlestringThe new title

Returns: Promise<void>

A promise indicating the success or failure of the operation.

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.

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.

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.

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.

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.

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.

Interfaces​

Monitor​

Allows you to retrieve information about a given monitor.

Since: 1.0.0

Properties​

name​

name: null | string

Human-readable name of the monitor

Defined in: window.ts:79

position​

position: PhysicalPosition

the Top-left corner position of the monitor relative to the larger full screen area.

Defined in: window.ts:83

scaleFactor​

scaleFactor: number

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

Defined in: window.ts:85

size​

size: PhysicalSize

The monitor's resolution.

Defined in: window.ts:81

ScaleFactorChanged​

The payload for the scaleChange event.

Since: 1.0.2

Properties​

scaleFactor​

scaleFactor: number

The new window scale factor.

Defined in: window.ts:95

size​

size: PhysicalSize

The new window size

Defined in: window.ts:97

WindowOptions​

Configuration for the window to create.

Since: 1.0.0

Properties​

acceptFirstMouse​

Optional acceptFirstMouse: boolean

Whether clicking an inactive window also clicks through to the webview on macOS.

Defined in: window.ts:2051

alwaysOnTop​

Optional alwaysOnTop: boolean

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

Defined in: window.ts:2025

center​

Optional center: boolean

Show window in the center of the screen..

Defined in: window.ts:1987

decorations​

Optional decorations: boolean

Whether the window should have borders and bars or not.

Defined in: window.ts:2023

fileDropEnabled​

Optional fileDropEnabled: boolean

Whether 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.

Defined in: window.ts:2033

focus​

Optional focus: boolean

Whether the window will be initially focused or not.

Defined in: window.ts:2011

fullscreen​

Optional fullscreen: boolean

Whether the window is in fullscreen mode or not.

Defined in: window.ts:2009

height​

Optional height: number

The initial height.

Defined in: window.ts:1995

hiddenTitle​

Optional hiddenTitle: boolean

If true, sets the window title to be hidden on macOS.

Defined in: window.ts:2047

maxHeight​

Optional maxHeight: number

The maximum height. Only applies if maxWidth is also set.

Defined in: window.ts:2003

maxWidth​

Optional maxWidth: number

The maximum width. Only applies if maxHeight is also set.

Defined in: window.ts:2001

maximized​

Optional maximized: boolean

Whether the window should be maximized upon creation or not.

Defined in: window.ts:2019

minHeight​

Optional minHeight: number

The minimum height. Only applies if minWidth is also set.

Defined in: window.ts:1999

minWidth​

Optional minWidth: number

The minimum width. Only applies if minHeight is also set.

Defined in: window.ts:1997

resizable​

Optional resizable: boolean

Whether the window is resizable or not.

Defined in: window.ts:2005

skipTaskbar​

Optional skipTaskbar: boolean

Whether or not the window icon should be added to the taskbar.

Defined in: window.ts:2027

tabbingIdentifier​

Optional tabbingIdentifier: string

Defines 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.

Defined in: window.ts:2058

theme​

Optional theme: Theme

The initial window theme. Defaults to the system theme.

Only implemented on Windows and macOS 10.14+.

Defined in: window.ts:2039

title​

Optional title: string

Window title.

Defined in: window.ts:2007

titleBarStyle​

Optional titleBarStyle: TitleBarStyle

The style of the macOS title bar.

Defined in: window.ts:2043

transparent​

Optional transparent: boolean

Whether 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.

Defined in: window.ts:2017

url​

Optional url: string

Remote 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).

Defined in: window.ts:1985

userAgent​

Optional userAgent: string

The user agent for the webview.

Defined in: window.ts:2062

visible​

Optional visible: boolean

Whether the window should be immediately visible upon creation or not.

Defined in: window.ts:2021

width​

Optional width: number

The initial width.

Defined in: window.ts:1993

x​

Optional x: number

The initial vertical position. Only applies if y is also set.

Defined in: window.ts:1989

y​

Optional y: number

The initial horizontal position. Only applies if x is also set.

Defined in: window.ts:1991

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: window.ts:233

FileDropEvent​

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

The file drop event types.

Defined in: window.ts:101

Theme​

Theme: "light" | "dark"

Defined in: window.ts:69

TitleBarStyle​

TitleBarStyle: "visible" | "transparent" | "overlay"

Defined in: window.ts:70

Variables​

appWindow​

appWindow: WebviewWindow

The WebviewWindow for the current window.

Defined in: window.ts:1953

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[]>

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>

getAll​

getAll(): WebviewWindow[]

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

Since: 1.0.0

Returns: WebviewWindow[]

getCurrent​

getCurrent(): WebviewWindow

Get an instance of WebviewWindow for the current webview window.

Since: 1.0.0

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

Since: 1.0.0

Returns: Promise<Monitor | null>