window
提供创建窗口、与其他窗口通信以及操作当前窗口的API。
可以使用Window.listen监听事件
import { getCurrentWindow } from "@tauri-apps/api/window";getCurrentWindow().listen("my-window-event", ({ event, payload }) => { });重新导出颜色
重新导出DragDropEvent
重新导出LogicalPosition
重新导出LogicalSize
重新导出PhysicalPosition
重新导出PhysicalSize
后台节流策略
2.0.0
Disabled: "disabled";来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2091
Suspend: "suspend";来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2093
Throttle: "throttle";来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2092
平台特定窗口效果
2.0.0
Acrylic: "acrylic";Windows 10/11
在Windows 10 v1903+和Windows 11 build 22000上调整窗口大小/拖动窗口时,此效果性能不佳。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2207
AppearanceBased: "appearanceBased";适合视图有效外观的默认材质。macOS 10.14-
自macOS 10.14以来。您应该改为选择适当的语义材质。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2107
Blur: "blur";仅限Windows 7/10/11(22H1)
在Windows 11 build 22621上调整窗口大小/拖动窗口时,此效果性能不佳。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2199
ContentBackground: "contentBackground";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2179
Dark: "dark";macOS 10.14-
自macOS 10.14以来。请改用语义材质。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2119
FullScreenUI: "fullScreenUI";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2171
HeaderView: "headerView";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2155
HudWindow: "hudWindow";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2167
Light: "light";macOS 10.14-
自macOS 10.14以来。请改用语义材质。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2113
MediumLight: "mediumLight";macOS 10.14-
自macOS 10.14以来。请改用语义材质。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2125
Menu: "menu";macOS 10.11+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2143
Mica: "mica";仅限Windows 11
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2191
Popover: "popover";macOS 10.11+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2147
Selection: "selection";macOS 10.10+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2139
Sheet: "sheet";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2159
Sidebar: "sidebar";macOS 10.11+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2151
Tabbed: "tabbed";与系统暗色偏好匹配的选项卡效果 仅限Windows 11
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2211
TabbedDark: "tabbedDark";在暗色模式下启用的选项卡效果,但仅在系统启用了暗色模式时 仅限Windows 11
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2215
TabbedLight: "tabbedLight";浅色模式下的选项卡效果 仅限Windows 11
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2219
Titlebar: "titlebar";macOS 10.10+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2135
Tooltip: "tooltip";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2175
UltraDark: "ultraDark";macOS 10.14-
自macOS 10.14以来。请改用语义材质。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2131
UnderPageBackground: "underPageBackground";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2187
UnderWindowBackground: "underWindowBackground";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2183
WindowBackground: "windowBackground";macOS 10.14+
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2163
窗口效果状态 仅限macOS
https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
2.0.0
Active: "active";使窗口效果状态始终处于活动状态 仅限macOS
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2237
FollowsWindowActiveState: "followsWindowActiveState";使窗口效果状态跟随窗口的活动状态 仅限macOS
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2233
Inactive: "inactive";使窗口效果状态始终处于非活动状态 仅限macOS
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2241
Error: "error";错误状态。在Linux上被视为正常
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L190
Indeterminate: "indeterminate";不确定状态。在Linux和macOS上被视为正常
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L182
None: "none";隐藏进度条。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L174
Normal: "normal";正常状态。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L178
Paused: "paused";暂停状态。在Linux上被视为正常
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L186
请求窗口注意的类型。
1.0.0
Critical: 1;平台特定
- macOS: 使停靠栏图标弹跳,直到应用程序获得焦点。
- Windows: 闪烁窗口和任务栏按钮,直到应用程序获得焦点。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L99
Informational: 2;平台特定
- macOS: 停靠栏图标弹跳一次。
- Windows: 任务栏按钮闪烁,直到应用程序获得焦点。
来源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L105
new CloseRequestedEvent(event): CloseRequestedEvent| 参数 | 类型 |
|---|---|
event | Event<未知> |
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L115
isPreventDefault(): boolean布尔值 (boolean)
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L124
preventDefault(): void空
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L120
创建新窗口或获取现有窗口的句柄。
窗口由一个*标签*(一个用于后续引用的唯一标识符)标识。它只能包含字母数字字符 a-zA-Z 以及以下特殊字符 -、/、: 和 _。
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();2.0.0
new Window(label, options): Window创建一个新窗口。
| 参数 | 类型 | 描述 |
|---|---|---|
标签 | 字符串 | 唯一的窗口标签。必须是字母数字:a-zA-Z-/:_。 |
选项 | 窗口选项 | - |
与窗口通信的 Window 实例。
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});源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L298
| 属性 | 类型 | 描述 | 定义于 |
|---|---|---|---|
标签 | 字符串 | 窗口标签。它是窗口的唯一标识符,可用于后续引用。 | 源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L276 |
监听器 | Record<字符串, EventCallback<任意>[]> | 本地事件监听器。 | 源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L279 |
center(): Promise<void>将窗口居中。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().center();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L835
clearEffects(): Promise<void>如果可能,清除任何应用的特效。
Promise<void>
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1223
close(): Promise<void>关闭窗口。
请注意,这将触发一个 closeRequested 事件,因此您可以拦截它。要强制关闭窗口,请使用 Window.destroy。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().close();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1144
destroy(): Promise<void>销毁窗口。行为类似于 Window.close,但强制关闭窗口而不是发出 closeRequested 事件。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().destroy();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1160
emit<T>(event, payload?): Promise<void>向所有 目标 发出事件。
| 类型参数 |
|---|
T |
| 参数 | 类型 | 描述 |
|---|---|---|
event | 字符串 | 事件名称。必须只包含字母数字字符、-、/、: 和 _。 |
载荷 (payload)? | T | 事件载荷。 |
Promise<void>
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().emit('window-loaded', { loggedIn: true, token: 'authToken' });源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L449
emitTo<T>( target, event,payload?): Promise<void>向所有与给定目标匹配的 目标 发出事件。
| 类型参数 |
|---|
T |
| 参数 | 类型 | 描述 |
|---|---|---|
目标 | 字符串 | EventTarget | 目标窗口/WebView/WebviewWindow 的标签,或原始 EventTarget 对象。 |
event | 字符串 | 事件名称。必须只包含字母数字字符、-、/、: 和 _。 |
载荷 (payload)? | T | 事件载荷。 |
Promise<void>
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L476
hide(): Promise<void>将窗口可见性设置为 false。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().hide();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1126
innerPosition(): Promise<PhysicalPosition>窗口客户区左上角相对于桌面左上角的位置。
窗口的内部位置。
import { getCurrentWindow } from '@tauri-apps/api/window';const position = await getCurrentWindow().innerPosition();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L537
innerSize(): Promise<PhysicalSize>窗口客户区的物理大小。客户区是窗口的内容,不包括标题栏和边框。
窗口的内部大小。
import { getCurrentWindow } from '@tauri-apps/api/window';const size = await getCurrentWindow().innerSize();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L570
isAlwaysOnTop(): Promise<boolean>窗口是否配置为始终位于其他窗口之上。
Promise<布尔值>
窗口是否可见。
import { getCurrentWindow } from '@tauri-apps/api/window';const alwaysOnTop = await getCurrentWindow().isAlwaysOnTop();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L817
isClosable(): Promise<boolean>获取窗口的本地关闭按钮状态。
平台特定
- iOS / Android: 不支持。
Promise<布尔值>
窗口的原生关闭按钮是否启用。
import { getCurrentWindow } from '@tauri-apps/api/window';const closable = await getCurrentWindow().isClosable();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L750
isDecorated(): Promise<boolean>获取窗口当前的装饰状态。
Promise<布尔值>
窗口是否被装饰。
import { getCurrentWindow } from '@tauri-apps/api/window';const decorated = await getCurrentWindow().isDecorated();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L671
isEnabled(): Promise<boolean>窗口是否启用或禁用。
Promise<布尔值>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setEnabled(false);2.0.0
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L927
isFocused(): Promise<boolean>获取窗口当前的焦点状态。
Promise<布尔值>
窗口是否获得焦点。
import { getCurrentWindow } from '@tauri-apps/api/window';const focused = await getCurrentWindow().isFocused();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L655
isFullscreen(): Promise<boolean>获取窗口当前的满屏状态。
Promise<布尔值>
窗口是否处于全屏模式。
import { getCurrentWindow } from '@tauri-apps/api/window';const fullscreen = await getCurrentWindow().isFullscreen();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L609
isMaximizable(): Promise<boolean>获取窗口的本地最大化按钮状态。
平台特定
- Linux / iOS / Android: 不支持。
Promise<布尔值>
窗口的本地最大化按钮是否启用。
import { getCurrentWindow } from '@tauri-apps/api/window';const maximizable = await getCurrentWindow().isMaximizable();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L708
isMaximized(): Promise<boolean>获取窗口当前的最大化状态。
Promise<布尔值>
窗口是否最大化。
import { getCurrentWindow } from '@tauri-apps/api/window';const maximized = await getCurrentWindow().isMaximized();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L639
isMinimizable(): Promise<boolean>获取窗口的本地最小化按钮状态。
平台特定
- Linux / iOS / Android: 不支持。
Promise<布尔值>
窗口的原生最小化按钮是否启用。
import { getCurrentWindow } from '@tauri-apps/api/window';const minimizable = await getCurrentWindow().isMinimizable();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L729
isMinimized(): Promise<boolean>获取窗口当前的最小化状态。
Promise<布尔值>
import { getCurrentWindow } from '@tauri-apps/api/window';const minimized = await getCurrentWindow().isMinimized();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L623
isResizable(): Promise<boolean>获取窗口当前的尺寸可调整状态。
Promise<布尔值>
窗口是否可调整大小。
import { getCurrentWindow } from '@tauri-apps/api/window';const resizable = await getCurrentWindow().isResizable();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L687
isVisible(): Promise<boolean>获取窗口当前的可见状态。
Promise<布尔值>
窗口是否可见。
import { getCurrentWindow } from '@tauri-apps/api/window';const visible = await getCurrentWindow().isVisible();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L766
listen<T>(event, handler): Promise<UnlistenFn>监听此窗口发出的事件。
| 类型参数 |
|---|
T |
| 参数 | 类型 | 描述 |
|---|---|---|
event | EventName | 事件名称。必须只包含字母数字字符、-、/、: 和 _。 |
处理程序 | EventCallback<T> | 事件处理程序。 |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L387
maximize(): Promise<void>最大化窗口。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().maximize();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1030
minimize(): Promise<void>最小化窗口。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().minimize();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1078
onCloseRequested(handler): Promise<UnlistenFn>监听窗口关闭请求。当用户请求关闭窗口时发出。
| 参数 | 类型 |
|---|---|
处理程序 | (事件) => void | Promise<void> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1885
onDragDropEvent(handler): Promise<UnlistenFn>监听文件拖放事件。当用户将选定的文件悬停在 webview 上、拖放文件或取消操作时,会触发监听器。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<DragDropEvent> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
import { getCurrentWindow } from "@tauri-apps/api/webview";const unlisten = await getCurrentWindow().onDragDropEvent((event) => { if (event.payload.type === 'over') { console.log('User hovering', event.payload.position); } 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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1923
onFocusChanged(handler): Promise<UnlistenFn>监听窗口焦点变化。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<布尔值> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2001
onMoved(handler): Promise<UnlistenFn>监听窗口移动。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<PhysicalPosition> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1856
onResized(handler): Promise<UnlistenFn>监听窗口大小调整。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<PhysicalSize> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1832
onScaleChanged(handler): Promise<UnlistenFn>监听窗口比例尺变化。当窗口的比例因子发生变化时发出。以下用户操作可能导致 DPI 变化
- 更改显示器分辨率。
- 更改显示器比例因子(例如在 Windows 控制面板中)。
- 将窗口移动到具有不同比例因子的显示器。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<ScaleFactorChanged> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2041
onThemeChanged(handler): Promise<UnlistenFn>监听系统主题变化。
| 参数 | 类型 |
|---|---|
处理程序 | EventCallback<Theme> |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2067
once<T>(event, handler): Promise<UnlistenFn>只监听此窗口发出的事件一次。
| 类型参数 |
|---|
T |
| 参数 | 类型 | 描述 |
|---|---|---|
event | EventName | 事件名称。必须只包含字母数字字符、-、/、: 和 _。 |
处理程序 | EventCallback<T> | 事件处理程序。 |
一个解析为取消监听事件函数的 Promise。请注意,如果您的监听器超出范围(例如组件已卸载),则必须删除该监听器。
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();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L422
outerPosition(): Promise<PhysicalPosition>窗口左上角相对于桌面左上角的位置。
窗口的外部位置。
import { getCurrentWindow } from '@tauri-apps/api/window';const position = await getCurrentWindow().outerPosition();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L553
outerSize(): Promise<PhysicalSize>整个窗口的物理大小。这些尺寸包括标题栏和边框。如果你不想要这些(通常也不需要),请使用 inner_size。
窗口的外部大小。
import { getCurrentWindow } from '@tauri-apps/api/window';const size = await getCurrentWindow().outerSize();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L590
requestUserAttention(requestType): Promise<void>请求用户注意窗口,如果应用程序已获得焦点,则此操作无效。请求用户注意的表现形式因平台而异,详情请参阅 UserAttentionType。
提供 null 将取消用户注意请求。当窗口接收输入时,窗口管理器可能不会自动取消用户注意请求。
平台特定
- macOS:
null无效。 - Linux: 紧急程度具有相同的效果。
| 参数 | 类型 |
|---|---|
requestType | null | UserAttentionType |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().requestUserAttention();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L861
scaleFactor(): Promise<number>可用于将物理像素映射到逻辑像素的比例因子。
Promise<数字>
窗口的显示器比例因子。
import { getCurrentWindow } from '@tauri-apps/api/window';const factor = await getCurrentWindow().scaleFactor();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L521
setAlwaysOnBottom(alwaysOnBottom): Promise<void>窗口是否应始终位于其他窗口下方。
| 参数 | 类型 | 描述 |
|---|---|---|
始终在底部 | 布尔值 (boolean) | 窗口是否应始终位于其他窗口之下。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setAlwaysOnBottom(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1259
setAlwaysOnTop(alwaysOnTop): Promise<void>窗口是否应始终位于其他窗口之上。
| 参数 | 类型 | 描述 |
|---|---|---|
始终在最顶层 | 布尔值 (boolean) | 窗口是否应始终位于其他窗口之上。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setAlwaysOnTop(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1241
setBackgroundColor(color): Promise<void>设置窗口背景颜色。
平台特定
- Windows: alpha 通道被忽略。
- iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
颜色 | 颜色 |
Promise<void>
表示操作成功或失败的 Promise。
2.1.0
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1593
setBadgeCount(count?): Promise<void>设置徽章计数。它是应用程序范围的,不特定于此窗口。
平台特定
- Windows: 不支持。请改用 @{linkcode Window.setOverlayIcon}。
| 参数 | 类型 | 描述 |
|---|---|---|
计数? | 数字 | 徽章计数。使用 undefined 删除徽章。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setBadgeCount(5);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1685
setBadgeLabel(label?): Promise<void>设置徽章标签 仅限 macOS。
| 参数 | 类型 | 描述 |
|---|---|---|
标签? | 字符串 | 徽章标签。使用 undefined 删除徽章。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setBadgeLabel("Hello");源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1704
setClosable(closable): Promise<void>设置窗口的本地关闭按钮是否启用。
平台特定
- Linux: GTK+ 将尽力说服窗口管理器不显示关闭按钮。根据系统,此功能在已可见的窗口上调用时可能无效。
- iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
可关闭 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setClosable(false);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L995
setContentProtected(protected_): Promise<void>防止窗口内容被其他应用程序捕获。
| 参数 | 类型 |
|---|---|
protected_ | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setContentProtected(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1276
setCursorGrab(grab): Promise<void>抓取光标,阻止其离开窗口。
不保证光标会被隐藏。如果需要,应自行隐藏。
平台特定
- Linux: 不支持。
- macOS: 这会将光标锁定在一个固定位置,这在视觉上看起来很笨拙。
| 参数 | 类型 | 描述 |
|---|---|---|
抓取 | 布尔值 (boolean) | true 抓取光标图标,false 释放光标图标。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorGrab(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1532
setCursorIcon(icon): Promise<void>修改窗口的光标图标。
| 参数 | 类型 | 描述 |
|---|---|---|
图标 | 光标图标 | 新光标图标。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorIcon('help');源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1574
setCursorPosition(position): Promise<void>更改光标在窗口坐标中的位置。
| 参数 | 类型 | 描述 |
|---|---|---|
位置 | 逻辑位置 | 物理位置 | 位置 | 新光标位置。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';await getCurrentWindow().setCursorPosition(new LogicalPosition(600, 300));源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1608
setCursorVisible(visible): Promise<void>修改光标的可见性。
平台特定
- Windows: 光标仅在窗口范围内隐藏。
- macOS: 只要窗口具有输入焦点,光标就会隐藏,即使光标在窗口外部也是如此。
| 参数 | 类型 | 描述 |
|---|---|---|
可见的 | 布尔值 (boolean) | 如果为 false,则隐藏光标。如果为 true,则显示光标。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setCursorVisible(false);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1556
setDecorations(decorations): Promise<void>窗口是否应该有边框和标题栏。
| 参数 | 类型 | 描述 |
|---|---|---|
装饰 | 布尔值 (boolean) | 窗口是否应该有边框和标题栏。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setDecorations(false);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1177
setEffects(effects): Promise<void>设置窗口效果。
| 参数 | 类型 |
|---|---|
效果 | 效果 |
Promise<void>
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1213
setEnabled(enabled): Promise<void>启用或禁用窗口。
| 参数 | 类型 |
|---|---|
已启用 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setEnabled(false);2.0.0
源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L908
setFocus(): Promise<void>将窗口置于最前端并聚焦。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setFocus();源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1434
setFocusable(focusable): Promise<void>设置窗口是否可聚焦。
平台特定
- macOS:如果窗口已获得焦点,则在调用
set_focusable(false)后无法取消其焦点。在这种情况下,您可以考虑调用 Window.setFocus,但这会将窗口移动到背面,即在 z 轴顺序上置于底部。
| 参数 | 类型 | 描述 |
|---|---|---|
可聚焦 | 布尔值 (boolean) | 窗口是否可聚焦。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setFocusable(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1457
setFullscreen(fullscreen): Promise<void>设置窗口全屏状态。
| 参数 | 类型 | 描述 |
|---|---|---|
全屏 | 布尔值 (boolean) | 窗口是否应全屏显示。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setFullscreen(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1401
setIcon(icon): Promise<void>设置窗口图标。
| 参数 | 类型 | 描述 |
|---|---|---|
图标 | | 字符串 | Uint8Array | 数字[] | ArrayBuffer | Image | 图标字节或图标文件路径。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setIcon('/tauri/awesome.png');请注意,您可能需要 image-ico 或 image-png Cargo 功能才能使用此 API。要启用它,请更改您的 Cargo.toml 文件
[dependencies]tauri = { version = "...", features = ["...", "image-png"] }源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1482
setIgnoreCursorEvents(ignore): Promise<void>更改光标事件行为。
| 参数 | 类型 | 描述 |
|---|---|---|
忽略 | 布尔值 (boolean) | true 忽略光标事件;false 照常处理它们。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setIgnoreCursorEvents(true);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1629
setMaxSize(size): Promise<void>设置窗口最大内部大小。如果 size 参数未定义,则取消约束。
| 参数 | 类型 | 描述 |
|---|---|---|
尺寸 | | 未定义 | null | 逻辑尺寸 | 物理尺寸 | 尺寸 | 逻辑或物理内部大小,或 null 以取消约束。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setMaxSize(new LogicalSize(600, 500));源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1332
setMaximizable(maximizable): Promise<void>设置窗口的本地最大化按钮是否启用。如果resizable设置为false,则此设置将被忽略。
平台特定
- macOS: 禁用窗口标题栏中的“缩放”按钮,该按钮也用于进入全屏模式。
- Linux / iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
可最大化 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setMaximizable(false);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L950
setMinSize(size): Promise<void>设置窗口最小内部大小。如果未提供 size 参数,则取消约束。
| 参数 | 类型 | 描述 |
|---|---|---|
尺寸 | | 未定义 | null | 逻辑尺寸 | 物理尺寸 | 尺寸 | 逻辑或物理内部大小,或 null 以取消约束。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, PhysicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setMinSize(new PhysicalSize(600, 500));源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1312
setMinimizable(minimizable): Promise<void>设置窗口的本地最小化按钮是否启用。
平台特定
- Linux / iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
可最小化 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setMinimizable(false);源: https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L972
setOverlayIcon(icon?): Promise<void>设置覆盖图标。仅限 Windows,可为每个窗口设置覆盖图标。
请注意,您可能需要 image-ico 或 image-png Cargo 功能才能使用此 API。要启用它,请更改您的 Cargo.toml 文件
[dependencies]tauri = { version = "...", features = ["...", "image-png"] }| 参数 | 类型 | 描述 |
|---|---|---|
图标? | | 字符串 | Uint8Array | 数字[] | ArrayBuffer | Image | 图标字节或图标文件的路径。使用 undefined 可删除覆盖图标。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setOverlayIcon("/tauri/awesome.png");来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1733
setPosition(position): Promise<void>设置窗口外部位置。
| 参数 | 类型 | 描述 |
|---|---|---|
位置 | 逻辑位置 | 物理位置 | 位置 | 新位置,以逻辑像素或物理像素表示。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';await getCurrentWindow().setPosition(new LogicalPosition(600, 500));来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1381
setProgressBar(state): Promise<void>设置任务栏进度状态。
平台特定
- Linux / macOS:进度条是应用范围的,不特定于此窗口。
- Linux:仅支持带有
libunity的桌面环境(例如 GNOME)。
| 参数 | 类型 |
|---|---|
状态 | 进度条状态 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, ProgressBarStatus } from '@tauri-apps/api/window';await getCurrentWindow().setProgressBar({ status: ProgressBarStatus.Normal, progress: 50,});来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1761
setResizable(resizable): Promise<void>更新窗口可调整大小的标志。
| 参数 | 类型 |
|---|---|
可调整大小 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setResizable(false);来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L889
setShadow(enable): Promise<void>窗口是否应该有阴影。
平台特定
- Windows
false对装饰窗口无效,阴影始终开启。true将使无装饰窗口有 1 像素的白色边框,在 Windows 11 上,它将有圆角。
- Linux: 不支持。
| 参数 | 类型 |
|---|---|
启用 | 布尔值 (boolean) |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setShadow(false);来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1203
setSimpleFullscreen(fullscreen): Promise<void>在 macOS 上,切换到不需要新 macOS 空间的全屏模式。返回一个布尔值,指示转换是否成功(如果窗口已处于原生全屏模式,则此操作无效)。这是 macOS 在 Lion 之前版本中全屏的工作方式。它允许用户拥有全屏窗口,而无需使用另一个空间或控制整个显示器。
在其他平台上,这与 Window.setFullscreen 相同。
| 参数 | 类型 | 描述 |
|---|---|---|
全屏 | 布尔值 (boolean) | 窗口是否应该进入简单全屏模式。 |
Promise<void>
表示操作成功或失败的 Promise。
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1417
setSize(size): Promise<void>使用新的内部尺寸调整窗口大小。
| 参数 | 类型 | 描述 |
|---|---|---|
尺寸 | LogicalSize | PhysicalSize | Size | 逻辑或物理内部尺寸。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';await getCurrentWindow().setSize(new LogicalSize(600, 500));来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1294
setSizeConstraints(constraints): Promise<void>设置窗口内部尺寸约束。
| 参数 | 类型 | 描述 |
|---|---|---|
约束 | undefined | null | WindowSizeConstraints | 逻辑或物理内部大小,或 null 以取消约束。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setSizeConstraints({ minWidth: 300 });来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1352
setSkipTaskbar(skip): Promise<void>窗口图标是否应从任务栏隐藏。
平台特定
- macOS: 不支持。
| 参数 | 类型 | 描述 |
|---|---|---|
跳过 | 布尔值 (boolean) | 设置为 true 以隐藏窗口图标,设置为 false 以显示它。 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setSkipTaskbar(true);来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1506
setTheme(theme?): Promise<void>设置窗口主题,传入 null 或 undefined 以跟随系统主题
平台特定
- Linux / macOS:主题是应用范围的,不特定于此窗口。
- iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
主题? | null | Theme |
Promise<void>
2.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1806
setTitle(title): Promise<void>设置窗口标题。
| 参数 | 类型 | 描述 |
|---|---|---|
标题 | 字符串 | 新标题 |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().setTitle('Tauri');来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1013
setTitleBarStyle(style): Promise<void>设置标题栏样式。仅限 macOS。
| 参数 | 类型 |
|---|---|
样式 | 标题栏样式 |
Promise<void>
2.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1789
setVisibleOnAllWorkspaces(visible): Promise<void>设置窗口是否应在所有工作区或虚拟桌面上可见。
平台特定
- Windows / iOS / Android: 不支持。
| 参数 | 类型 |
|---|---|
可见的 | 布尔值 (boolean) |
Promise<void>
2.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1777
show(): Promise<void>将窗口可见性设置为 true。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().show();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1110
startDragging(): Promise<void>开始拖动窗口。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().startDragging();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1646
startResizeDragging(direction): Promise<void>开始调整窗口大小拖动。
| 参数 | 类型 |
|---|---|
方向 | ResizeDirection |
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().startResizeDragging();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1662
theme(): Promise<null | Theme>获取窗口当前主题。
平台特定
- macOS: 主题在 macOS 10.14 中引入。在 macOS 10.13 及更低版本上返回
light。
窗口主题。
import { getCurrentWindow } from '@tauri-apps/api/window';const theme = await getCurrentWindow().theme();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L801
title(): Promise<string>获取窗口当前标题。
Promise<string>
import { getCurrentWindow } from '@tauri-apps/api/window';const title = await getCurrentWindow().title();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L780
toggleMaximize(): Promise<void>切换窗口最大化状态。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().toggleMaximize();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1062
unmaximize(): Promise<void>取消窗口最大化。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().unmaximize();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1046
unminimize(): Promise<void>取消窗口最小化。
Promise<void>
表示操作成功或失败的 Promise。
import { getCurrentWindow } from '@tauri-apps/api/window';await getCurrentWindow().unminimize();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L1094
static getAll(): Promise<Window[]>获取所有可用窗口的 Window 实例列表。
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L345
static getByLabel(label): Promise<null | Window>获取与给定标签关联的 Window。
| 参数 | 类型 | 描述 |
|---|---|---|
标签 | 字符串 | 窗口标签。 |
用于与窗口通信的 Window 实例,如果窗口不存在则为 null。
import { Window } from '@tauri-apps/api/window';const mainWindow = Window.getByLabel('main');来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L331
static getCurrent(): Window获取当前窗口的 Window 实例。
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L338
static getFocusedWindow(): Promise<null | Window>获取焦点窗口。
Window 实例,如果没有任何焦点窗口,则为 undefined。
import { Window } from '@tauri-apps/api/window';const focusedWindow = Window.getFocusedWindow();来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L359
窗口效果配置对象
2.0.0
| 属性 | 类型 | 描述 | 定义于 |
|---|---|---|---|
color? | 颜色 | 窗口效果颜色。仅在 Windows 10 v1903+ 上影响 Effect.Blur 和 Effect.Acrylic。对 Windows 7 或 Windows 11 没有影响。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2266 |
effects | 效果[] | 要应用于窗口的窗口效果列表。冲突的效果将应用第一个并忽略其余的。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2253 |
radius? | 数字 | 窗口效果圆角半径仅限 macOS | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2261 |
state? | 效果状态 | 窗口效果状态仅限 macOS | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2257 |
允许您检索有关给定显示器的信息。
1.0.0
| 属性 | 类型 | 描述 | 定义于 |
|---|---|---|---|
name | null | string | 显示器的人性化名称 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L49 |
position | 物理位置 | 显示器相对于更大全屏区域的左上角位置。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L53 |
scaleFactor | 数字 | 可用于将物理像素映射到逻辑像素的比例因子。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L60 |
size | 物理大小 | 显示器分辨率。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L51 |
workArea | 对象 | 显示器的工作区域。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L55 |
workArea.position | 物理位置 | - | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L56 |
workArea.size | 物理大小 | - | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L57 |
| 属性 | 类型 | 描述 | 定义于 |
|---|---|---|---|
progress? | 数字 | 进度条进度。值范围为 0 到 100 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L208 |
status? | 进度条状态 | 进度条状态。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L204 |
scaleChange 事件的负载。
1.0.2
| 属性 | 类型 | 描述 | 定义于 |
|---|---|---|---|
scaleFactor | 数字 | 新窗口缩放因子。 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L83 |
size | 物理大小 | 新窗口尺寸 | 来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L85 |
要创建的窗口配置。
1.0.0
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";来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L129
type Theme: "light" | "dark";来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L63
type TitleBarStyle: "visible" | "transparent" | "overlay";来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L64
function availableMonitors(): Promise<Monitor[]>返回系统上所有可用显示器的列表。
import { availableMonitors } from '@tauri-apps/api/window';const monitors = await availableMonitors();1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2554
function currentMonitor(): Promise<Monitor | null>返回窗口当前所在的显示器。如果无法检测到当前显示器,则返回 null。
import { currentMonitor } from '@tauri-apps/api/window';const monitor = await currentMonitor();1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2504
function cursorPosition(): Promise<PhysicalPosition>获取光标相对于桌面左上角的位置。
请注意,桌面的左上角不一定与屏幕相同。如果用户使用多显示器桌面,Windows 和 macOS 上的桌面左上角是主显示器的左上角,而 X11 上是左侧显示器的左上角。
如果窗口的左上角位于可见屏幕区域之外,则坐标可能为负数。
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2570
function getAllWindows(): Promise<Window[]>获取所有可用窗口的 Window 实例列表。
1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L228
function getCurrentWindow(): Window获取当前窗口的 Window 实例。
1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L216
function monitorFromPoint(x, y): Promise<Monitor | null>返回包含给定点的显示器。如果找不到任何显示器,则返回 null。
| 参数 | 类型 |
|---|---|
x | 数字 |
y | 数字 |
import { monitorFromPoint } from '@tauri-apps/api/window';const monitor = await monitorFromPoint(100.0, 200.0);1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2537
function primaryMonitor(): Promise<Monitor | null>返回系统的主显示器。如果无法将任何显示器识别为主显示器,则返回 null。
import { primaryMonitor } from '@tauri-apps/api/window';const monitor = await primaryMonitor();1.0.0
来源:https://github.com/tauri-apps/tauri/blob/dev/packages/api/src/window.ts#L2521
© 2025 Tauri 贡献者。CC-BY / MIT