본문으로 건너뛰기

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

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

Classes

CloseRequestedEvent

Since: 1.0.2

Constructors

constructor

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

Parameters

NameType
eventEvent<null>

Defined in: window.ts:1933

Properties

event

event: EventName

Event name

Defined in: window.ts:1926

id

id: number

Event identifier used to unlisten

Defined in: window.ts:1930

windowLabel

windowLabel: string

The label of the window that emitted this event.

Defined in: window.ts:1928

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:163

Properties

type

type: string = 'Logical'

Defined in: window.ts:159

x

x: number

Defined in: window.ts:160

y

y: number

Defined in: window.ts:161

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:117

Properties

height

height: number

Defined in: window.ts:115

type

type: string = 'Logical'

Defined in: window.ts:113

width

width: number

Defined in: window.ts:114

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:179

Properties

type

type: string = 'Physical'

Defined in: window.ts:175

x

x: number

Defined in: window.ts:176

y

y: number

Defined in: window.ts:177

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:133

Properties

height

height: number

Defined in: window.ts:131

type

type: string = 'Physical'

Defined in: window.ts:129

width

width: number

Defined in: window.ts:130

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

  • WindowManager
    • WebviewWindow

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:2001

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:315

listeners

listeners: Record<string, EventCallback<any>[]>

Local event listeners.

Inherited from: WindowManager.listeners

Defined in: window.ts:317

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.

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.

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>

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: EventName, 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
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. 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 | 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.

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.

setContentProtected

setContentProtected(protected_: boolean): 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

NameType
protected_boolean

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.

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>

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.

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:80

position

position: PhysicalPosition

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

Defined in: window.ts:84

scaleFactor

scaleFactor: number

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

Defined in: window.ts:86

size

size: PhysicalSize

The monitor's resolution.

Defined in: window.ts:82

ScaleFactorChanged

The payload for the scaleChange event.

Since: 1.0.2

Properties

scaleFactor

scaleFactor: number

The new window scale factor.

Defined in: window.ts:96

size

size: PhysicalSize

The new window size

Defined in: window.ts:98

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:2143

alwaysOnTop

Optional alwaysOnTop: boolean

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

Defined in: window.ts:2115

center

Optional center: boolean

Show window in the center of the screen..

Defined in: window.ts:2077

contentProtected

Optional contentProtected: boolean

Prevents the window contents from being captured by other apps.

Defined in: window.ts:2117

decorations

Optional decorations: boolean

Whether the window should have borders and bars or not.

Defined in: window.ts:2113

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:2125

focus

Optional focus: boolean

Whether the window will be initially focused or not.

Defined in: window.ts:2101

fullscreen

Optional fullscreen: boolean

Whether the window is in fullscreen mode or not.

Defined in: window.ts:2099

height

Optional height: number

The initial height.

Defined in: window.ts:2085

hiddenTitle

Optional hiddenTitle: boolean

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

Defined in: window.ts:2139

maxHeight

Optional maxHeight: number

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

Defined in: window.ts:2093

maxWidth

Optional maxWidth: number

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

Defined in: window.ts:2091

maximized

Optional maximized: boolean

Whether the window should be maximized upon creation or not.

Defined in: window.ts:2109

minHeight

Optional minHeight: number

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

Defined in: window.ts:2089

minWidth

Optional minWidth: number

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

Defined in: window.ts:2087

resizable

Optional resizable: boolean

Whether the window is resizable or not.

Defined in: window.ts:2095

skipTaskbar

Optional skipTaskbar: boolean

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

Defined in: window.ts:2119

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:2150

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:2131

title

Optional title: string

Window title.

Defined in: window.ts:2097

titleBarStyle

Optional titleBarStyle: TitleBarStyle

The style of the macOS title bar.

Defined in: window.ts:2135

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:2107

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:2075

userAgent

Optional userAgent: string

The user agent for the webview.

Defined in: window.ts:2154

visible

Optional visible: boolean

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

Defined in: window.ts:2111

width

Optional width: number

The initial width.

Defined in: window.ts:2083

x

Optional x: number

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

Defined in: window.ts:2079

y

Optional y: number

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

Defined in: window.ts:2081

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:234

FileDropEvent

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

The file drop event types.

Defined in: window.ts:102

Theme

Theme: "light" | "dark"

Defined in: window.ts:70

TitleBarStyle

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

Defined in: window.ts:71

Variables

appWindow

appWindow: WebviewWindow

The WebviewWindow for the current window.

Defined in: window.ts:2043

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>