refactor(api)!: renamed getCurrent functions to avoid ambiguity (#10229)

* refactor(api)!: renamed `getCurrent` functions to avoid ambiguity

closes #10193

* Update .changes/get-current-ambguity.md

* rename `getAll` and update docs and examples
This commit is contained in:
Amr Bashir
2024-07-11 14:26:15 +03:00
committed by GitHub
parent 249cdde9b6
commit 2b1ceb40d3
10 changed files with 207 additions and 191 deletions

View File

@@ -0,0 +1,13 @@
---
"@tauri-apps/api": "patch:breaking"
"tauri": "patch:breaking"
---
Renamed the JS `getCurrent` and `getAll` functions to a clearer name to avoid ambiguity:
- `getCurrent` in `window` module has been renamed to `getCurrentWindow`
- `getCurrent` in `webview` module has been renamed to `getCurrentWebview`
- `getCurrent` in `webviewWindow` module has been renamed to `getCurrentWebviewWindow`
- `getAll` in `window` module has been renamed to `getAllWindows`
- `getAll` in `webview` module has been renamed to `getAllWebviews`
- `getAll` in `webviewWindow` module has been renamed to `getAllWebviewWindows`

File diff suppressed because one or more lines are too long

View File

@@ -1,12 +1,12 @@
<script>
import { getCurrent } from '@tauri-apps/api/webviewWindow'
import { getCurrentWebviewWindow } from '@tauri-apps/api/webviewWindow'
import { invoke } from '@tauri-apps/api/core'
import { onMount, onDestroy } from 'svelte'
export let onMessage
let unlisten
const webviewWindow = getCurrent()
const webviewWindow = getCurrentWebviewWindow()
onMount(async () => {
unlisten = await webviewWindow.listen('rust-event', onMessage)

View File

@@ -15,7 +15,7 @@
<script>
const WebviewWindow = window.__TAURI__.webviewWindow.WebviewWindow
const appWindow = window.__TAURI__.window.getCurrent()
const appWindow = window.__TAURI__.window.getCurrentWindow()
const windowLabel = appWindow.label
const windowLabelContainer = document.getElementById('window-label')
windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'
@@ -75,7 +75,7 @@
})
container.appendChild(globalMessageButton)
const allWindows = window.__TAURI__.window.getAll()
const allWindows = window.__TAURI__.window.getAllWindows()
for (const index in allWindows) {
const label = allWindows[index].label
if (label === windowLabel) {

View File

@@ -15,7 +15,7 @@
<script>
const { WebviewWindow } = window.__TAURI__.webviewWindow
const thisTauriWindow = window.__TAURI__.window.getCurrent()
const thisTauriWindow = window.__TAURI__.window.getCurrentWindow()
const windowLabel = thisTauriWindow.label
const windowLabelContainer = document.getElementById('window-label')
windowLabelContainer.innerText = 'This is the ' + windowLabel + ' window.'

View File

@@ -37,8 +37,8 @@ class PhysicalSize {
* Converts the physical size to a logical one.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const appWindow = getCurrentWindow();
* const factor = await appWindow.scaleFactor();
* const size = await appWindow.innerSize();
* const logical = size.toLogical(factor);
@@ -84,8 +84,8 @@ class PhysicalPosition {
* Converts the physical position to a logical one.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const appWindow = getCurrentWindow();
* const factor = await appWindow.scaleFactor();
* const position = await appWindow.innerPosition();
* const logical = position.toLogical(factor);

View File

@@ -111,11 +111,11 @@ export function mockIPC(
*
* ```js
* import { mockWindows } from "@tauri-apps/api/mocks";
* import { getCurrent } from "@tauri-apps/api/window";
* import { getCurrentWindow } from "@tauri-apps/api/window";
*
* mockWindows("main", "second", "third");
*
* const win = getCurrent();
* const win = getCurrentWindow();
*
* win.label // "main"
* ```

View File

@@ -9,8 +9,8 @@
*
* Events can be listened to using {@link Webview.listen}:
* ```typescript
* import { getCurrent } from "@tauri-apps/api/webview";
* getCurrent().listen("my-webview-event", ({ event, payload }) => { });
* import { getCurrentWebview } from "@tauri-apps/api/webview";
* getCurrentWebview().listen("my-webview-event", ({ event, payload }) => { });
* ```
*
* @module
@@ -29,7 +29,7 @@ import {
once
} from './event'
import { invoke } from './core'
import { Window, getCurrent as getCurrentWindow } from './window'
import { Window, getCurrentWindow } from './window'
import { WebviewWindow } from './webviewWindow'
interface DragDropPayload {
@@ -53,7 +53,7 @@ type DragDropEvent =
*
* @since 2.0.0
*/
function getCurrent(): Webview {
function getCurrentWebview(): Webview {
return new Webview(
getCurrentWindow(),
window.__TAURI_INTERNALS__.metadata.currentWebview.label,
@@ -69,7 +69,7 @@ function getCurrent(): Webview {
*
* @since 2.0.0
*/
function getAll(): Webview[] {
function getAllWebviews(): Webview[] {
return window.__TAURI_INTERNALS__.metadata.webviews.map(
(w) =>
new Webview(Window.getByLabel(w.windowLabel)!, w.label, {
@@ -184,21 +184,21 @@ class Webview {
* @returns The Webview instance to communicate with the webview or null if the webview doesn't exist.
*/
static getByLabel(label: string): Webview | null {
return getAll().find((w) => w.label === label) ?? null
return getAllWebviews().find((w) => w.label === label) ?? null
}
/**
* Get an instance of `Webview` for the current webview.
*/
static getCurrent(): Webview {
return getCurrent()
return getCurrentWebview()
}
/**
* Gets a list of instances of `Webview` for all available webviews.
*/
static getAll(): Webview[] {
return getAll()
return getAllWebviews()
}
/**
@@ -206,8 +206,8 @@ class Webview {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* const unlisten = await getCurrent().listen<string>('state-changed', (event) => {
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* const unlisten = await getCurrentWebview().listen<string>('state-changed', (event) => {
* console.log(`Got error: ${payload}`);
* });
*
@@ -241,7 +241,7 @@ class Webview {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* const unlisten = await getCurrent().once<null>('initialized', (event) => {
* console.log(`Webview initialized!`);
* });
@@ -276,8 +276,8 @@ class Webview {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().emit('webview-loaded', { loggedIn: true, token: 'authToken' });
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().emit('webview-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
@@ -303,8 +303,8 @@ class Webview {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().emitTo('main', 'webview-loaded', { loggedIn: true, token: 'authToken' });
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().emitTo('main', 'webview-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object.
@@ -350,8 +350,8 @@ class Webview {
* The position of the top-left hand corner of the webview's client area relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* const position = await getCurrent().position();
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* const position = await getCurrentWebview().position();
* ```
*
* @returns The webview's position.
@@ -367,8 +367,8 @@ class Webview {
* The client area is the content of the webview, excluding the title bar and borders.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* const size = await getCurrent().size();
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* const size = await getCurrentWebview().size();
* ```
*
* @returns The webview's size.
@@ -388,8 +388,8 @@ class Webview {
* Closes the webview.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().close();
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().close();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -405,7 +405,7 @@ class Webview {
* @example
* ```typescript
* import { getCurrent, LogicalSize } from '@tauri-apps/api/webview';
* await getCurrent().setSize(new LogicalSize(600, 500));
* await getCurrentWebview().setSize(new LogicalSize(600, 500));
* ```
*
* @param size The logical or physical size.
@@ -435,7 +435,7 @@ class Webview {
* @example
* ```typescript
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/webview';
* await getCurrent().setPosition(new LogicalPosition(600, 500));
* await getCurrentWebview().setPosition(new LogicalPosition(600, 500));
* ```
*
* @param position The new position, in logical or physical pixels.
@@ -469,8 +469,8 @@ class Webview {
* Bring the webview to front and focus.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().setFocus();
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().setFocus();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -485,8 +485,8 @@ class Webview {
* Set webview zoom level.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().setZoom(1.5);
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().setZoom(1.5);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -502,8 +502,8 @@ class Webview {
* Moves this webview to the given label.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/webview';
* await getCurrent().reparent('other-window');
* import { getCurrentWebview } from '@tauri-apps/api/webview';
* await getCurrentWebview().reparent('other-window');
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -525,7 +525,7 @@ class Webview {
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/webview";
* const unlisten = await getCurrent().onDragDropEvent((event) => {
* const unlisten = await getCurrentWebview().onDragDropEvent((event) => {
* if (event.payload.type === 'hover') {
* console.log('User hovering', event.payload.paths);
* } else if (event.payload.type === 'drop') {
@@ -680,6 +680,6 @@ interface WebviewOptions {
zoomHotkeysEnabled?: boolean
}
export { Webview, getCurrent, getAll }
export { Webview, getCurrentWebview, getAllWebviews }
export type { DragDropEvent, DragDropPayload, WebviewOptions }

View File

@@ -3,7 +3,7 @@
// SPDX-License-Identifier: MIT
import {
getCurrent as getCurrentWebview,
getCurrentWebview,
Webview,
WebviewLabel,
WebviewOptions
@@ -20,7 +20,7 @@ import type { DragDropEvent, DragDropPayload } from './webview'
*
* @since 2.0.0
*/
function getCurrent(): WebviewWindow {
function getCurrentWebviewWindow(): WebviewWindow {
const webview = getCurrentWebview()
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
return new WebviewWindow(webview.label, { skip: true })
@@ -31,7 +31,7 @@ function getCurrent(): WebviewWindow {
*
* @since 2.0.0
*/
function getAll(): WebviewWindow[] {
function getAllWebviewWindows(): WebviewWindow[] {
return window.__TAURI_INTERNALS__.metadata.webviews.map(
(w) =>
new WebviewWindow(w.label, {
@@ -108,7 +108,8 @@ class WebviewWindow {
* @returns The Webview instance to communicate with the webview or null if the webview doesn't exist.
*/
static getByLabel(label: string): WebviewWindow | null {
const webview = getAll().find((w) => w.label === label) ?? null
const webview =
getAllWebviewWindows().find((w) => w.label === label) ?? null
if (webview) {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
return new WebviewWindow(webview.label, { skip: true })
@@ -120,15 +121,17 @@ class WebviewWindow {
* Get an instance of `Webview` for the current webview.
*/
static getCurrent(): WebviewWindow {
return getCurrent()
return getCurrentWebviewWindow()
}
/**
* Gets a list of instances of `Webview` for all available webviews.
*/
static getAll(): WebviewWindow[] {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
return getAll().map((w) => new WebviewWindow(w.label, { skip: true }))
return getAllWebviewWindows().map(
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
(w) => new WebviewWindow(w.label, { skip: true })
)
}
/**
@@ -232,5 +235,5 @@ function applyMixins(
})
}
export { WebviewWindow, getCurrent, getAll }
export { WebviewWindow, getCurrentWebviewWindow, getAllWebviewWindows }
export type { DragDropEvent, DragDropPayload }

View File

@@ -9,8 +9,8 @@
*
* Events can be listened to using {@link Window.listen}:
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* getCurrent().listen("my-window-event", ({ event, payload }) => { });
* import { getCurrentWindow } from "@tauri-apps/api/window";
* getCurrentWindow().listen("my-window-event", ({ event, payload }) => { });
* ```
*
* @module
@@ -199,7 +199,7 @@ export interface ProgressBarState {
*
* @since 1.0.0
*/
function getCurrent(): Window {
function getCurrentWindow(): Window {
return new Window(window.__TAURI_INTERNALS__.metadata.currentWindow.label, {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
skip: true
@@ -211,7 +211,7 @@ function getCurrent(): Window {
*
* @since 1.0.0
*/
function getAll(): Window[] {
function getAllWindows(): Window[] {
return window.__TAURI_INTERNALS__.metadata.windows.map(
(w) =>
new Window(w.label, {
@@ -313,21 +313,21 @@ class Window {
* @returns The Window instance to communicate with the window or null if the window doesn't exist.
*/
static getByLabel(label: string): Window | null {
return getAll().find((w) => w.label === label) ?? null
return getAllWindows().find((w) => w.label === label) ?? null
}
/**
* Get an instance of `Window` for the current window.
*/
static getCurrent(): Window {
return getCurrent()
return getCurrentWindow()
}
/**
* Gets a list of instances of `Window` for all available windows.
*/
static getAll(): Window[] {
return getAll()
return getAllWindows()
}
/**
@@ -341,7 +341,7 @@ class Window {
* @returns The Window instance or `undefined` if there is not any focused window.
*/
static async getFocusedWindow(): Promise<Window | null> {
for (const w of getAll()) {
for (const w of getAllWindows()) {
if (await w.isFocused()) {
return w
}
@@ -354,8 +354,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().listen<string>('state-changed', (event) => {
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const unlisten = await getCurrentWindow().listen<string>('state-changed', (event) => {
* console.log(`Got error: ${payload}`);
* });
*
@@ -389,8 +389,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().once<null>('initialized', (event) => {
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const unlisten = await getCurrentWindow().once<null>('initialized', (event) => {
* console.log(`Window initialized!`);
* });
*
@@ -423,8 +423,8 @@ class Window {
* Emits an event to all {@link EventTarget|targets}.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().emit('window-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
@@ -450,8 +450,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().emit('main', 'window-loaded', { loggedIn: true, token: 'authToken' });
* ```
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object.
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
@@ -496,8 +496,8 @@ class Window {
* The scale factor that can be used to map physical pixels to logical pixels.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const factor = await getCurrent().scaleFactor();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const factor = await getCurrentWindow().scaleFactor();
* ```
*
* @returns The window's monitor scale factor.
@@ -512,8 +512,8 @@ class Window {
* The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().innerPosition();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const position = await getCurrentWindow().innerPosition();
* ```
*
* @returns The window's inner position.
@@ -528,8 +528,8 @@ class Window {
* The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().outerPosition();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const position = await getCurrentWindow().outerPosition();
* ```
*
* @returns The window's outer position.
@@ -545,8 +545,8 @@ class Window {
* The client area is the content of the window, excluding the title bar and borders.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().innerSize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const size = await getCurrentWindow().innerSize();
* ```
*
* @returns The window's inner size.
@@ -565,8 +565,8 @@ class Window {
* These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().outerSize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const size = await getCurrentWindow().outerSize();
* ```
*
* @returns The window's outer size.
@@ -584,8 +584,8 @@ class Window {
* Gets the window's current fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const fullscreen = await getCurrent().isFullscreen();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const fullscreen = await getCurrentWindow().isFullscreen();
* ```
*
* @returns Whether the window is in fullscreen mode or not.
@@ -600,8 +600,8 @@ class Window {
* Gets the window's current minimized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimized = await getCurrent().isMinimized();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const minimized = await getCurrentWindow().isMinimized();
* ```
*/
async isMinimized(): Promise<boolean> {
@@ -614,8 +614,8 @@ class Window {
* Gets the window's current maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximized = await getCurrent().isMaximized();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const maximized = await getCurrentWindow().isMaximized();
* ```
*
* @returns Whether the window is maximized or not.
@@ -630,8 +630,8 @@ class Window {
* Gets the window's current focus state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const focused = await getCurrent().isFocused();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const focused = await getCurrentWindow().isFocused();
* ```
*
* @returns Whether the window is focused or not.
@@ -646,8 +646,8 @@ class Window {
* Gets the window's current decorated state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const decorated = await getCurrent().isDecorated();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const decorated = await getCurrentWindow().isDecorated();
* ```
*
* @returns Whether the window is decorated or not.
@@ -662,8 +662,8 @@ class Window {
* Gets the window's current resizable state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const resizable = await getCurrent().isResizable();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const resizable = await getCurrentWindow().isResizable();
* ```
*
* @returns Whether the window is resizable or not.
@@ -683,8 +683,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximizable = await getCurrent().isMaximizable();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const maximizable = await getCurrentWindow().isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
@@ -704,8 +704,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimizable = await getCurrent().isMinimizable();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const minimizable = await getCurrentWindow().isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
@@ -725,8 +725,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const closable = await getCurrent().isClosable();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const closable = await getCurrentWindow().isClosable();
* ```
*
* @returns Whether the window's native close button is enabled or not.
@@ -741,8 +741,8 @@ class Window {
* Gets the window's current visible state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const visible = await getCurrent().isVisible();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const visible = await getCurrentWindow().isVisible();
* ```
*
* @returns Whether the window is visible or not.
@@ -757,8 +757,8 @@ class Window {
* Gets the window's current title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const title = await getCurrent().title();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const title = await getCurrentWindow().title();
* ```
*/
async title(): Promise<string> {
@@ -776,8 +776,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const theme = await getCurrent().theme();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* const theme = await getCurrentWindow().theme();
* ```
*
* @returns The window theme.
@@ -794,8 +794,8 @@ class Window {
* Centers the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().center();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().center();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -820,8 +820,8 @@ class Window {
* - **Linux:** Urgency levels have the same effect.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().requestUserAttention();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().requestUserAttention();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -848,8 +848,8 @@ class Window {
* Updates the window resizable flag.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setResizable(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setResizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -872,8 +872,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMaximizable(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setMaximizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -894,8 +894,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMinimizable(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setMinimizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -917,8 +917,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setClosable(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setClosable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -934,8 +934,8 @@ class Window {
* Sets the window title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setTitle('Tauri');
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setTitle('Tauri');
* ```
*
* @param title The new title
@@ -952,8 +952,8 @@ class Window {
* Maximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().maximize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().maximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -968,8 +968,8 @@ class Window {
* Unmaximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unmaximize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().unmaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -984,8 +984,8 @@ class Window {
* Toggles the window maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().toggleMaximize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().toggleMaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1000,8 +1000,8 @@ class Window {
* Minimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().minimize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().minimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1016,8 +1016,8 @@ class Window {
* Unminimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unminimize();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().unminimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1032,8 +1032,8 @@ class Window {
* Sets the window visibility to true.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().show();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().show();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1048,8 +1048,8 @@ class Window {
* Sets the window visibility to false.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().hide();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().hide();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1066,8 +1066,8 @@ class Window {
* Note this emits a closeRequested event so you can intercept it. To force window close, use {@link Window.destroy}.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().close();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().close();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1082,8 +1082,8 @@ class Window {
* Destroys the window. Behaves like {@link Window.close} but forces the window close instead of emitting a closeRequested event.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().destroy();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().destroy();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1098,8 +1098,8 @@ class Window {
* Whether the window should have borders and bars.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setDecorations(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setDecorations(false);
* ```
*
* @param decorations Whether the window should have borders and bars.
@@ -1125,8 +1125,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setShadow(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setShadow(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1162,8 +1162,8 @@ class Window {
* Whether the window should always be on top of other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setAlwaysOnTop(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setAlwaysOnTop(true);
* ```
*
* @param alwaysOnTop Whether the window should always be on top of other windows or not.
@@ -1180,8 +1180,8 @@ class Window {
* Whether the window should always be below other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setAlwaysOnBottom(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setAlwaysOnBottom(true);
* ```
*
* @param alwaysOnBottom Whether the window should always be below other windows or not.
@@ -1198,8 +1198,8 @@ class Window {
* Prevents the window contents from being captured by other apps.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setContentProtected(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setContentProtected(true);
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1215,8 +1215,8 @@ class Window {
* Resizes the window with a new inner size.
* @example
* ```typescript
* import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
* await getCurrent().setSize(new LogicalSize(600, 500));
* import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';
* await getCurrentWindow().setSize(new LogicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size.
@@ -1245,8 +1245,8 @@ class Window {
* Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset.
* @example
* ```typescript
* import { getCurrent, PhysicalSize } from '@tauri-apps/api/window';
* await getCurrent().setMinSize(new PhysicalSize(600, 500));
* import { getCurrentWindow, PhysicalSize } from '@tauri-apps/api/window';
* await getCurrentWindow().setMinSize(new PhysicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size, or `null` to unset the constraint.
@@ -1280,8 +1280,8 @@ class Window {
* Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset.
* @example
* ```typescript
* import { getCurrent, LogicalSize } from '@tauri-apps/api/window';
* await getCurrent().setMaxSize(new LogicalSize(600, 500));
* import { getCurrentWindow, LogicalSize } from '@tauri-apps/api/window';
* await getCurrentWindow().setMaxSize(new LogicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size, or `null` to unset the constraint.
@@ -1315,8 +1315,8 @@ class Window {
* Sets the window outer position.
* @example
* ```typescript
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrent().setPosition(new LogicalPosition(600, 500));
* import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrentWindow().setPosition(new LogicalPosition(600, 500));
* ```
*
* @param position The new position, in logical or physical pixels.
@@ -1350,8 +1350,8 @@ class Window {
* Sets the window fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setFullscreen(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setFullscreen(true);
* ```
*
* @param fullscreen Whether the window should go to fullscreen or not.
@@ -1368,8 +1368,8 @@ class Window {
* Bring the window to front and focus.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setFocus();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setFocus();
* ```
*
* @returns A promise indicating the success or failure of the operation.
@@ -1384,8 +1384,8 @@ class Window {
* Sets the window icon.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setIcon('/tauri/awesome.png');
* 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.
@@ -1415,8 +1415,8 @@ class Window {
* - **macOS:** Unsupported.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setSkipTaskbar(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setSkipTaskbar(true);
* ```
*
* @param skip true to hide window icon, false to show it.
@@ -1441,8 +1441,8 @@ class Window {
* - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setCursorGrab(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setCursorGrab(true);
* ```
*
* @param grab `true` to grab the cursor icon, `false` to release it.
@@ -1465,8 +1465,8 @@ class Window {
* outside of the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setCursorVisible(false);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setCursorVisible(false);
* ```
*
* @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
@@ -1483,8 +1483,8 @@ class Window {
* Modifies the cursor icon of the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setCursorIcon('help');
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setCursorIcon('help');
* ```
*
* @param icon The new cursor icon.
@@ -1501,8 +1501,8 @@ class Window {
* Changes the position of the cursor in window coordinates.
* @example
* ```typescript
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrent().setCursorPosition(new LogicalPosition(600, 300));
* import { getCurrentWindow, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrentWindow().setCursorPosition(new LogicalPosition(600, 300));
* ```
*
* @param position The new cursor position.
@@ -1537,8 +1537,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setIgnoreCursorEvents(true);
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().setIgnoreCursorEvents(true);
* ```
*
* @param ignore `true` to ignore the cursor events; `false` to process them as usual.
@@ -1555,8 +1555,8 @@ class Window {
* Starts dragging the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().startDragging();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().startDragging();
* ```
*
* @return A promise indicating the success or failure of the operation.
@@ -1571,8 +1571,8 @@ class Window {
* Starts resize-dragging the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().startResizeDragging();
* import { getCurrentWindow } from '@tauri-apps/api/window';
* await getCurrentWindow().startResizeDragging();
* ```
*
* @return A promise indicating the success or failure of the operation.
@@ -1594,8 +1594,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
* await getCurrent().setProgressBar({
* import { getCurrentWindow, ProgressBarStatus } from '@tauri-apps/api/window';
* await getCurrentWindow().setProgressBar({
* status: ProgressBarStatus.Normal,
* progress: 50,
* });
@@ -1645,8 +1645,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().onResized(({ payload: size }) => {
* import { getCurrentWindow } from "@tauri-apps/api/window";
* const unlisten = await getCurrentWindow().onResized(({ payload: size }) => {
* console.log('Window resized', size);
* });
*
@@ -1669,8 +1669,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().onMoved(({ payload: position }) => {
* import { getCurrentWindow } from "@tauri-apps/api/window";
* const unlisten = await getCurrentWindow().onMoved(({ payload: position }) => {
* console.log('Window moved', position);
* });
*
@@ -1693,9 +1693,9 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* import { getCurrentWindow } from "@tauri-apps/api/window";
* import { confirm } from '@tauri-apps/api/dialog';
* const unlisten = await getCurrent().onCloseRequested(async (event) => {
* 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
@@ -1730,8 +1730,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/webview";
* const unlisten = await getCurrent().onDragDropEvent((event) => {
* 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') {
@@ -1812,8 +1812,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().onFocusChanged(({ payload: focused }) => {
* import { getCurrentWindow } from "@tauri-apps/api/window";
* const unlisten = await getCurrentWindow().onFocusChanged(({ payload: focused }) => {
* console.log('Focus changed, window is focused? ' + focused);
* });
*
@@ -1852,8 +1852,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().onScaleChanged(({ payload }) => {
* import { getCurrentWindow } from "@tauri-apps/api/window";
* const unlisten = await getCurrentWindow().onScaleChanged(({ payload }) => {
* console.log('Scale changed', payload.scaleFactor, payload.size);
* });
*
@@ -1878,8 +1878,8 @@ class Window {
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().onThemeChanged(({ payload: theme }) => {
* import { getCurrentWindow } from "@tauri-apps/api/window";
* const unlisten = await getCurrentWindow().onThemeChanged(({ payload: theme }) => {
* console.log('New theme: ' + theme);
* });
*
@@ -2304,8 +2304,8 @@ async function cursorPosition(): Promise<PhysicalPosition> {
export {
Window,
CloseRequestedEvent,
getCurrent,
getAll,
getCurrentWindow,
getAllWindows,
LogicalSize,
PhysicalSize,
LogicalPosition,