window
Provides APIs to create windows, communicate with other windows and manipulate the current window.
Window events
Events can be listened to using Window.listen:
import { getCurrentWindow } from "@tauri-apps/api/window";getCurrentWindow().listen("my-window-event", ({ event, payload }) => { });References
DragDropEvent
Re-exports DragDropEvent
LogicalPosition
Re-exports LogicalPosition
LogicalSize
Re-exports LogicalSize
PhysicalPosition
Re-exports PhysicalPosition
PhysicalSize
Re-exports PhysicalSize
Enumerations
Effect
Platform-specific window effects
Since
2.0.0
Enumeration Members
Acrylic
Acrylic: "acrylic";Windows 10/11
Notes
This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2054
AppearanceBased
AppearanceBased: "appearanceBased";A default material appropriate for the view’s effectiveAppearance. macOS 10.14-
Deprecated
since macOS 10.14. You should instead choose an appropriate semantic material.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1954
Blur
Blur: "blur";Windows 7/10/11(22H1) Only
Notes
This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2046
ContentBackground
ContentBackground: "contentBackground";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2026
Dark
Dark: "dark";macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1966
FullScreenUI
FullScreenUI: "fullScreenUI";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2018
HeaderView
HeaderView: "headerView";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2002
HudWindow
HudWindow: "hudWindow";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2014
Light
Light: "light";macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1960
MediumLight
MediumLight: "mediumLight";macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1972
Menu
Menu: "menu";macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1990
Mica
Mica: "mica";Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2038
Popover
Popover: "popover";macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1994
Selection
Selection: "selection";macOS 10.10+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1986
Sheet
Sheet: "sheet";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2006
Sidebar
Sidebar: "sidebar";macOS 10.11+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1998
Tabbed
Tabbed: "tabbed";Tabbed effect that matches the system dark perefence Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2058
TabbedDark
TabbedDark: "tabbedDark";Tabbed effect with dark mode but only if dark mode is enabled on the system Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2062
TabbedLight
TabbedLight: "tabbedLight";Tabbed effect with light mode Windows 11 Only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2066
Titlebar
Titlebar: "titlebar";macOS 10.10+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1982
Tooltip
Tooltip: "tooltip";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2022
UltraDark
UltraDark: "ultraDark";macOS 10.14-
Deprecated
since macOS 10.14. Use a semantic material instead.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1978
UnderPageBackground
UnderPageBackground: "underPageBackground";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2034
UnderWindowBackground
UnderWindowBackground: "underWindowBackground";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2030
WindowBackground
WindowBackground: "windowBackground";macOS 10.14+
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2010
EffectState
Window effect state macOS only
See
https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
Since
2.0.0
Enumeration Members
Active
Active: "active";Make window effect state always active macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2084
FollowsWindowActiveState
FollowsWindowActiveState: "followsWindowActiveState";Make window effect state follow the window’s active state macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2080
Inactive
Inactive: "inactive";Make window effect state always inactive macOS only
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2088
ProgressBarStatus
Enumeration Members
Error
Error: "error";Error state. Treated as Normal on linux
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L183
Indeterminate
Indeterminate: "indeterminate";Indeterminate state. Treated as Normal on Linux and macOS
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L175
None
None: "none";Hide progress bar.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L167
Normal
Normal: "normal";Normal state.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L171
Paused
Paused: "paused";Paused state. Treated as Normal on Linux
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L179
UserAttentionType
Attention type to request on a window.
Since
1.0.0
Enumeration Members
Critical
Critical: 1;Platform-specific
- macOS: Bounces the dock icon until the application is in focus.
- Windows: Flashes both the window and the taskbar button until the application is in focus.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L92
Informational
Informational: 2;Platform-specific
- macOS: Bounces the dock icon once.
- Windows: Flashes the taskbar button until the application is in focus.
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L98
Classes
CloseRequestedEvent
Constructors
new CloseRequestedEvent()
new CloseRequestedEvent(event): CloseRequestedEventParameters
| Parameter | Type |
|---|---|
event | Event<unknown> |
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L108
Properties
| Property | Modifier | Type | Default value | Description |
|---|---|---|---|---|
_preventDefault | private | boolean | false | - |
event | public | EventName | undefined | Event name |
id | public | number | undefined | Event identifier used to unlisten |
Methods
isPreventDefault()
isPreventDefault(): booleanReturns
boolean
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L117
preventDefault()
preventDefault(): voidReturns
void
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L113
Window
Create new window or get a handle to an existing one.
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
import { Window } from "@tauri-apps/api/window"
const appWindow = new Window('theUniqueLabel');
appWindow.once('tauri://created', function () { // window successfully created});appWindow.once('tauri://error', function (e) { // an error happened creating the window});
// emit an event to the backendawait appWindow.emit("some-event", "data");// listen to an event from the backendconst unlisten = await appWindow.listen("event-name", e => {});unlisten();Since
2.0.0
Extended by
Constructors
new Window()
new Window(label, options): WindowCreates a new Window.
Parameters
| Parameter | Type | Description |
|---|---|---|
label | string | The unique window label. Must be alphanumeric: a-zA-Z-/:_. |
options | WindowOptions | - |
Returns
The Window instance to communicate with the window.
Example
import { Window } from '@tauri-apps/api/window';const appWindow = new Window('my-label');appWindow.once('tauri://created', function () { // window successfully created});appWindow.once('tauri://error', function (e) { // an error happened creating the window});Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L289
Properties
| Property | Type | Description |
|---|---|---|
label | string | The window label. It is a unique identifier for the window, can be used to reference it later. |
listeners | Record<string, EventCallback<any>[]> | Local event listeners. |
Methods
center()
center(): Promise<void>Centers the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().center();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L810
clearEffects()
clearEffects(): Promise<void>Clear any applied effects if possible.
Returns
Promise<void>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1161
close()
close(): Promise<void>Closes the window.
Note this emits a closeRequested event so you can intercept it. To force window close, use Window.destroy.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().close();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1082
destroy()
destroy(): Promise<void>Destroys the window. Behaves like Window.close but forces the window close instead of emitting a closeRequested event.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().destroy();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1098
emit()
emit(event, payload?): Promise<void>Emits an event to all targets.
Parameters
| Parameter | Type | Description |
|---|---|---|
event | string | Event name. Must include only alphanumeric characters, -, /, : and _. |
payload? | unknown | Event payload. |
Returns
Promise<void>
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().emit('window-loaded', { loggedIn: true, token: 'authToken' });Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L440
emitTo()
emitTo( target, event,payload?): Promise<void>Emits an event to all targets matching the given target.
Parameters
| Parameter | Type | Description |
|---|---|---|
target | string | EventTarget | Label of the target Window/Webview/WebviewWindow or raw EventTarget object. |
event | string | Event name. Must include only alphanumeric characters, -, /, : and _. |
payload? | unknown | Event payload. |
Returns
Promise<void>
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L467
hide()
hide(): Promise<void>Sets the window visibility to false.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().hide();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1064
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.
Returns
The window’s inner position.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const position = await getCurrentWindow().innerPosition();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L528
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.
Returns
The window’s inner size.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const size = await getCurrentWindow().innerSize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L561
isClosable()
isClosable(): Promise<boolean>Gets the window’s native close button state.
Platform-specific
- iOS / Android: Unsupported.
Returns
Promise<boolean>
Whether the window’s native close button is enabled or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const closable = await getCurrentWindow().isClosable();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L741
isDecorated()
isDecorated(): Promise<boolean>Gets the window’s current decorated state.
Returns
Promise<boolean>
Whether the window is decorated or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const decorated = await getCurrentWindow().isDecorated();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L662
isFocused()
isFocused(): Promise<boolean>Gets the window’s current focus state.
Returns
Promise<boolean>
Whether the window is focused or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const focused = await getCurrentWindow().isFocused();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L646
isFullscreen()
isFullscreen(): Promise<boolean>Gets the window’s current fullscreen state.
Returns
Promise<boolean>
Whether the window is in fullscreen mode or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const fullscreen = await getCurrentWindow().isFullscreen();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L600
isMaximizable()
isMaximizable(): Promise<boolean>Gets the window’s native maximize button state.
Platform-specific
- Linux / iOS / Android: Unsupported.
Returns
Promise<boolean>
Whether the window’s native maximize button is enabled or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const maximizable = await getCurrentWindow().isMaximizable();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L699
isMaximized()
isMaximized(): Promise<boolean>Gets the window’s current maximized state.
Returns
Promise<boolean>
Whether the window is maximized or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const maximized = await getCurrentWindow().isMaximized();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L630
isMinimizable()
isMinimizable(): Promise<boolean>Gets the window’s native minimize button state.
Platform-specific
- Linux / iOS / Android: Unsupported.
Returns
Promise<boolean>
Whether the window’s native minimize button is enabled or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const minimizable = await getCurrentWindow().isMinimizable();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L720
isMinimized()
isMinimized(): Promise<boolean>Gets the window’s current minimized state.
Returns
Promise<boolean>
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const minimized = await getCurrentWindow().isMinimized();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L614
isResizable()
isResizable(): Promise<boolean>Gets the window’s current resizable state.
Returns
Promise<boolean>
Whether the window is resizable or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const resizable = await getCurrentWindow().isResizable();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L678
isVisible()
isVisible(): Promise<boolean>Gets the window’s current visible state.
Returns
Promise<boolean>
Whether the window is visible or not.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const visible = await getCurrentWindow().isVisible();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L757
listen()
listen<T>(event, handler): Promise<UnlistenFn>Listen to an emitted event on this window.
Type parameters
| Type parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, -, /, : and _. |
handler | EventCallback<T> | Event handler. |
Returns
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.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L378
maximize()
maximize(): Promise<void>Maximizes the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().maximize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L968
minimize()
minimize(): Promise<void>Minimizes the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().minimize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1016
onCloseRequested()
onCloseRequested(handler): Promise<UnlistenFn>Listen to window close requested. Emitted when the user requests to closes the window.
Parameters
| Parameter | Type |
|---|---|
handler | (event) => void | Promise<void> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";import { confirm } from '@tauri-apps/api/dialog';const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1749
onDragDropEvent()
onDragDropEvent(handler): Promise<UnlistenFn>Listen to a file drop event. The listener is triggered when the user hovers the selected files on the webview, drops the files or cancels the operation.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<DragDropEvent> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/webview";const unlisten = await getCurrentWindow().onDragDropEvent((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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1787
onFocusChanged()
onFocusChanged(handler): Promise<UnlistenFn>Listen to window focus change.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<boolean> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1865
onMoved()
onMoved(handler): Promise<UnlistenFn>Listen to window move.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<PhysicalPosition> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1720
onResized()
onResized(handler): Promise<UnlistenFn>Listen to window resize.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<PhysicalSize> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1696
onScaleChanged()
onScaleChanged(handler): Promise<UnlistenFn>Listen to window scale change. Emitted when the window’s scale factor has changed. The following user actions can cause DPI changes:
- Changing the display’s resolution.
- Changing the display’s scale factor (e.g. in Control Panel on Windows).
- Moving the window to a display with a different scale factor.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<ScaleFactorChanged> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1905
onThemeChanged()
onThemeChanged(handler): Promise<UnlistenFn>Listen to the system theme change.
Parameters
| Parameter | Type |
|---|---|
handler | EventCallback<Theme> |
Returns
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.
Example
import { getCurrentWindow } from "@tauri-apps/api/window";const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1931
once()
once<T>(event, handler): Promise<UnlistenFn>Listen to an emitted event on this window only once.
Type parameters
| Type parameter |
|---|
T |
Parameters
| Parameter | Type | Description |
|---|---|---|
event | EventName | Event name. Must include only alphanumeric characters, -, /, : and _. |
handler | EventCallback<T> | Event handler. |
Returns
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.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const unlisten = await getCurrentWindow().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 unmountedunlisten();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L413
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.
Returns
The window’s outer position.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const position = await getCurrentWindow().outerPosition();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L544
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.
Returns
The window’s outer size.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const size = await getCurrentWindow().outerSize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L581
requestUserAttention()
requestUserAttention(requestType): Promise<void>Requests user attention to the window, this has no effect if the application
is already focused. How requesting for user attention manifests is platform dependent,
see UserAttentionType for details.
Providing null will unset the request for user attention. Unsetting the request for
user attention might not be done automatically by the WM when the window receives input.
Platform-specific
- macOS:
nullhas no effect. - Linux: Urgency levels have the same effect.
Parameters
| Parameter | Type |
|---|---|
requestType | null | UserAttentionType |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().requestUserAttention();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L836
scaleFactor()
scaleFactor(): Promise<number>The scale factor that can be used to map physical pixels to logical pixels.
Returns
Promise<number>
The window’s monitor scale factor.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const factor = await getCurrentWindow().scaleFactor();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L512
setAlwaysOnBottom()
setAlwaysOnBottom(alwaysOnBottom): Promise<void>Whether the window should always be below other windows.
Parameters
| Parameter | Type | Description |
|---|---|---|
alwaysOnBottom | boolean | Whether the window should always be below other windows or not. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setAlwaysOnBottom(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1197
setAlwaysOnTop()
setAlwaysOnTop(alwaysOnTop): Promise<void>Whether the window should always be on top of other windows.
Parameters
| Parameter | Type | Description |
|---|---|---|
alwaysOnTop | boolean | Whether 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.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setAlwaysOnTop(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1179
setClosable()
setClosable(closable): Promise<void>Sets whether the window’s native close button is enabled or not.
Platform-specific
- Linux: GTK+ will do its best to convince the window manager not to show a close button. Depending on the system, this function may not have any effect when called on a window that is already visible
- iOS / Android: Unsupported.
Parameters
| Parameter | Type |
|---|---|
closable | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setClosable(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L933
setContentProtected()
setContentProtected(protected_): Promise<void>Prevents the window contents from being captured by other apps.
Parameters
| Parameter | Type |
|---|---|
protected_ | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setContentProtected(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1214
setCursorGrab()
setCursorGrab(grab): Promise<void>Grabs the cursor, preventing it from leaving the window.
There’s no guarantee that the cursor will be hidden. You should hide it by yourself if you want so.
Platform-specific
- Linux: Unsupported.
- macOS: This locks the cursor in a fixed location, which looks visually awkward.
Parameters
| Parameter | Type | Description |
|---|---|---|
grab | boolean | true to grab the cursor icon, false to release it. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorGrab(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1487
setCursorIcon()
setCursorIcon(icon): Promise<void>Modifies the cursor icon of the window.
Parameters
| Parameter | Type | Description |
|---|---|---|
icon | CursorIcon | The new cursor icon. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorIcon('help');Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1529
setCursorPosition()
setCursorPosition(position): Promise<void>Changes the position of the cursor in window coordinates.
Parameters
| Parameter | Type | Description |
|---|---|---|
position | LogicalPosition | PhysicalPosition | The new cursor position. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';await getCurrentWindow().setCursorPosition(new LogicalPosition(600, 300));Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1547
setCursorVisible()
setCursorVisible(visible): Promise<void>Modifies the cursor’s visibility.
Platform-specific
- Windows: The cursor is only hidden within the confines of the window.
- macOS: The cursor is hidden as long as the window has input focus, even if the cursor is outside of the window.
Parameters
| Parameter | Type | Description |
|---|---|---|
visible | boolean | If 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.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorVisible(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1511
setDecorations()
setDecorations(decorations): Promise<void>Whether the window should have borders and bars.
Parameters
| Parameter | Type | Description |
|---|---|---|
decorations | boolean | Whether the window should have borders and bars. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setDecorations(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1115
setEffects()
setEffects(effects): Promise<void>Set window effects.
Parameters
| Parameter | Type |
|---|---|
effects | Effects |
Returns
Promise<void>
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1151
setFocus()
setFocus(): Promise<void>Bring the window to front and focus.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setFocus();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1413
setFullscreen()
setFullscreen(fullscreen): Promise<void>Sets the window fullscreen state.
Parameters
| Parameter | Type | Description |
|---|---|---|
fullscreen | boolean | Whether the window should go to fullscreen or not. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setFullscreen(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1396
setIcon()
setIcon(icon): Promise<void>Sets the window icon.
Parameters
| Parameter | Type | Description |
|---|---|---|
icon | | string | number[] | ArrayBuffer | Uint8Array | Image | Icon bytes or path to the icon file. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setIcon('/tauri/awesome.png');Note that you need the image-ico or image-png Cargo features to use this API.
To enable it, change your Cargo.toml file:
[dependencies]tauri = { version = "...", features = ["...", "image-png"] }Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1437
setIgnoreCursorEvents()
setIgnoreCursorEvents(ignore): Promise<void>Changes the cursor events behavior.
Parameters
| Parameter | Type | Description |
|---|---|---|
ignore | boolean | true to ignore the cursor events; false to process them as usual. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setIgnoreCursorEvents(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1583
setMaxSize()
setMaxSize(size): Promise<void>Sets the window maximum inner size. If the size argument is undefined, the constraint is unset.
Parameters
| Parameter | Type | Description |
|---|---|---|
size | undefined | null | LogicalSize | PhysicalSize | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setMaxSize(new LogicalSize(600, 500));Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1297
setMaximizable()
setMaximizable(maximizable): Promise<void>Sets whether the window’s native maximize button is enabled or not. If resizable is set to false, this setting is ignored.
Platform-specific
- macOS: Disables the “zoom” button in the window titlebar, which is also used to enter fullscreen mode.
- Linux / iOS / Android: Unsupported.
Parameters
| Parameter | Type |
|---|---|
maximizable | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setMaximizable(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L888
setMinSize()
setMinSize(size): Promise<void>Sets the window minimum inner size. If the size argument is not provided, the constraint is unset.
Parameters
| Parameter | Type | Description |
|---|---|---|
size | undefined | null | LogicalSize | PhysicalSize | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, PhysicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setMinSize(new PhysicalSize(600, 500));Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1262
setMinimizable()
setMinimizable(minimizable): Promise<void>Sets whether the window’s native minimize button is enabled or not.
Platform-specific
- Linux / iOS / Android: Unsupported.
Parameters
| Parameter | Type |
|---|---|
minimizable | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setMinimizable(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L910
setPosition()
setPosition(position): Promise<void>Sets the window outer position.
Parameters
| Parameter | Type | Description |
|---|---|---|
position | LogicalPosition | PhysicalPosition | The new position, in logical or physical pixels. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';await getCurrentWindow().setPosition(new LogicalPosition(600, 500));Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1361
setProgressBar()
setProgressBar(state): Promise<void>Sets the taskbar progress state.
Platform-specific
- Linux / macOS: Progress bar is app-wide and not specific to this window.
- Linux: Only supported desktop environments with
libunity(e.g. GNOME).
Parameters
| Parameter | Type |
|---|---|
state | ProgressBarState |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, ProgressBarStatus } from '@tauri-apps/api/window';await getCurrentWindow().setProgressBar({ status: ProgressBarStatus.Normal, progress: 50,});Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1642
setResizable()
setResizable(resizable): Promise<void>Updates the window resizable flag.
Parameters
| Parameter | Type |
|---|---|
resizable | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setResizable(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L864
setShadow()
setShadow(enable): Promise<void>Whether or not the window should have shadow.
Platform-specific
- Windows:
falsehas no effect on decorated window, shadows are always ON.truewill make ndecorated window have a 1px white border, and on Windows 11, it will have a rounded corners.
- Linux: Unsupported.
Parameters
| Parameter | Type |
|---|---|
enable | boolean |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setShadow(false);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1141
setSize()
setSize(size): Promise<void>Resizes the window with a new inner size.
Parameters
| Parameter | Type | Description |
|---|---|---|
size | LogicalSize | PhysicalSize | The logical or physical inner size. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setSize(new LogicalSize(600, 500));Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1232
setSizeConstraints()
setSizeConstraints(constraints): Promise<void>Sets the window inner size constraints.
Parameters
| Parameter | Type | Description |
|---|---|---|
constraints | undefined | null | WindowSizeConstraints | The logical or physical inner size, or null to unset the constraint. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setSizeConstraints({ minWidth: 300 });Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1332
setSkipTaskbar()
setSkipTaskbar(skip): Promise<void>Whether the window icon should be hidden from the taskbar or not.
Platform-specific
- macOS: Unsupported.
Parameters
| Parameter | Type | Description |
|---|---|---|
skip | boolean | true to hide window icon, false to show it. |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setSkipTaskbar(true);Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1461
setTitle()
setTitle(title): Promise<void>Sets the window title.
Parameters
| Parameter | Type | Description |
|---|---|---|
title | string | The new title |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setTitle('Tauri');Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L951
setTitleBarStyle()
setTitleBarStyle(style): Promise<void>Sets the title bar style. macOS only.
Parameters
| Parameter | Type |
|---|---|
style | TitleBarStyle |
Returns
Promise<void>
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1670
setVisibleOnAllWorkspaces()
setVisibleOnAllWorkspaces(visible): Promise<void>Sets whether the window should be visible on all workspaces or virtual desktops.
Platform-specific
- Windows / iOS / Android: Unsupported.
Parameters
| Parameter | Type |
|---|---|
visible | boolean |
Returns
Promise<void>
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1658
show()
show(): Promise<void>Sets the window visibility to true.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().show();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1048
startDragging()
startDragging(): Promise<void>Starts dragging the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().startDragging();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1600
startResizeDragging()
startResizeDragging(direction): Promise<void>Starts resize-dragging the window.
Parameters
| Parameter | Type |
|---|---|
direction | ResizeDirection |
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().startResizeDragging();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1616
theme()
theme(): Promise<null | Theme>Gets the window’s current theme.
Platform-specific
- macOS: Theme was introduced on macOS 10.14. Returns
lighton macOS 10.13 and below.
Returns
The window theme.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const theme = await getCurrentWindow().theme();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L792
title()
title(): Promise<string>Gets the window’s current title.
Returns
Promise<string>
Example
import { getCurrentWindow } from '@tauri-apps/api/window';const title = await getCurrentWindow().title();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L771
toggleMaximize()
toggleMaximize(): Promise<void>Toggles the window maximized state.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().toggleMaximize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1000
unmaximize()
unmaximize(): Promise<void>Unmaximizes the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().unmaximize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L984
unminimize()
unminimize(): Promise<void>Unminimizes the window.
Returns
Promise<void>
A promise indicating the success or failure of the operation.
Example
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().unminimize();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1032
getAll()
static getAll(): Window[]Gets a list of instances of Window for all available windows.
Returns
Window[]
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L336
getByLabel()
static getByLabel(label): null | WindowGets the Window associated with the given label.
Parameters
| Parameter | Type | Description |
|---|---|---|
label | string | The window label. |
Returns
null | Window
The Window instance to communicate with the window or null if the window doesn’t exist.
Example
import { Window } from '@tauri-apps/api/window';const mainWindow = Window.getByLabel('main');Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L322
getCurrent()
static getCurrent(): WindowGet an instance of Window for the current window.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L329
getFocusedWindow()
static getFocusedWindow(): Promise<null | Window>Gets the focused window.
Returns
The Window instance or undefined if there is not any focused window.
Example
import { Window } from '@tauri-apps/api/window';const focusedWindow = Window.getFocusedWindow();Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L350
Interfaces
Effects
The window effects configuration object
Since
2.0.0
Properties
| Property | Type | Description |
|---|---|---|
color? | Color | Window effect color. Affects Effect.Blur and Effect.Acrylic only on Windows 10 v1903+. Doesn’t have any effect on Windows 7 or Windows 11. |
effects | Effect[] | List of Window effects to apply to the Window. Conflicting effects will apply the first one and ignore the rest. |
radius? | number | Window effect corner radius macOS Only |
state? | EffectState | Window effect state macOS Only |
Monitor
Allows you to retrieve information about a given monitor.
Since
1.0.0
Properties
| Property | Type | Description |
|---|---|---|
name | null | string | Human-readable name of the monitor |
position | PhysicalPosition | the Top-left corner position of the monitor relative to the larger full screen area. |
scaleFactor | number | The scale factor that can be used to map physical pixels to logical pixels. |
size | PhysicalSize | The monitor’s resolution. |
ProgressBarState
Properties
| Property | Type | Description |
|---|---|---|
progress? | number | The progress bar progress. This can be a value ranging from 0 to 100 |
status? | ProgressBarStatus | The progress bar status. |
ScaleFactorChanged
The payload for the scaleChange event.
Since
1.0.2
Properties
| Property | Type | Description |
|---|---|---|
scaleFactor | number | The new window scale factor. |
size | PhysicalSize | The new window size |
WindowOptions
Configuration for the window to create.
Since
1.0.0
Properties
| Property | Type | Description |
|---|---|---|
alwaysOnBottom? | boolean | Whether the window should always be below other windows. |
alwaysOnTop? | boolean | Whether the window should always be on top of other windows or not. |
center? | boolean | Show window in the center of the screen.. |
closable? | boolean | Whether the window’s native close button is enabled or not. Defaults to true. |
contentProtected? | boolean | Prevents the window contents from being captured by other apps. |
decorations? | boolean | Whether the window should have borders and bars or not. |
focus? | boolean | Whether the window will be initially focused or not. |
fullscreen? | boolean | Whether the window is in fullscreen mode or not. |
height? | number | The initial height. |
hiddenTitle? | boolean | If true, sets the window title to be hidden on macOS. |
maxHeight? | number | The maximum height. Only applies if maxWidth is also set. |
maxWidth? | number | The maximum width. Only applies if maxHeight is also set. |
maximizable? | boolean | Whether the window’s native maximize button is enabled or not. Defaults to true. |
maximized? | boolean | Whether the window should be maximized upon creation or not. |
minHeight? | number | The minimum height. Only applies if minWidth is also set. |
minWidth? | number | The minimum width. Only applies if minHeight is also set. |
minimizable? | boolean | Whether the window’s native minimize button is enabled or not. Defaults to true. |
parent? | string | Window | WebviewWindow | Sets a parent to the window to be created. Can be either a Platform-specific
|
resizable? | boolean | Whether the window is resizable or not. |
shadow? | boolean | Whether or not the window has shadow. Platform-specific
Since 2.0.0 |
skipTaskbar? | boolean | Whether or not the window icon should be added to the taskbar. |
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. |
theme? | Theme | The initial window theme. Defaults to the system theme. Only implemented on Windows and macOS 10.14+. |
title? | string | Window title. |
titleBarStyle? | TitleBarStyle | The style of the macOS title bar. |
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 > app > macOSPrivateApi. WARNING: Using private APIs on macOS prevents your application from being accepted to the App Store. |
visible? | boolean | Whether the window should be immediately visible upon creation or not. |
visibleOnAllWorkspaces? | boolean | Whether the window should be visible on all workspaces or virtual desktops. Platform-specific
Since 2.0.0 |
width? | number | The initial width. |
x? | number | The initial vertical position. Only applies if y is also set. |
y? | number | The initial horizontal position. Only applies if x is also set. |
WindowSizeConstraints
Properties
| Property | Type |
|---|---|
maxHeight? | number |
maxWidth? | number |
minHeight? | number |
minWidth? | number |
Type Aliases
Color
type Color: [number, number, number, number];an array RGBA colors. Each value has minimum of 0 and maximum of 255.
Since
2.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L1941
CursorIcon
type CursorIcon: | "default" | "crosshair" | "hand" | "arrow" | "move" | "text" | "wait" | "help" | "progress" | "notAllowed" | "contextMenu" | "cell" | "verticalText" | "alias" | "copy" | "noDrop" | "grab" | "grabbing" | "allScroll" | "zoomIn" | "zoomOut" | "eResize" | "nResize" | "neResize" | "nwResize" | "sResize" | "seResize" | "swResize" | "wResize" | "ewResize" | "nsResize" | "neswResize" | "nwseResize" | "colResize" | "rowResize";Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L122
Theme
type Theme: "light" | "dark";Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L56
TitleBarStyle
type TitleBarStyle: "visible" | "transparent" | "overlay";Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L57
Functions
availableMonitors()
function availableMonitors(): Promise<Monitor[]>Returns the list of all the monitors available on the system.
Returns
Example
import { availableMonitors } from '@tauri-apps/api/window';const monitors = availableMonitors();Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2320
currentMonitor()
function currentMonitor(): Promise<Monitor | null>Returns the monitor on which the window currently resides.
Returns null if current monitor can’t be detected.
Returns
Example
import { currentMonitor } from '@tauri-apps/api/window';const monitor = currentMonitor();Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2270
cursorPosition()
function cursorPosition(): Promise<PhysicalPosition>Get the cursor position relative to the top-left hand corner of the desktop.
Note that the top-left hand corner of the desktop is not necessarily the same as the screen. If the user uses a desktop with multiple monitors, the top-left hand corner of the desktop is the top-left hand corner of the main monitor on Windows and macOS or the top-left of the leftmost monitor on X11.
The coordinates can be negative if the top-left hand corner of the window is outside of the visible screen region.
Returns
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2336
getAllWindows()
function getAllWindows(): Window[]Gets a list of instances of Window for all available windows.
Returns
Window[]
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L221
getCurrentWindow()
function getCurrentWindow(): WindowGet an instance of Window for the current window.
Returns
Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L209
monitorFromPoint()
function monitorFromPoint(x, y): Promise<Monitor | null>Returns the monitor that contains the given point. Returns null if can’t find any.
Parameters
| Parameter | Type |
|---|---|
x | number |
y | number |
Returns
Example
import { monitorFromPoint } from '@tauri-apps/api/window';const monitor = monitorFromPoint();Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2303
primaryMonitor()
function primaryMonitor(): Promise<Monitor | null>Returns the primary monitor of the system.
Returns null if it can’t identify any monitor as a primary one.
Returns
Example
import { primaryMonitor } from '@tauri-apps/api/window';const monitor = primaryMonitor();Since
1.0.0
Source: https://github.com/tauri-apps/tauri/blob/dev/tooling/api/src/window.ts#L2287
© 2024 Tauri Contributors. CC-BY / MIT