Files
DeviceManager/node_modules/@tauri-apps/api/event-41a9edf5.d.ts

1492 lines
51 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
type Theme = 'light' | 'dark';
type TitleBarStyle = 'visible' | 'transparent' | 'overlay';
/**
* Allows you to retrieve information about a given monitor.
*
* @since 1.0.0
*/
interface Monitor {
/** Human-readable name of the monitor */
name: string | null;
/** The monitor's resolution. */
size: PhysicalSize;
/** the Top-left corner position of the monitor relative to the larger full screen area. */
position: PhysicalPosition;
/** The scale factor that can be used to map physical pixels to logical pixels. */
scaleFactor: number;
}
/**
* The payload for the `scaleChange` event.
*
* @since 1.0.2
*/
interface ScaleFactorChanged {
/** The new window scale factor. */
scaleFactor: number;
/** The new window size */
size: PhysicalSize;
}
/** The file drop event types. */
type FileDropEvent = {
type: 'hover';
paths: string[];
} | {
type: 'drop';
paths: string[];
} | {
type: 'cancel';
};
/**
* A size represented in logical pixels.
*
* @since 1.0.0
*/
declare class LogicalSize {
type: string;
width: number;
height: number;
constructor(width: number, height: number);
}
/**
* A size represented in physical pixels.
*
* @since 1.0.0
*/
declare class PhysicalSize {
type: string;
width: number;
height: number;
constructor(width: number, height: number);
/**
* Converts the physical size to a logical one.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const factor = await appWindow.scaleFactor();
* const size = await appWindow.innerSize();
* const logical = size.toLogical(factor);
* ```
* */
toLogical(scaleFactor: number): LogicalSize;
}
/**
* A position represented in logical pixels.
*
* @since 1.0.0
*/
declare class LogicalPosition {
type: string;
x: number;
y: number;
constructor(x: number, y: number);
}
/**
* A position represented in physical pixels.
*
* @since 1.0.0
*/
declare class PhysicalPosition {
type: string;
x: number;
y: number;
constructor(x: number, y: number);
/**
* Converts the physical position to a logical one.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const factor = await appWindow.scaleFactor();
* const position = await appWindow.innerPosition();
* const logical = position.toLogical(factor);
* ```
* */
toLogical(scaleFactor: number): LogicalPosition;
}
/** @ignore */
interface WindowDef {
label: string;
}
/** @ignore */
declare global {
interface Window {
__TAURI_METADATA__: {
__windows: WindowDef[];
__currentWindow: WindowDef;
};
}
}
/**
* Attention type to request on a window.
*
* @since 1.0.0
*/
declare enum UserAttentionType {
/**
* #### 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.
*/
Critical = 1,
/**
* #### Platform-specific
* - **macOS:** Bounces the dock icon once.
* - **Windows:** Flashes the taskbar button until the application is in focus.
*/
Informational = 2
}
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';
/**
* Get an instance of `WebviewWindow` for the current webview window.
*
* @since 1.0.0
*/
declare function getCurrent(): WebviewWindow;
/**
* Gets a list of instances of `WebviewWindow` for all available webview windows.
*
* @since 1.0.0
*/
declare function getAll(): WebviewWindow[];
/** @ignore */
type WindowLabel = string;
/**
* A webview window handle allows emitting and listening to events from the backend that are tied to the window.
*
* @ignore
* @since 1.0.0
*/
declare class WebviewWindowHandle {
/** The window label. It is a unique identifier for the window, can be used to reference it later. */
label: WindowLabel;
/** Local event listeners. */
listeners: Record<string, Array<EventCallback<any>>>;
constructor(label: WindowLabel);
/**
* Listen to an event emitted by the backend or webview.
* The event must either be a global event or an event targetting this window.
*
* See {@link WebviewWindow.emit | `emit`} for more information.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const unlisten = await appWindow.listen<string>('state-changed', (event) => {
* console.log(`Got error: ${payload}`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param handler Event handler.
* @returns A promise resolving to a function to unlisten to the event.
*/
listen<T>(event: EventName, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Listen to an one-off event.
* See {@link WebviewWindow.listen | `listen`} for more information.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const unlisten = await appWindow.once<null>('initialized', (event) => {
* console.log(`Window initialized!`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param handler Event handler.
* @returns A promise resolving to a function to unlisten to the event.
*/
once<T>(event: string, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Emits an event to the backend and all Tauri windows.
* The event will have this window's {@link WebviewWindow.label | label} as {@link Event.windowLabel | source window label}.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.emit('window-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* This function can also be used to communicate between windows:
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.listen('sync-data', (event) => { });
*
* // on another window...
* import { WebviewWindow } from '@tauri-apps/api/window';
* const otherWindow = WebviewWindow.getByLabel('other')
* await otherWindow.emit('sync-data');
* ```
*
* Global listeners are also triggered:
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* import { listen } from '@tauri-apps/api/event';
* await listen('ping', (event) => { });
*
* await appWindow.emit('ping');
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param payload Event payload.
*/
emit(event: string, payload?: unknown): Promise<void>;
/** @ignore */
_handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean;
}
/**
* Manage the current window object.
*
* @ignore
* @since 1.0.0
*/
declare class WindowManager extends WebviewWindowHandle {
/**
* The scale factor that can be used to map physical pixels to logical pixels.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const factor = await appWindow.scaleFactor();
* ```
*
* @returns The window's monitor scale factor.
* */
scaleFactor(): Promise<number>;
/**
* 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 { appWindow } from '@tauri-apps/api/window';
* const position = await appWindow.innerPosition();
* ```
*
* @returns The window's inner position.
* */
innerPosition(): Promise<PhysicalPosition>;
/**
* The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const position = await appWindow.outerPosition();
* ```
*
* @returns The window's outer position.
* */
outerPosition(): Promise<PhysicalPosition>;
/**
* The physical size of the window's client area.
* The client area is the content of the window, excluding the title bar and borders.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const size = await appWindow.innerSize();
* ```
*
* @returns The window's inner size.
*/
innerSize(): Promise<PhysicalSize>;
/**
* The physical size of the entire window.
* These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const size = await appWindow.outerSize();
* ```
*
* @returns The window's outer size.
*/
outerSize(): Promise<PhysicalSize>;
/**
* Gets the window's current fullscreen state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const fullscreen = await appWindow.isFullscreen();
* ```
*
* @returns Whether the window is in fullscreen mode or not.
* */
isFullscreen(): Promise<boolean>;
/**
* Gets the window's current minimized state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const minimized = await appWindow.isMinimized();
* ```
*
* @since 1.3.0
* */
isMinimized(): Promise<boolean>;
/**
* Gets the window's current maximized state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const maximized = await appWindow.isMaximized();
* ```
*
* @returns Whether the window is maximized or not.
* */
isMaximized(): Promise<boolean>;
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const focused = await appWindow.isFocused();
* ```
*
* @returns Whether the window is focused or not.
*
* @since 1.4
* */
isFocused(): Promise<boolean>;
/**
* Gets the window's current decorated state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const decorated = await appWindow.isDecorated();
* ```
*
* @returns Whether the window is decorated or not.
* */
isDecorated(): Promise<boolean>;
/**
* Gets the window's current resizable state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const resizable = await appWindow.isResizable();
* ```
*
* @returns Whether the window is resizable or not.
* */
isResizable(): Promise<boolean>;
/**
* Gets the windows native maximize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const maximizable = await appWindow.isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
* */
isMaximizable(): Promise<boolean>;
/**
* Gets the windows native minimize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const minimizable = await appWindow.isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
* */
isMinimizable(): Promise<boolean>;
/**
* Gets the windows native close button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const closable = await appWindow.isClosable();
* ```
*
* @returns Whether the window's native close button is enabled or not.
* */
isClosable(): Promise<boolean>;
/**
* Gets the window's current visible state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const visible = await appWindow.isVisible();
* ```
*
* @returns Whether the window is visible or not.
* */
isVisible(): Promise<boolean>;
/**
* Gets the window's current title.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const title = await appWindow.title();
* ```
*
* @since 1.3.0
* */
title(): Promise<string>;
/**
* Gets the window's current theme.
*
* #### Platform-specific
*
* - **macOS:** Theme was introduced on macOS 10.14. Returns `light` on macOS 10.13 and below.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* const theme = await appWindow.theme();
* ```
*
* @returns The window theme.
* */
theme(): Promise<Theme | null>;
/**
* Centers the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.center();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
center(): Promise<void>;
/**
* Requests user attention to the window, this has no effect if the application
* is already focused. How requesting for user attention manifests is platform dependent,
* see `UserAttentionType` for details.
*
* Providing `null` will unset the request for user attention. Unsetting the request for
* user attention might not be done automatically by the WM when the window receives input.
*
* #### Platform-specific
*
* - **macOS:** `null` has no effect.
* - **Linux:** Urgency levels have the same effect.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.requestUserAttention();
* ```
*
* @param requestType
* @returns A promise indicating the success or failure of the operation.
*/
requestUserAttention(requestType: UserAttentionType | null): Promise<void>;
/**
* Updates the window resizable flag.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setResizable(false);
* ```
*
* @param resizable
* @returns A promise indicating the success or failure of the operation.
*/
setResizable(resizable: boolean): 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.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setMaximizable(false);
* ```
*
* @param maximizable
* @returns A promise indicating the success or failure of the operation.
*/
setMaximizable(maximizable: boolean): Promise<void>;
/**
* Sets whether the window's native minimize button is enabled or not.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setMinimizable(false);
* ```
*
* @param minimizable
* @returns A promise indicating the success or failure of the operation.
*/
setMinimizable(minimizable: boolean): 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.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setClosable(false);
* ```
*
* @param closable
* @returns A promise indicating the success or failure of the operation.
*/
setClosable(closable: boolean): Promise<void>;
/**
* Sets the window title.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setTitle('Tauri');
* ```
*
* @param title The new title
* @returns A promise indicating the success or failure of the operation.
*/
setTitle(title: string): Promise<void>;
/**
* Maximizes the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.maximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
maximize(): Promise<void>;
/**
* Unmaximizes the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.unmaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
unmaximize(): Promise<void>;
/**
* Toggles the window maximized state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.toggleMaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
toggleMaximize(): Promise<void>;
/**
* Minimizes the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.minimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
minimize(): Promise<void>;
/**
* Unminimizes the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.unminimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
unminimize(): Promise<void>;
/**
* Sets the window visibility to true.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.show();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
show(): Promise<void>;
/**
* Sets the window visibility to false.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.hide();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
hide(): Promise<void>;
/**
* Closes the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.close();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
close(): Promise<void>;
/**
* Whether the window should have borders and bars.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setDecorations(false);
* ```
*
* @param decorations Whether the window should have borders and bars.
* @returns A promise indicating the success or failure of the operation.
*/
setDecorations(decorations: boolean): Promise<void>;
/**
* Whether the window should always be on top of other windows.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setAlwaysOnTop(true);
* ```
*
* @param alwaysOnTop Whether the window should always be on top of other windows or not.
* @returns A promise indicating the success or failure of the operation.
*/
setAlwaysOnTop(alwaysOnTop: boolean): Promise<void>;
/**
* Prevents the window contents from being captured by other apps.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setContentProtected(true);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*
* @since 1.2.0
*/
setContentProtected(protected_: boolean): Promise<void>;
/**
* Resizes the window with a new inner size.
* @example
* ```typescript
* import { appWindow, LogicalSize } from '@tauri-apps/api/window';
* await appWindow.setSize(new LogicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size.
* @returns A promise indicating the success or failure of the operation.
*/
setSize(size: LogicalSize | PhysicalSize): Promise<void>;
/**
* Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset.
* @example
* ```typescript
* import { appWindow, PhysicalSize } from '@tauri-apps/api/window';
* await appWindow.setMinSize(new PhysicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size, or `null` to unset the constraint.
* @returns A promise indicating the success or failure of the operation.
*/
setMinSize(size: LogicalSize | PhysicalSize | null | undefined): Promise<void>;
/**
* Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset.
* @example
* ```typescript
* import { appWindow, LogicalSize } from '@tauri-apps/api/window';
* await appWindow.setMaxSize(new LogicalSize(600, 500));
* ```
*
* @param size The logical or physical inner size, or `null` to unset the constraint.
* @returns A promise indicating the success or failure of the operation.
*/
setMaxSize(size: LogicalSize | PhysicalSize | null | undefined): Promise<void>;
/**
* Sets the window outer position.
* @example
* ```typescript
* import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
* await appWindow.setPosition(new LogicalPosition(600, 500));
* ```
*
* @param position The new position, in logical or physical pixels.
* @returns A promise indicating the success or failure of the operation.
*/
setPosition(position: LogicalPosition | PhysicalPosition): Promise<void>;
/**
* Sets the window fullscreen state.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setFullscreen(true);
* ```
*
* @param fullscreen Whether the window should go to fullscreen or not.
* @returns A promise indicating the success or failure of the operation.
*/
setFullscreen(fullscreen: boolean): Promise<void>;
/**
* Bring the window to front and focus.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setFocus();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
setFocus(): Promise<void>;
/**
* Sets the window icon.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setIcon('/tauri/awesome.png');
* ```
*
* Note that you need the `icon-ico` or `icon-png` Cargo features to use this API.
* To enable it, change your Cargo.toml file:
* ```toml
* [dependencies]
* tauri = { version = "...", features = ["...", "icon-png"] }
* ```
*
* @param icon Icon bytes or path to the icon file.
* @returns A promise indicating the success or failure of the operation.
*/
setIcon(icon: string | Uint8Array): Promise<void>;
/**
* Whether the window icon should be hidden from the taskbar or not.
*
* #### Platform-specific
*
* - **macOS:** Unsupported.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setSkipTaskbar(true);
* ```
*
* @param skip true to hide window icon, false to show it.
* @returns A promise indicating the success or failure of the operation.
*/
setSkipTaskbar(skip: boolean): Promise<void>;
/**
* Grabs the cursor, preventing it from leaving the window.
*
* There's no guarantee that the cursor will be hidden. You should
* hide it by yourself if you want so.
*
* #### Platform-specific
*
* - **Linux:** Unsupported.
* - **macOS:** This locks the cursor in a fixed location, which looks visually awkward.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setCursorGrab(true);
* ```
*
* @param grab `true` to grab the cursor icon, `false` to release it.
* @returns A promise indicating the success or failure of the operation.
*/
setCursorGrab(grab: boolean): Promise<void>;
/**
* Modifies the cursor's visibility.
*
* #### Platform-specific
*
* - **Windows:** The cursor is only hidden within the confines of the window.
* - **macOS:** The cursor is hidden as long as the window has input focus, even if the cursor is
* outside of the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setCursorVisible(false);
* ```
*
* @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor.
* @returns A promise indicating the success or failure of the operation.
*/
setCursorVisible(visible: boolean): Promise<void>;
/**
* Modifies the cursor icon of the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setCursorIcon('help');
* ```
*
* @param icon The new cursor icon.
* @returns A promise indicating the success or failure of the operation.
*/
setCursorIcon(icon: CursorIcon): Promise<void>;
/**
* Changes the position of the cursor in window coordinates.
* @example
* ```typescript
* import { appWindow, LogicalPosition } from '@tauri-apps/api/window';
* await appWindow.setCursorPosition(new LogicalPosition(600, 300));
* ```
*
* @param position The new cursor position.
* @returns A promise indicating the success or failure of the operation.
*/
setCursorPosition(position: LogicalPosition | PhysicalPosition): Promise<void>;
/**
* Changes the cursor events behavior.
*
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.setIgnoreCursorEvents(true);
* ```
*
* @param ignore `true` to ignore the cursor events; `false` to process them as usual.
* @returns A promise indicating the success or failure of the operation.
*/
setIgnoreCursorEvents(ignore: boolean): Promise<void>;
/**
* Starts dragging the window.
* @example
* ```typescript
* import { appWindow } from '@tauri-apps/api/window';
* await appWindow.startDragging();
* ```
*
* @return A promise indicating the success or failure of the operation.
*/
startDragging(): Promise<void>;
/**
* Listen to window resize.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onResized(({ payload: size }) => {
* console.log('Window resized', size);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onResized(handler: EventCallback<PhysicalSize>): Promise<UnlistenFn>;
/**
* Listen to window move.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onMoved(({ payload: position }) => {
* console.log('Window moved', position);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onMoved(handler: EventCallback<PhysicalPosition>): Promise<UnlistenFn>;
/**
* Listen to window close requested. Emitted when the user requests to closes the window.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* import { confirm } from '@tauri-apps/api/dialog';
* const unlisten = await appWindow.onCloseRequested(async (event) => {
* const confirmed = await confirm('Are you sure?');
* if (!confirmed) {
* // user did not confirm closing the window; let's prevent it
* event.preventDefault();
* }
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onCloseRequested(handler: (event: CloseRequestedEvent) => void | Promise<void>): Promise<UnlistenFn>;
/**
* Listen to window focus change.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onFocusChanged(({ payload: focused }) => {
* console.log('Focus changed, window is focused? ' + focused);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onFocusChanged(handler: EventCallback<boolean>): Promise<UnlistenFn>;
/**
* Listen to window scale change. Emitted when the window's scale factor has changed.
* The following user actions can cause DPI changes:
* - Changing the display's resolution.
* - Changing the display's scale factor (e.g. in Control Panel on Windows).
* - Moving the window to a display with a different scale factor.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onScaleChanged(({ payload }) => {
* console.log('Scale changed', payload.scaleFactor, payload.size);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onScaleChanged(handler: EventCallback<ScaleFactorChanged>): Promise<UnlistenFn>;
/**
* Listen to the window menu item click. The payload is the item id.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onMenuClicked(({ payload: menuId }) => {
* console.log('Menu clicked: ' + menuId);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onMenuClicked(handler: EventCallback<string>): Promise<UnlistenFn>;
/**
* Listen to a file drop event.
* The listener is triggered when the user hovers the selected files on the window,
* drops the files or cancels the operation.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onFileDropEvent((event) => {
* if (event.payload.type === 'hover') {
* console.log('User hovering', event.payload.paths);
* } else if (event.payload.type === 'drop') {
* console.log('User dropped', event.payload.paths);
* } else {
* console.log('File drop cancelled');
* }
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onFileDropEvent(handler: EventCallback<FileDropEvent>): Promise<UnlistenFn>;
/**
* Listen to the system theme change.
*
* @example
* ```typescript
* import { appWindow } from "@tauri-apps/api/window";
* const unlisten = await appWindow.onThemeChanged(({ payload: theme }) => {
* console.log('New theme: ' + theme);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @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.
*
* @since 1.0.2
*/
onThemeChanged(handler: EventCallback<Theme>): Promise<UnlistenFn>;
}
/**
* @since 1.0.2
*/
declare class CloseRequestedEvent {
/** Event name */
event: EventName;
/** The label of the window that emitted this event. */
windowLabel: string;
/** Event identifier used to unlisten */
id: number;
private _preventDefault;
constructor(event: Event<null>);
preventDefault(): void;
isPreventDefault(): boolean;
}
/**
* Create new webview windows and get a handle to existing ones.
*
* Windows are identified by a *label* a unique identifier that can be used to reference it later.
* It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
*
* @example
* ```typescript
* // loading embedded asset:
* const webview = new WebviewWindow('theUniqueLabel', {
* url: 'path/to/page.html'
* });
* // alternatively, load a remote URL:
* const webview = new WebviewWindow('theUniqueLabel', {
* url: 'https://github.com/tauri-apps/tauri'
* });
*
* webview.once('tauri://created', function () {
* // webview window successfully created
* });
* webview.once('tauri://error', function (e) {
* // an error happened creating the webview window
* });
*
* // emit an event to the backend
* await webview.emit("some event", "data");
* // listen to an event from the backend
* const unlisten = await webview.listen("event name", e => {});
* unlisten();
* ```
*
* @since 1.0.2
*/
declare class WebviewWindow extends WindowManager {
/**
* Creates a new WebviewWindow.
* @example
* ```typescript
* import { WebviewWindow } from '@tauri-apps/api/window';
* const webview = new WebviewWindow('my-label', {
* url: 'https://github.com/tauri-apps/tauri'
* });
* webview.once('tauri://created', function () {
* // webview window successfully created
* });
* webview.once('tauri://error', function (e) {
* // an error happened creating the webview window
* });
* ```
*
* * @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`.
* @returns The WebviewWindow instance to communicate with the webview.
*/
constructor(label: WindowLabel, options?: WindowOptions);
/**
* Gets the WebviewWindow for the webview associated with the given label.
* @example
* ```typescript
* import { WebviewWindow } from '@tauri-apps/api/window';
* const mainWindow = WebviewWindow.getByLabel('main');
* ```
*
* @param label The webview window label.
* @returns The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist.
*/
static getByLabel(label: string): WebviewWindow | null;
/**
* Gets the focused window.
* @example
* ```typescript
* import { WebviewWindow } from '@tauri-apps/api/window';
* const focusedWindow = WebviewWindow.getFocusedWindow();
* ```
*
* @returns The WebviewWindow instance to communicate with the webview or `undefined` if there is not any focused window.
*
* @since 1.4
*/
static getFocusedWindow(): Promise<WebviewWindow | null>;
}
/** The WebviewWindow for the current window. */
declare let appWindow: WebviewWindow;
/**
* Configuration for the window to create.
*
* @since 1.0.0
*/
interface WindowOptions {
/**
* Remote URL or local file path to open.
*
* - URL such as `https://github.com/tauri-apps` is opened directly on a Tauri window.
* - data: URL such as `data:text/html,<html>...` is only supported with the `window-data-url` Cargo feature for the `tauri` dependency.
* - local file path or route such as `/path/to/page.html` or `/users` is appended to the application URL (the devServer URL on development, or `tauri://localhost/` and `https://tauri.localhost/` on production).
*/
url?: string;
/** Show window in the center of the screen.. */
center?: boolean;
/** The initial vertical position. Only applies if `y` is also set. */
x?: number;
/** The initial horizontal position. Only applies if `x` is also set. */
y?: number;
/** The initial width. */
width?: number;
/** The initial height. */
height?: number;
/** The minimum width. Only applies if `minHeight` is also set. */
minWidth?: number;
/** The minimum height. Only applies if `minWidth` is also set. */
minHeight?: number;
/** The maximum width. Only applies if `maxHeight` is also set. */
maxWidth?: number;
/** The maximum height. Only applies if `maxWidth` is also set. */
maxHeight?: number;
/** Whether the window is resizable or not. */
resizable?: boolean;
/** Window title. */
title?: string;
/** Whether the window is in fullscreen mode or not. */
fullscreen?: boolean;
/** Whether the window will be initially focused or not. */
focus?: boolean;
/**
* Whether the window is transparent or not.
* Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri.conf.json > tauri > macOSPrivateApi`.
* WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`.
*/
transparent?: boolean;
/** Whether the window should be maximized upon creation or not. */
maximized?: boolean;
/** Whether the window should be immediately visible upon creation or not. */
visible?: boolean;
/** Whether the window should have borders and bars or not. */
decorations?: boolean;
/** Whether the window should always be on top of other windows or not. */
alwaysOnTop?: boolean;
/** Prevents the window contents from being captured by other apps. */
contentProtected?: boolean;
/** Whether or not the window icon should be added to the taskbar. */
skipTaskbar?: boolean;
/**
* Whether the file drop is enabled or not on the webview. By default it is enabled.
*
* Disabling it is required to use drag and drop on the frontend on Windows.
*/
fileDropEnabled?: boolean;
/**
* The initial window theme. Defaults to the system theme.
*
* Only implemented on Windows and macOS 10.14+.
*/
theme?: Theme;
/**
* The style of the macOS title bar.
*/
titleBarStyle?: TitleBarStyle;
/**
* If `true`, sets the window title to be hidden on macOS.
*/
hiddenTitle?: boolean;
/**
* Whether clicking an inactive window also clicks through to the webview on macOS.
*/
acceptFirstMouse?: boolean;
/**
* Defines the window [tabbing identifier](https://developer.apple.com/documentation/appkit/nswindow/1644704-tabbingidentifier) on macOS.
*
* Windows with the same tabbing identifier will be grouped together.
* If the tabbing identifier is not set, automatic tabbing will be disabled.
*/
tabbingIdentifier?: string;
/**
* The user agent for the webview.
*/
userAgent?: string;
/**
* Whether the window's native maximize button is enabled or not. Defaults to `true`.
*/
maximizable?: boolean;
/**
* Whether the window's native minimize button is enabled or not. Defaults to `true`.
*/
minimizable?: boolean;
/**
* Whether the window's native close button is enabled or not. Defaults to `true`.
*/
closable?: boolean;
}
/**
* Returns the monitor on which the window currently resides.
* Returns `null` if current monitor can't be detected.
* @example
* ```typescript
* import { currentMonitor } from '@tauri-apps/api/window';
* const monitor = currentMonitor();
* ```
*
* @since 1.0.0
*/
declare function currentMonitor(): Promise<Monitor | null>;
/**
* Returns the primary monitor of the system.
* Returns `null` if it can't identify any monitor as a primary one.
* @example
* ```typescript
* import { primaryMonitor } from '@tauri-apps/api/window';
* const monitor = primaryMonitor();
* ```
*
* @since 1.0.0
*/
declare function primaryMonitor(): Promise<Monitor | null>;
/**
* Returns the list of all the monitors available on the system.
* @example
* ```typescript
* import { availableMonitors } from '@tauri-apps/api/window';
* const monitors = availableMonitors();
* ```
*
* @since 1.0.0
*/
declare function availableMonitors(): Promise<Monitor[]>;
type window_WebviewWindow = WebviewWindow;
declare const window_WebviewWindow: typeof WebviewWindow;
type window_WebviewWindowHandle = WebviewWindowHandle;
declare const window_WebviewWindowHandle: typeof WebviewWindowHandle;
type window_WindowManager = WindowManager;
declare const window_WindowManager: typeof WindowManager;
type window_CloseRequestedEvent = CloseRequestedEvent;
declare const window_CloseRequestedEvent: typeof CloseRequestedEvent;
declare const window_getCurrent: typeof getCurrent;
declare const window_getAll: typeof getAll;
declare const window_appWindow: typeof appWindow;
type window_LogicalSize = LogicalSize;
declare const window_LogicalSize: typeof LogicalSize;
type window_PhysicalSize = PhysicalSize;
declare const window_PhysicalSize: typeof PhysicalSize;
type window_LogicalPosition = LogicalPosition;
declare const window_LogicalPosition: typeof LogicalPosition;
type window_PhysicalPosition = PhysicalPosition;
declare const window_PhysicalPosition: typeof PhysicalPosition;
type window_UserAttentionType = UserAttentionType;
declare const window_UserAttentionType: typeof UserAttentionType;
declare const window_currentMonitor: typeof currentMonitor;
declare const window_primaryMonitor: typeof primaryMonitor;
declare const window_availableMonitors: typeof availableMonitors;
type window_Theme = Theme;
type window_TitleBarStyle = TitleBarStyle;
type window_Monitor = Monitor;
type window_ScaleFactorChanged = ScaleFactorChanged;
type window_FileDropEvent = FileDropEvent;
type window_WindowOptions = WindowOptions;
type window_CursorIcon = CursorIcon;
type window_WindowLabel = WindowLabel;
declare namespace window {
export {
window_WebviewWindow as WebviewWindow,
window_WebviewWindowHandle as WebviewWindowHandle,
window_WindowManager as WindowManager,
window_CloseRequestedEvent as CloseRequestedEvent,
window_getCurrent as getCurrent,
window_getAll as getAll,
window_appWindow as appWindow,
window_LogicalSize as LogicalSize,
window_PhysicalSize as PhysicalSize,
window_LogicalPosition as LogicalPosition,
window_PhysicalPosition as PhysicalPosition,
window_UserAttentionType as UserAttentionType,
window_currentMonitor as currentMonitor,
window_primaryMonitor as primaryMonitor,
window_availableMonitors as availableMonitors,
window_Theme as Theme,
window_TitleBarStyle as TitleBarStyle,
window_Monitor as Monitor,
window_ScaleFactorChanged as ScaleFactorChanged,
window_FileDropEvent as FileDropEvent,
window_WindowOptions as WindowOptions,
window_CursorIcon as CursorIcon,
window_WindowLabel as WindowLabel,
};
}
interface Event<T> {
/** Event name */
event: EventName;
/** The label of the window that emitted this event. */
windowLabel: string;
/** Event identifier used to unlisten */
id: number;
/** Event payload */
payload: T;
}
type EventCallback<T> = (event: Event<T>) => void;
type UnlistenFn = () => void;
type EventName = `${TauriEvent}` | (string & Record<never, never>);
/**
* @since 1.1.0
*/
declare enum TauriEvent {
WINDOW_RESIZED = "tauri://resize",
WINDOW_MOVED = "tauri://move",
WINDOW_CLOSE_REQUESTED = "tauri://close-requested",
WINDOW_CREATED = "tauri://window-created",
WINDOW_DESTROYED = "tauri://destroyed",
WINDOW_FOCUS = "tauri://focus",
WINDOW_BLUR = "tauri://blur",
WINDOW_SCALE_FACTOR_CHANGED = "tauri://scale-change",
WINDOW_THEME_CHANGED = "tauri://theme-changed",
WINDOW_FILE_DROP = "tauri://file-drop",
WINDOW_FILE_DROP_HOVER = "tauri://file-drop-hover",
WINDOW_FILE_DROP_CANCELLED = "tauri://file-drop-cancelled",
MENU = "tauri://menu",
CHECK_UPDATE = "tauri://update",
UPDATE_AVAILABLE = "tauri://update-available",
INSTALL_UPDATE = "tauri://update-install",
STATUS_UPDATE = "tauri://update-status",
DOWNLOAD_PROGRESS = "tauri://update-download-progress"
}
/**
* Listen to an event. The event can be either global or window-specific.
* See {@link Event.windowLabel} to check the event source.
*
* @example
* ```typescript
* import { listen } from '@tauri-apps/api/event';
* const unlisten = await listen<string>('error', (event) => {
* console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param handler Event handler callback.
* @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.
*
* @since 1.0.0
*/
declare function listen<T>(event: EventName, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Listen to an one-off event. See {@link listen} for more information.
*
* @example
* ```typescript
* import { once } from '@tauri-apps/api/event';
* interface LoadedPayload {
* loggedIn: boolean,
* token: string
* }
* const unlisten = await once<LoadedPayload>('loaded', (event) => {
* console.log(`App is loaded, loggedIn: ${event.payload.loggedIn}, token: ${event.payload.token}`);
* });
*
* // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted
* unlisten();
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @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.
*
* @since 1.0.0
*/
declare function once<T>(event: EventName, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Emits an event to the backend and all Tauri windows.
* @example
* ```typescript
* import { emit } from '@tauri-apps/api/event';
* await emit('frontend-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
*
* @since 1.0.0
*/
declare function emit(event: string, payload?: unknown): Promise<void>;
type event_Event<T> = Event<T>;
type event_EventCallback<T> = EventCallback<T>;
type event_UnlistenFn = UnlistenFn;
declare const event_listen: typeof listen;
declare const event_once: typeof once;
declare const event_emit: typeof emit;
type event_EventName = EventName;
type event_TauriEvent = TauriEvent;
declare const event_TauriEvent: typeof TauriEvent;
declare namespace event {
export {
event_Event as Event,
event_EventCallback as EventCallback,
event_UnlistenFn as UnlistenFn,
event_listen as listen,
event_once as once,
event_emit as emit,
event_EventName as EventName,
event_TauriEvent as TauriEvent,
};
}
export { CloseRequestedEvent as C, Event as E, FileDropEvent as F, LogicalSize as L, Monitor as M, PhysicalSize as P, ScaleFactorChanged as S, Theme as T, UnlistenFn as U, WebviewWindow as W, WebviewWindowHandle as a, WindowManager as b, getAll as c, appWindow as d, event as e, LogicalPosition as f, getCurrent as g, PhysicalPosition as h, UserAttentionType as i, currentMonitor as j, availableMonitors as k, TitleBarStyle as l, WindowOptions as m, CursorIcon as n, WindowLabel as o, primaryMonitor as p, EventCallback as q, listen as r, once as s, emit as t, EventName as u, TauriEvent as v, window as w };