Socket
Socket
Sign inDemoInstall

@tauri-apps/api

Package Overview
Dependencies
Maintainers
5
Versions
75
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tauri-apps/api - npm Package Compare versions

Comparing version 2.0.0-alpha.9 to 2.0.0-alpha.10

65

app.d.ts

@@ -1,1 +0,64 @@

export { g as getName, c as getTauriVersion, b as getVersion, h as hide, s as show } from './app-d81a8ac4.js';
/**
* Application metadata and related APIs.
*
* @module
*/
/**
* Gets the application version.
* @example
* ```typescript
* import { getVersion } from '@tauri-apps/api/app';
* const appVersion = await getVersion();
* ```
*
* @since 1.0.0
*/
declare function getVersion(): Promise<string>;
/**
* Gets the application name.
* @example
* ```typescript
* import { getName } from '@tauri-apps/api/app';
* const appName = await getName();
* ```
*
* @since 1.0.0
*/
declare function getName(): Promise<string>;
/**
* Gets the Tauri version.
*
* @example
* ```typescript
* import { getTauriVersion } from '@tauri-apps/api/app';
* const tauriVersion = await getTauriVersion();
* ```
*
* @since 1.0.0
*/
declare function getTauriVersion(): Promise<string>;
/**
* Shows the application on macOS. This function does not automatically focus any specific app window.
*
* @example
* ```typescript
* import { show } from '@tauri-apps/api/app';
* await show();
* ```
*
* @since 1.2.0
*/
declare function show(): Promise<void>;
/**
* Hides the application on macOS.
*
* @example
* ```typescript
* import { hide } from '@tauri-apps/api/app';
* await hide();
* ```
*
* @since 1.2.0
*/
declare function hide(): Promise<void>;
export { getName, getVersion, getTauriVersion, show, hide };

@@ -1,1 +0,80 @@

import{a,b,c,d,e}from"./chunk-KXWJIJYO.js";import"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{b as getName,c as getTauriVersion,a as getVersion,e as hide,d as show};
import { invoke } from './primitives.js';
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Application metadata and related APIs.
*
* @module
*/
/**
* Gets the application version.
* @example
* ```typescript
* import { getVersion } from '@tauri-apps/api/app';
* const appVersion = await getVersion();
* ```
*
* @since 1.0.0
*/
async function getVersion() {
return invoke('plugin:app|version');
}
/**
* Gets the application name.
* @example
* ```typescript
* import { getName } from '@tauri-apps/api/app';
* const appName = await getName();
* ```
*
* @since 1.0.0
*/
async function getName() {
return invoke('plugin:app|name');
}
/**
* Gets the Tauri version.
*
* @example
* ```typescript
* import { getTauriVersion } from '@tauri-apps/api/app';
* const tauriVersion = await getTauriVersion();
* ```
*
* @since 1.0.0
*/
async function getTauriVersion() {
return invoke('plugin:app|tauri_version');
}
/**
* Shows the application on macOS. This function does not automatically focus any specific app window.
*
* @example
* ```typescript
* import { show } from '@tauri-apps/api/app';
* await show();
* ```
*
* @since 1.2.0
*/
async function show() {
return invoke('plugin:app|app_show');
}
/**
* Hides the application on macOS.
*
* @example
* ```typescript
* import { hide } from '@tauri-apps/api/app';
* await hide();
* ```
*
* @since 1.2.0
*/
async function hide() {
return invoke('plugin:app|app_hide');
}
export { getName, getTauriVersion, getVersion, hide, show };
# Changelog
## \[2.0.0-alpha.10]
### Enhancements
- [`c6c59cf2`](https://www.github.com/tauri-apps/tauri/commit/c6c59cf2373258b626b00a26f4de4331765dd487) Pull changes from Tauri 1.5 release.
### Bug Fixes
- [`287066b2`](https://www.github.com/tauri-apps/tauri/commit/287066b279f503dd09bfd43d5da37d1f471451fb)([#8071](https://www.github.com/tauri-apps/tauri/pull/8071)) No longer crashing in tests without mocks when `clearMocks` is defined in `afterEach` hook.
## \[2.0.0-alpha.9]

@@ -90,2 +100,22 @@

## \[1.5.1]
### New Features
- [`2b0212af`](https://www.github.com/tauri-apps/tauri/commit/2b0212af49c386e52bb2357381813d6d435ec4af)([#7961](https://www.github.com/tauri-apps/tauri/pull/7961)) Add `mockConvertFileSrc` in `mocks` module, to mock `convertFileSrc` function.
## \[1.5.0]
### New Features
- [`6c408b73`](https://www.github.com/tauri-apps/tauri/commit/6c408b736c7aa2a0a91f0a40d45a2b7a7dedfe78)([#7269](https://www.github.com/tauri-apps/tauri/pull/7269)) Add option to specify notification sound.
### Enhancements
- [`58d6b899`](https://www.github.com/tauri-apps/tauri/commit/58d6b899e21d37bb42810890d289deb57f2273bd)([#7636](https://www.github.com/tauri-apps/tauri/pull/7636)) Add `append` option to `FsOptions` in the `fs` JS module, used in `writeTextFile` and `writeBinaryFile`, to be able to append to existing files instead of overwriting it.
### Bug Fixes
- [`2eab1505`](https://www.github.com/tauri-apps/tauri/commit/2eab1505632ff71431d4c31c49b5afc78fa5b9dd)([#7394](https://www.github.com/tauri-apps/tauri/pull/7394)) Fix `Body.form` static not reading and sending entries of type `Blob` (including subclasses such as `File`)
## \[1.4.0]

@@ -92,0 +122,0 @@

@@ -1,1 +0,69 @@

export { b as LogicalPosition, L as LogicalSize, a as PhysicalPosition, P as PhysicalSize } from './dpi-1b9c86cc.js';
/**
* A size represented in logical pixels.
*
* @since 2.0.0
*/
declare class LogicalSize {
type: string;
width: number;
height: number;
constructor(width: number, height: number);
}
/**
* A size represented in physical pixels.
*
* @since 2.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 { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* 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 2.0.0
*/
declare class LogicalPosition {
type: string;
x: number;
y: number;
constructor(x: number, y: number);
}
/**
* A position represented in physical pixels.
*
* @since 2.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 { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* const factor = await appWindow.scaleFactor();
* const position = await appWindow.innerPosition();
* const logical = position.toLogical(factor);
* ```
* */
toLogical(scaleFactor: number): LogicalPosition;
}
export { LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize };

@@ -1,1 +0,81 @@

import{a,b,c,d}from"./chunk-24ATAN64.js";import"./chunk-NDS2DDJC.js";export{c as LogicalPosition,a as LogicalSize,d as PhysicalPosition,b as PhysicalSize};
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* A size represented in logical pixels.
*
* @since 2.0.0
*/
class LogicalSize {
constructor(width, height) {
this.type = 'Logical';
this.width = width;
this.height = height;
}
}
/**
* A size represented in physical pixels.
*
* @since 2.0.0
*/
class PhysicalSize {
constructor(width, height) {
this.type = 'Physical';
this.width = width;
this.height = height;
}
/**
* Converts the physical size to a logical one.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* const factor = await appWindow.scaleFactor();
* const size = await appWindow.innerSize();
* const logical = size.toLogical(factor);
* ```
* */
toLogical(scaleFactor) {
return new LogicalSize(this.width / scaleFactor, this.height / scaleFactor);
}
}
/**
* A position represented in logical pixels.
*
* @since 2.0.0
*/
class LogicalPosition {
constructor(x, y) {
this.type = 'Logical';
this.x = x;
this.y = y;
}
}
/**
* A position represented in physical pixels.
*
* @since 2.0.0
*/
class PhysicalPosition {
constructor(x, y) {
this.type = 'Physical';
this.x = x;
this.y = y;
}
/**
* Converts the physical position to a logical one.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const appWindow = getCurrent();
* const factor = await appWindow.scaleFactor();
* const position = await appWindow.innerPosition();
* const logical = position.toLogical(factor);
* ```
* */
toLogical(scaleFactor) {
return new LogicalPosition(this.x / scaleFactor, this.y / scaleFactor);
}
}
export { LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize };

@@ -1,1 +0,105 @@

export { a as Event, b as EventCallback, E as EventName, O as Options, T as TauriEvent, U as UnlistenFn, c as emit, l as listen, o as once } from './event-bdc5d2c8.js';
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>);
interface Options {
/**
* Label of the window the function targets.
*
* When listening to events and using this value,
* only events triggered by the window with the given label are received.
*
* When emitting events, only the window with the given label will receive it.
*/
target?: string;
}
/**
* @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"
}
/**
* 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>, options?: Options): 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>, options?: Options): 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, options?: Options): Promise<void>;
export type { Event, EventCallback, UnlistenFn, EventName, Options };
export { listen, once, emit, TauriEvent };

@@ -1,1 +0,126 @@

import{a,b,c,d}from"./chunk-AFSYT2WA.js";import"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{a as TauriEvent,d as emit,b as listen,c as once};
import { invoke, transformCallback } from './primitives.js';
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* The event system allows you to emit events to the backend and listen to events from it.
*
* This package is also accessible with `window.__TAURI__.event` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
* @module
*/
/**
* @since 1.1.0
*/
var TauriEvent;
(function (TauriEvent) {
TauriEvent["WINDOW_RESIZED"] = "tauri://resize";
TauriEvent["WINDOW_MOVED"] = "tauri://move";
TauriEvent["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested";
TauriEvent["WINDOW_CREATED"] = "tauri://window-created";
TauriEvent["WINDOW_DESTROYED"] = "tauri://destroyed";
TauriEvent["WINDOW_FOCUS"] = "tauri://focus";
TauriEvent["WINDOW_BLUR"] = "tauri://blur";
TauriEvent["WINDOW_SCALE_FACTOR_CHANGED"] = "tauri://scale-change";
TauriEvent["WINDOW_THEME_CHANGED"] = "tauri://theme-changed";
TauriEvent["WINDOW_FILE_DROP"] = "tauri://file-drop";
TauriEvent["WINDOW_FILE_DROP_HOVER"] = "tauri://file-drop-hover";
TauriEvent["WINDOW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled";
TauriEvent["MENU"] = "tauri://menu";
})(TauriEvent || (TauriEvent = {}));
/**
* Unregister the event listener associated with the given name and id.
*
* @ignore
* @param event The event name
* @param eventId Event identifier
* @returns
*/
async function _unlisten(event, eventId) {
await invoke('plugin:event|unlisten', {
event,
eventId
});
}
/**
* 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
*/
async function listen(event, handler, options) {
return invoke('plugin:event|listen', {
event,
windowLabel: options?.target,
handler: transformCallback(handler)
}).then((eventId) => {
return async () => _unlisten(event, eventId);
});
}
/**
* 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
*/
async function once(event, handler, options) {
return listen(event, (eventData) => {
handler(eventData);
_unlisten(event, eventData.id).catch(() => { });
}, options);
}
/**
* 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
*/
async function emit(event, payload, options) {
await invoke('plugin:event|emit', {
event,
windowLabel: options?.target,
payload
});
}
export { TauriEvent, emit, listen, once };

23

index.d.ts

@@ -1,6 +0,17 @@

export { a as app } from './app-d81a8ac4.js';
export { e as event } from './event-bdc5d2c8.js';
export { p as primitives } from './primitives-742a88b2.js';
export { w as window } from './window-e99b5597.js';
export { p as path } from './path-9694881f.js';
export { d as dpi } from './dpi-1b9c86cc.js';
/**
* The Tauri API allows you to interface with the backend layer.
*
* This module exposes all other modules as an object where the key is the module name, and the value is the module exports.
* @example
* ```typescript
* import { event, window, path } from '@tauri-apps/api'
* ```
* @module
*/
import * as app from './app';
import * as event from './event';
import * as primitives from './primitives';
import * as window from './window';
import * as path from './path';
import * as dpi from './dpi';
export { app, dpi, event, path, primitives, window };

@@ -1,1 +0,12 @@

import{l as i}from"./chunk-5MN3W4J2.js";import{f as r}from"./chunk-KXWJIJYO.js";import{e as m}from"./chunk-24ATAN64.js";import{e as p}from"./chunk-AFSYT2WA.js";import{I as t}from"./chunk-UPUVCPZK.js";import{g as o}from"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{r as app,m as dpi,p as event,t as path,o as primitives,i as window};
import * as app from './app.js';
export { app };
import * as event from './event.js';
export { event };
import * as primitives from './primitives.js';
export { primitives };
import * as window from './window.js';
export { window };
import * as path from './path.js';
export { path };
import * as dpi from './dpi.js';
export { dpi };

@@ -54,3 +54,3 @@ /**

*/
declare function mockIPC(cb: (cmd: string, payload: Record<string, unknown>) => unknown): void;
export declare function mockIPC(cb: (cmd: string, payload: Record<string, unknown>) => unknown): void;
/**

@@ -96,4 +96,23 @@ * Mocks one or many window labels.

*/
declare function mockWindows(current: string, ...additionalWindows: string[]): void;
export declare function mockWindows(current: string, ...additionalWindows: string[]): void;
/**
* Mock `convertFileSrc` function
*
*
* @example
* ```js
* import { mockConvertFileSrc } from "@tauri-apps/api/mocks";
* import { convertFileSrc } from "@tauri-apps/api/primitives";
*
* mockConvertFileSrc("windows")
*
* const url = convertFileSrc("C:\\Users\\user\\file.txt")
* ```
*
* @param osName The operating system to mock, can be one of linux, macos, or windows
*
* @since 1.6.0
*/
export declare function mockConvertFileSrc(osName: string): void;
/**
* Clears mocked functions/data injected by the other functions in this module.

@@ -124,4 +143,2 @@ * When using a test runner that doesn't provide a fresh window object for each test, calling this function will reset tauri specific properties.

*/
declare function clearMocks(): void;
export { clearMocks, mockIPC, mockWindows };
export declare function clearMocks(): void;

@@ -1,1 +0,183 @@

import"./chunk-NDS2DDJC.js";function a(n){window.__TAURI_INTERNALS__.ipc=async({cmd:o,callback:e,error:i,payload:t})=>{try{window[`_${e}`](await n(o,t))}catch(_){window[`_${i}`](_)}}}function d(n,...o){window.__TAURI_INTERNALS__.metadata={windows:[n,...o].map(e=>({label:e})),currentWindow:{label:n}}}function r(){delete window.__TAURI_INTERNALS__.ipc,delete window.__TAURI_INTERNALS__.metadata}export{r as clearMocks,a as mockIPC,d as mockWindows};
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Intercepts all IPC requests with the given mock handler.
*
* This function can be used when testing tauri frontend applications or when running the frontend in a Node.js context during static site generation.
*
* # Examples
*
* Testing setup using vitest:
* ```js
* import { mockIPC, clearMocks } from "@tauri-apps/api/mocks"
* import { invoke } from "@tauri-apps/api/primitives"
*
* afterEach(() => {
* clearMocks()
* })
*
* test("mocked command", () => {
* mockIPC((cmd, payload) => {
* switch (cmd) {
* case "add":
* return (payload.a as number) + (payload.b as number);
* default:
* break;
* }
* });
*
* expect(invoke('add', { a: 12, b: 15 })).resolves.toBe(27);
* })
* ```
*
* The callback function can also return a Promise:
* ```js
* import { mockIPC, clearMocks } from "@tauri-apps/api/mocks"
* import { invoke } from "@tauri-apps/api/primitives"
*
* afterEach(() => {
* clearMocks()
* })
*
* test("mocked command", () => {
* mockIPC((cmd, payload) => {
* if(cmd === "get_data") {
* return fetch("https://example.com/data.json")
* .then((response) => response.json())
* }
* });
*
* expect(invoke('get_data')).resolves.toBe({ foo: 'bar' });
* })
* ```
*
* @since 1.0.0
*/
function mockIPC(cb) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
window.__TAURI_INTERNALS__.ipc = async ({ cmd, callback, error, payload }) => {
try {
// @ts-expect-error The function key is dynamic and therefore not typed
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
window[`_${callback}`](await cb(cmd, payload));
}
catch (err) {
// @ts-expect-error The function key is dynamic and therefore not typed
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
window[`_${error}`](err);
}
};
}
/**
* Mocks one or many window labels.
* In non-tauri context it is required to call this function *before* using the `@tauri-apps/api/window` module.
*
* This function only mocks the *presence* of windows,
* window properties (e.g. width and height) can be mocked like regular IPC calls using the `mockIPC` function.
*
* # Examples
*
* ```js
* import { mockWindows } from "@tauri-apps/api/mocks";
* import { getCurrent } from "@tauri-apps/api/window";
*
* mockWindows("main", "second", "third");
*
* const win = getCurrent();
*
* win.label // "main"
* ```
*
* ```js
* import { mockWindows } from "@tauri-apps/api/mocks";
*
* mockWindows("main", "second", "third");
*
* mockIPC((cmd, args) => {
* if (cmd === "plugin:event|emit") {
* console.log('emit event', args?.event, args?.payload);
* }
* });
*
* const { emit } = await import("@tauri-apps/api/event");
* await emit('loaded'); // this will cause the mocked IPC handler to log to the console.
* ```
*
* @param current Label of window this JavaScript context is running in.
* @param additionalWindows Label of additional windows the app has.
*
* @since 1.0.0
*/
function mockWindows(current, ...additionalWindows) {
window.__TAURI_INTERNALS__.metadata = {
windows: [current, ...additionalWindows].map((label) => ({ label })),
currentWindow: { label: current }
};
}
/**
* Mock `convertFileSrc` function
*
*
* @example
* ```js
* import { mockConvertFileSrc } from "@tauri-apps/api/mocks";
* import { convertFileSrc } from "@tauri-apps/api/primitives";
*
* mockConvertFileSrc("windows")
*
* const url = convertFileSrc("C:\\Users\\user\\file.txt")
* ```
*
* @param osName The operating system to mock, can be one of linux, macos, or windows
*
* @since 1.6.0
*/
function mockConvertFileSrc(osName) {
window.__TAURI_INTERNALS__ = window.__TAURI_INTERNALS__ ?? {};
window.__TAURI_INTERNALS__.convertFileSrc = function (filePath, protocol = 'asset') {
const path = encodeURIComponent(filePath);
return osName === 'windows'
? `http://${protocol}.localhost/${path}`
: `${protocol}://localhost/${path}`;
};
}
/**
* Clears mocked functions/data injected by the other functions in this module.
* When using a test runner that doesn't provide a fresh window object for each test, calling this function will reset tauri specific properties.
*
* # Example
*
* ```js
* import { mockWindows, clearMocks } from "@tauri-apps/api/mocks"
*
* afterEach(() => {
* clearMocks()
* })
*
* test("mocked windows", () => {
* mockWindows("main", "second", "third");
*
* expect(window.__TAURI_INTERNALS__).toHaveProperty("metadata")
* })
*
* test("no mocked windows", () => {
* expect(window.__TAURI_INTERNALS__).not.toHaveProperty("metadata")
* })
* ```
*
* @since 1.0.0
*/
function clearMocks() {
if (typeof window.__TAURI_INTERNALS__ !== 'object') {
return;
}
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI_INTERNALS__.convertFileSrc;
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI_INTERNALS__.ipc;
// @ts-expect-error "The operand of a 'delete' operator must be optional' does not matter in this case
delete window.__TAURI_INTERNALS__.metadata;
}
export { clearMocks, mockConvertFileSrc, mockIPC, mockWindows };
{
"name": "@tauri-apps/api",
"version": "2.0.0-alpha.9",
"version": "2.0.0-alpha.10",
"description": "Tauri API definitions",
"type": "module",
"funding": {

@@ -10,2 +9,26 @@ "type": "opencollective",

},
"repository": {
"type": "git",
"url": "git+https://github.com/tauri-apps/tauri.git"
},
"contributors": [
"Tauri Programme within The Commons Conservancy"
],
"license": "Apache-2.0 OR MIT",
"bugs": {
"url": "https://github.com/tauri-apps/tauri/issues"
},
"homepage": "https://github.com/tauri-apps/tauri#readme",
"type": "module",
"scripts": {
"build": "yarn rollup --config rollup.config.ts --configPlugin typescript",
"npm-pack": "yarn build && cd ./dist && npm pack",
"npm-publish": "yarn build && cd ./dist && yarn publish --access public --loglevel silly --tag next",
"check": "tsc",
"lint": "eslint --ext ts \"./src/**/*.ts\"",
"lint:fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
"format": "prettier --write . --config ../../.prettierrc --ignore-path .gitignore --ignore-path ../../.prettierignore",
"format:check": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore --ignore-path ../../.prettierignore"
},
"devDependencies": {},
"exports": {

@@ -24,6 +47,2 @@ "./app": {

},
"./global.d": {
"import": "./global.d.js",
"require": "./global.d.cjs"
},
".": {

@@ -51,27 +70,2 @@ "import": "./index.js",

},
"scripts": {
"build": "yarn tsup && node ./scripts/after-build.cjs && yarn generate-docs",
"npm-pack": "yarn build && cd ./dist && npm pack",
"npm-publish": "yarn build && cd ./dist && yarn publish --access public --loglevel silly --tag next",
"lint": "eslint --ext ts \"./src/**/*.ts\"",
"lint-fix": "eslint --fix --ext ts \"./src/**/*.ts\"",
"format": "prettier --write --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path ../../.prettierignore",
"format:check": "prettier --check --end-of-line=auto \"./**/*.{cjs,js,jsx,ts,tsx,html,css,json}\" --ignore-path ../../.prettierignore",
"generate-docs": "typedoc --plugin typedoc-plugin-markdown --plugin typedoc-plugin-mdn-links"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tauri-apps/tauri.git"
},
"contributors": [
"Tauri Programme within The Commons Conservancy"
],
"license": "Apache-2.0 OR MIT",
"bugs": {
"url": "https://github.com/tauri-apps/tauri/issues"
},
"homepage": "https://github.com/tauri-apps/tauri#readme",
"publishConfig": {
"access": "public"
},
"engines": {

@@ -81,7 +75,3 @@ "node": ">= 18",

"yarn": ">= 1.19.1"
},
"devDependencies": {},
"resolutions": {
"semver": ">=7.5.2"
}
}

@@ -1,1 +0,507 @@

export { B as BaseDirectory, d as appCacheDir, a as appConfigDir, b as appDataDir, c as appLocalDataDir, e as appLogDir, f as audioDir, G as basename, g as cacheDir, h as configDir, i as dataDir, z as delimiter, j as desktopDir, E as dirname, k as documentDir, l as downloadDir, m as executableDir, F as extname, n as fontDir, o as homeDir, H as isAbsolute, D as join, q as localDataDir, C as normalize, r as pictureDir, s as publicDir, A as resolve, u as resolveResource, t as resourceDir, v as runtimeDir, y as sep, I as tempDir, w as templateDir, x as videoDir } from './path-9694881f.js';
/**
* @since 2.0.0
*/
declare enum BaseDirectory {
Audio = 1,
Cache = 2,
Config = 3,
Data = 4,
LocalData = 5,
Document = 6,
Download = 7,
Picture = 8,
Public = 9,
Video = 10,
Resource = 11,
Temp = 12,
AppConfig = 13,
AppData = 14,
AppLocalData = 15,
AppCache = 16,
AppLog = 17,
Desktop = 18,
Executable = 19,
Font = 20,
Home = 21,
Runtime = 22,
Template = 23
}
/**
* Returns the path to the suggested directory for your app's config files.
* Resolves to `${configDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appConfigDir } from '@tauri-apps/api/path';
* const appConfigDirPath = await appConfigDir();
* ```
*
* @since 1.2.0
*/
declare function appConfigDir(): Promise<string>;
/**
* Returns the path to the suggested directory for your app's data files.
* Resolves to `${dataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* ```
*
* @since 1.2.0
*/
declare function appDataDir(): Promise<string>;
/**
* Returns the path to the suggested directory for your app's local data files.
* Resolves to `${localDataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appLocalDataDir } from '@tauri-apps/api/path';
* const appLocalDataDirPath = await appLocalDataDir();
* ```
*
* @since 1.2.0
*/
declare function appLocalDataDir(): Promise<string>;
/**
* Returns the path to the suggested directory for your app's cache files.
* Resolves to `${cacheDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appCacheDir } from '@tauri-apps/api/path';
* const appCacheDirPath = await appCacheDir();
* ```
*
* @since 1.2.0
*/
declare function appCacheDir(): Promise<string>;
/**
* Returns the path to the user's audio directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_MUSIC_DIR`.
* - **macOS:** Resolves to `$HOME/Music`.
* - **Windows:** Resolves to `{FOLDERID_Music}`.
* @example
* ```typescript
* import { audioDir } from '@tauri-apps/api/path';
* const audioDirPath = await audioDir();
* ```
*
* @since 1.0.0
*/
declare function audioDir(): Promise<string>;
/**
* Returns the path to the user's cache directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_CACHE_HOME` or `$HOME/.cache`.
* - **macOS:** Resolves to `$HOME/Library/Caches`.
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
* @example
* ```typescript
* import { cacheDir } from '@tauri-apps/api/path';
* const cacheDirPath = await cacheDir();
* ```
*
* @since 1.0.0
*/
declare function cacheDir(): Promise<string>;
/**
* Returns the path to the user's config directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
* @example
* ```typescript
* import { configDir } from '@tauri-apps/api/path';
* const configDirPath = await configDir();
* ```
*
* @since 1.0.0
*/
declare function configDir(): Promise<string>;
/**
* Returns the path to the user's data directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
* @example
* ```typescript
* import { dataDir } from '@tauri-apps/api/path';
* const dataDirPath = await dataDir();
* ```
*
* @since 1.0.0
*/
declare function dataDir(): Promise<string>;
/**
* Returns the path to the user's desktop directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DESKTOP_DIR`.
* - **macOS:** Resolves to `$HOME/Desktop`.
* - **Windows:** Resolves to `{FOLDERID_Desktop}`.
* @example
* ```typescript
* import { desktopDir } from '@tauri-apps/api/path';
* const desktopPath = await desktopDir();
* ```
*
* @since 1.0.0
*/
declare function desktopDir(): Promise<string>;
/**
* Returns the path to the user's document directory.
* @example
* ```typescript
* import { documentDir } from '@tauri-apps/api/path';
* const documentDirPath = await documentDir();
* ```
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOCUMENTS_DIR`.
* - **macOS:** Resolves to `$HOME/Documents`.
* - **Windows:** Resolves to `{FOLDERID_Documents}`.
*
* @since 1.0.0
*/
declare function documentDir(): Promise<string>;
/**
* Returns the path to the user's download directory.
*
* #### Platform-specific
*
* - **Linux**: Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOWNLOAD_DIR`.
* - **macOS**: Resolves to `$HOME/Downloads`.
* - **Windows**: Resolves to `{FOLDERID_Downloads}`.
* @example
* ```typescript
* import { downloadDir } from '@tauri-apps/api/path';
* const downloadDirPath = await downloadDir();
* ```
*
* @since 1.0.0
*/
declare function downloadDir(): Promise<string>;
/**
* Returns the path to the user's executable directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_BIN_HOME/../bin` or `$XDG_DATA_HOME/../bin` or `$HOME/.local/bin`.
* - **macOS:** Not supported.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { executableDir } from '@tauri-apps/api/path';
* const executableDirPath = await executableDir();
* ```
*
* @since 1.0.0
*/
declare function executableDir(): Promise<string>;
/**
* Returns the path to the user's font directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME/fonts` or `$HOME/.local/share/fonts`.
* - **macOS:** Resolves to `$HOME/Library/Fonts`.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { fontDir } from '@tauri-apps/api/path';
* const fontDirPath = await fontDir();
* ```
*
* @since 1.0.0
*/
declare function fontDir(): Promise<string>;
/**
* Returns the path to the user's home directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$HOME`.
* - **macOS:** Resolves to `$HOME`.
* - **Windows:** Resolves to `{FOLDERID_Profile}`.
* @example
* ```typescript
* import { homeDir } from '@tauri-apps/api/path';
* const homeDirPath = await homeDir();
* ```
*
* @since 1.0.0
*/
declare function homeDir(): Promise<string>;
/**
* Returns the path to the user's local data directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
* @example
* ```typescript
* import { localDataDir } from '@tauri-apps/api/path';
* const localDataDirPath = await localDataDir();
* ```
*
* @since 1.0.0
*/
declare function localDataDir(): Promise<string>;
/**
* Returns the path to the user's picture directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PICTURES_DIR`.
* - **macOS:** Resolves to `$HOME/Pictures`.
* - **Windows:** Resolves to `{FOLDERID_Pictures}`.
* @example
* ```typescript
* import { pictureDir } from '@tauri-apps/api/path';
* const pictureDirPath = await pictureDir();
* ```
*
* @since 1.0.0
*/
declare function pictureDir(): Promise<string>;
/**
* Returns the path to the user's public directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PUBLICSHARE_DIR`.
* - **macOS:** Resolves to `$HOME/Public`.
* - **Windows:** Resolves to `{FOLDERID_Public}`.
* @example
* ```typescript
* import { publicDir } from '@tauri-apps/api/path';
* const publicDirPath = await publicDir();
* ```
*
* @since 1.0.0
*/
declare function publicDir(): Promise<string>;
/**
* Returns the path to the application's resource directory.
* To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
* @example
* ```typescript
* import { resourceDir } from '@tauri-apps/api/path';
* const resourceDirPath = await resourceDir();
* ```
*
* @since 1.0.0
*/
declare function resourceDir(): Promise<string>;
/**
* Resolve the path to a resource file.
* @example
* ```typescript
* import { resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('script.sh');
* ```
*
* @param resourcePath The path to the resource.
* Must follow the same syntax as defined in `tauri.conf.json > tauri > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
* @returns The full path to the resource.
*
* @since 1.0.0
*/
declare function resolveResource(resourcePath: string): Promise<string>;
/**
* Returns the path to the user's runtime directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_RUNTIME_DIR`.
* - **macOS:** Not supported.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { runtimeDir } from '@tauri-apps/api/path';
* const runtimeDirPath = await runtimeDir();
* ```
*
* @since 1.0.0
*/
declare function runtimeDir(): Promise<string>;
/**
* Returns the path to the user's template directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_TEMPLATES_DIR`.
* - **macOS:** Not supported.
* - **Windows:** Resolves to `{FOLDERID_Templates}`.
* @example
* ```typescript
* import { templateDir } from '@tauri-apps/api/path';
* const templateDirPath = await templateDir();
* ```
*
* @since 1.0.0
*/
declare function templateDir(): Promise<string>;
/**
* Returns the path to the user's video directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_VIDEOS_DIR`.
* - **macOS:** Resolves to `$HOME/Movies`.
* - **Windows:** Resolves to `{FOLDERID_Videos}`.
* @example
* ```typescript
* import { videoDir } from '@tauri-apps/api/path';
* const videoDirPath = await videoDir();
* ```
*
* @since 1.0.0
*/
declare function videoDir(): Promise<string>;
/**
* Returns the path to the suggested directory for your app's log files.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
* - **macOS:** Resolves to `${homeDir}/Library/Logs/{bundleIdentifier}`
* - **Windows:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
* @example
* ```typescript
* import { appLogDir } from '@tauri-apps/api/path';
* const appLogDirPath = await appLogDir();
* ```
*
* @since 1.2.0
*/
declare function appLogDir(): Promise<string>;
/**
* Returns a temporary directory.
* @example
* ```typescript
* import { tempDir } from '@tauri-apps/api/path';
* const temp = await tempDir();
* ```
*
* @since 2.0.0
*/
declare function tempDir(path: string): Promise<string>;
/**
* Returns the platform-specific path segment separator:
* - `\` on Windows
* - `/` on POSIX
*
* @since 2.0.0
*/
declare function sep(): string;
/**
* Returns the platform-specific path segment delimiter:
* - `;` on Windows
* - `:` on POSIX
*
* @since 2.0.0
*/
declare function delimiter(): string;
/**
* Resolves a sequence of `paths` or `path` segments into an absolute path.
* @example
* ```typescript
* import { resolve, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
declare function resolve(...paths: string[]): Promise<string>;
/**
* Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symbolic links.
* @example
* ```typescript
* import { normalize, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await normalize(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
declare function normalize(path: string): Promise<string>;
/**
* Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
* @example
* ```typescript
* import { join, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
declare function join(...paths: string[]): Promise<string>;
/**
* Returns the directory name of a `path`. Trailing directory separators are ignored.
* @example
* ```typescript
* import { dirname, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const dir = await dirname(appDataDirPath);
* ```
*
* @since 1.0.0
*/
declare function dirname(path: string): Promise<string>;
/**
* Returns the extension of the `path`.
* @example
* ```typescript
* import { extname, resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('app.conf');
* const ext = await extname(resourcePath);
* assert(ext === 'conf');
* ```
*
* @since 1.0.0
*/
declare function extname(path: string): Promise<string>;
/**
* Returns the last portion of a `path`. Trailing directory separators are ignored.
* @example
* ```typescript
* import { basename, resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('app.conf');
* const base = await basename(resourcePath);
* assert(base === 'app.conf');
* ```
*
* @param ext An optional file extension to be removed from the returned path.
*
* @since 1.0.0
*/
declare function basename(path: string, ext?: string): Promise<string>;
/**
* Returns whether the path is absolute or not.
* @example
* ```typescript
* import { isAbsolute } from '@tauri-apps/api/path';
* assert(await isAbsolute('/home/tauri'));
* ```
*
* @since 1.0.0
*/
declare function isAbsolute(path: string): Promise<boolean>;
export { BaseDirectory, appConfigDir, appDataDir, appLocalDataDir, appCacheDir, appLogDir, audioDir, cacheDir, configDir, dataDir, desktopDir, documentDir, downloadDir, executableDir, fontDir, homeDir, localDataDir, pictureDir, publicDir, resourceDir, resolveResource, runtimeDir, templateDir, videoDir, sep, delimiter, resolve, normalize, join, dirname, extname, basename, isAbsolute, tempDir };

@@ -1,1 +0,637 @@

import{A,B,C,D,E,F,G,H,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}from"./chunk-UPUVCPZK.js";import"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{a as BaseDirectory,e as appCacheDir,b as appConfigDir,c as appDataDir,d as appLocalDataDir,x as appLogDir,f as audioDir,G as basename,g as cacheDir,h as configDir,i as dataDir,A as delimiter,j as desktopDir,E as dirname,k as documentDir,l as downloadDir,m as executableDir,F as extname,n as fontDir,o as homeDir,H as isAbsolute,D as join,p as localDataDir,C as normalize,q as pictureDir,r as publicDir,B as resolve,t as resolveResource,s as resourceDir,u as runtimeDir,z as sep,y as tempDir,v as templateDir,w as videoDir};
import { invoke } from './primitives.js';
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* The path module provides utilities for working with file and directory paths.
*
* This package is also accessible with `window.__TAURI__.path` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
*
* It is recommended to allowlist only the APIs you use for optimal bundle size and security.
* @module
*/
/**
* @since 2.0.0
*/
var BaseDirectory;
(function (BaseDirectory) {
BaseDirectory[BaseDirectory["Audio"] = 1] = "Audio";
BaseDirectory[BaseDirectory["Cache"] = 2] = "Cache";
BaseDirectory[BaseDirectory["Config"] = 3] = "Config";
BaseDirectory[BaseDirectory["Data"] = 4] = "Data";
BaseDirectory[BaseDirectory["LocalData"] = 5] = "LocalData";
BaseDirectory[BaseDirectory["Document"] = 6] = "Document";
BaseDirectory[BaseDirectory["Download"] = 7] = "Download";
BaseDirectory[BaseDirectory["Picture"] = 8] = "Picture";
BaseDirectory[BaseDirectory["Public"] = 9] = "Public";
BaseDirectory[BaseDirectory["Video"] = 10] = "Video";
BaseDirectory[BaseDirectory["Resource"] = 11] = "Resource";
BaseDirectory[BaseDirectory["Temp"] = 12] = "Temp";
BaseDirectory[BaseDirectory["AppConfig"] = 13] = "AppConfig";
BaseDirectory[BaseDirectory["AppData"] = 14] = "AppData";
BaseDirectory[BaseDirectory["AppLocalData"] = 15] = "AppLocalData";
BaseDirectory[BaseDirectory["AppCache"] = 16] = "AppCache";
BaseDirectory[BaseDirectory["AppLog"] = 17] = "AppLog";
BaseDirectory[BaseDirectory["Desktop"] = 18] = "Desktop";
BaseDirectory[BaseDirectory["Executable"] = 19] = "Executable";
BaseDirectory[BaseDirectory["Font"] = 20] = "Font";
BaseDirectory[BaseDirectory["Home"] = 21] = "Home";
BaseDirectory[BaseDirectory["Runtime"] = 22] = "Runtime";
BaseDirectory[BaseDirectory["Template"] = 23] = "Template";
})(BaseDirectory || (BaseDirectory = {}));
/**
* Returns the path to the suggested directory for your app's config files.
* Resolves to `${configDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appConfigDir } from '@tauri-apps/api/path';
* const appConfigDirPath = await appConfigDir();
* ```
*
* @since 1.2.0
*/
async function appConfigDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.AppConfig
});
}
/**
* Returns the path to the suggested directory for your app's data files.
* Resolves to `${dataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* ```
*
* @since 1.2.0
*/
async function appDataDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.AppData
});
}
/**
* Returns the path to the suggested directory for your app's local data files.
* Resolves to `${localDataDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appLocalDataDir } from '@tauri-apps/api/path';
* const appLocalDataDirPath = await appLocalDataDir();
* ```
*
* @since 1.2.0
*/
async function appLocalDataDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.AppLocalData
});
}
/**
* Returns the path to the suggested directory for your app's cache files.
* Resolves to `${cacheDir}/${bundleIdentifier}`, where `bundleIdentifier` is the value [`tauri.bundle.identifier`](https://tauri.app/v1/api/config/#bundleconfig.identifier) is configured in `tauri.conf.json`.
* @example
* ```typescript
* import { appCacheDir } from '@tauri-apps/api/path';
* const appCacheDirPath = await appCacheDir();
* ```
*
* @since 1.2.0
*/
async function appCacheDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.AppCache
});
}
/**
* Returns the path to the user's audio directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_MUSIC_DIR`.
* - **macOS:** Resolves to `$HOME/Music`.
* - **Windows:** Resolves to `{FOLDERID_Music}`.
* @example
* ```typescript
* import { audioDir } from '@tauri-apps/api/path';
* const audioDirPath = await audioDir();
* ```
*
* @since 1.0.0
*/
async function audioDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Audio
});
}
/**
* Returns the path to the user's cache directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_CACHE_HOME` or `$HOME/.cache`.
* - **macOS:** Resolves to `$HOME/Library/Caches`.
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
* @example
* ```typescript
* import { cacheDir } from '@tauri-apps/api/path';
* const cacheDirPath = await cacheDir();
* ```
*
* @since 1.0.0
*/
async function cacheDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Cache
});
}
/**
* Returns the path to the user's config directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_CONFIG_HOME` or `$HOME/.config`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
* @example
* ```typescript
* import { configDir } from '@tauri-apps/api/path';
* const configDirPath = await configDir();
* ```
*
* @since 1.0.0
*/
async function configDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Config
});
}
/**
* Returns the path to the user's data directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_RoamingAppData}`.
* @example
* ```typescript
* import { dataDir } from '@tauri-apps/api/path';
* const dataDirPath = await dataDir();
* ```
*
* @since 1.0.0
*/
async function dataDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Data
});
}
/**
* Returns the path to the user's desktop directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DESKTOP_DIR`.
* - **macOS:** Resolves to `$HOME/Desktop`.
* - **Windows:** Resolves to `{FOLDERID_Desktop}`.
* @example
* ```typescript
* import { desktopDir } from '@tauri-apps/api/path';
* const desktopPath = await desktopDir();
* ```
*
* @since 1.0.0
*/
async function desktopDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Desktop
});
}
/**
* Returns the path to the user's document directory.
* @example
* ```typescript
* import { documentDir } from '@tauri-apps/api/path';
* const documentDirPath = await documentDir();
* ```
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOCUMENTS_DIR`.
* - **macOS:** Resolves to `$HOME/Documents`.
* - **Windows:** Resolves to `{FOLDERID_Documents}`.
*
* @since 1.0.0
*/
async function documentDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Document
});
}
/**
* Returns the path to the user's download directory.
*
* #### Platform-specific
*
* - **Linux**: Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_DOWNLOAD_DIR`.
* - **macOS**: Resolves to `$HOME/Downloads`.
* - **Windows**: Resolves to `{FOLDERID_Downloads}`.
* @example
* ```typescript
* import { downloadDir } from '@tauri-apps/api/path';
* const downloadDirPath = await downloadDir();
* ```
*
* @since 1.0.0
*/
async function downloadDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Download
});
}
/**
* Returns the path to the user's executable directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_BIN_HOME/../bin` or `$XDG_DATA_HOME/../bin` or `$HOME/.local/bin`.
* - **macOS:** Not supported.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { executableDir } from '@tauri-apps/api/path';
* const executableDirPath = await executableDir();
* ```
*
* @since 1.0.0
*/
async function executableDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Executable
});
}
/**
* Returns the path to the user's font directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME/fonts` or `$HOME/.local/share/fonts`.
* - **macOS:** Resolves to `$HOME/Library/Fonts`.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { fontDir } from '@tauri-apps/api/path';
* const fontDirPath = await fontDir();
* ```
*
* @since 1.0.0
*/
async function fontDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Font
});
}
/**
* Returns the path to the user's home directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$HOME`.
* - **macOS:** Resolves to `$HOME`.
* - **Windows:** Resolves to `{FOLDERID_Profile}`.
* @example
* ```typescript
* import { homeDir } from '@tauri-apps/api/path';
* const homeDirPath = await homeDir();
* ```
*
* @since 1.0.0
*/
async function homeDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Home
});
}
/**
* Returns the path to the user's local data directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_DATA_HOME` or `$HOME/.local/share`.
* - **macOS:** Resolves to `$HOME/Library/Application Support`.
* - **Windows:** Resolves to `{FOLDERID_LocalAppData}`.
* @example
* ```typescript
* import { localDataDir } from '@tauri-apps/api/path';
* const localDataDirPath = await localDataDir();
* ```
*
* @since 1.0.0
*/
async function localDataDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.LocalData
});
}
/**
* Returns the path to the user's picture directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PICTURES_DIR`.
* - **macOS:** Resolves to `$HOME/Pictures`.
* - **Windows:** Resolves to `{FOLDERID_Pictures}`.
* @example
* ```typescript
* import { pictureDir } from '@tauri-apps/api/path';
* const pictureDirPath = await pictureDir();
* ```
*
* @since 1.0.0
*/
async function pictureDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Picture
});
}
/**
* Returns the path to the user's public directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_PUBLICSHARE_DIR`.
* - **macOS:** Resolves to `$HOME/Public`.
* - **Windows:** Resolves to `{FOLDERID_Public}`.
* @example
* ```typescript
* import { publicDir } from '@tauri-apps/api/path';
* const publicDirPath = await publicDir();
* ```
*
* @since 1.0.0
*/
async function publicDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Public
});
}
/**
* Returns the path to the application's resource directory.
* To resolve a resource path, see the [[resolveResource | `resolveResource API`]].
* @example
* ```typescript
* import { resourceDir } from '@tauri-apps/api/path';
* const resourceDirPath = await resourceDir();
* ```
*
* @since 1.0.0
*/
async function resourceDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Resource
});
}
/**
* Resolve the path to a resource file.
* @example
* ```typescript
* import { resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('script.sh');
* ```
*
* @param resourcePath The path to the resource.
* Must follow the same syntax as defined in `tauri.conf.json > tauri > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`).
* @returns The full path to the resource.
*
* @since 1.0.0
*/
async function resolveResource(resourcePath) {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Resource,
path: resourcePath
});
}
/**
* Returns the path to the user's runtime directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `$XDG_RUNTIME_DIR`.
* - **macOS:** Not supported.
* - **Windows:** Not supported.
* @example
* ```typescript
* import { runtimeDir } from '@tauri-apps/api/path';
* const runtimeDirPath = await runtimeDir();
* ```
*
* @since 1.0.0
*/
async function runtimeDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Runtime
});
}
/**
* Returns the path to the user's template directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_TEMPLATES_DIR`.
* - **macOS:** Not supported.
* - **Windows:** Resolves to `{FOLDERID_Templates}`.
* @example
* ```typescript
* import { templateDir } from '@tauri-apps/api/path';
* const templateDirPath = await templateDir();
* ```
*
* @since 1.0.0
*/
async function templateDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Template
});
}
/**
* Returns the path to the user's video directory.
*
* #### Platform-specific
*
* - **Linux:** Resolves to [`xdg-user-dirs`](https://www.freedesktop.org/wiki/Software/xdg-user-dirs/)' `XDG_VIDEOS_DIR`.
* - **macOS:** Resolves to `$HOME/Movies`.
* - **Windows:** Resolves to `{FOLDERID_Videos}`.
* @example
* ```typescript
* import { videoDir } from '@tauri-apps/api/path';
* const videoDirPath = await videoDir();
* ```
*
* @since 1.0.0
*/
async function videoDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Video
});
}
/**
* Returns the path to the suggested directory for your app's log files.
*
* #### Platform-specific
*
* - **Linux:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
* - **macOS:** Resolves to `${homeDir}/Library/Logs/{bundleIdentifier}`
* - **Windows:** Resolves to `${configDir}/${bundleIdentifier}/logs`.
* @example
* ```typescript
* import { appLogDir } from '@tauri-apps/api/path';
* const appLogDirPath = await appLogDir();
* ```
*
* @since 1.2.0
*/
async function appLogDir() {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.AppLog
});
}
/**
* Returns a temporary directory.
* @example
* ```typescript
* import { tempDir } from '@tauri-apps/api/path';
* const temp = await tempDir();
* ```
*
* @since 2.0.0
*/
async function tempDir(path) {
return invoke('plugin:path|resolve_directory', {
directory: BaseDirectory.Temp
});
}
/**
* Returns the platform-specific path segment separator:
* - `\` on Windows
* - `/` on POSIX
*
* @since 2.0.0
*/
function sep() {
return window.__TAURI_INTERNALS__.plugins.path.sep;
}
/**
* Returns the platform-specific path segment delimiter:
* - `;` on Windows
* - `:` on POSIX
*
* @since 2.0.0
*/
function delimiter() {
return window.__TAURI_INTERNALS__.plugins.path.delimiter;
}
/**
* Resolves a sequence of `paths` or `path` segments into an absolute path.
* @example
* ```typescript
* import { resolve, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await resolve(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
async function resolve(...paths) {
return invoke('plugin:path|resolve', { paths });
}
/**
* Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symbolic links.
* @example
* ```typescript
* import { normalize, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await normalize(appDataDirPath, '..', 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
async function normalize(path) {
return invoke('plugin:path|normalize', { path });
}
/**
* Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.
* @example
* ```typescript
* import { join, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const path = await join(appDataDirPath, 'users', 'tauri', 'avatar.png');
* ```
*
* @since 1.0.0
*/
async function join(...paths) {
return invoke('plugin:path|join', { paths });
}
/**
* Returns the directory name of a `path`. Trailing directory separators are ignored.
* @example
* ```typescript
* import { dirname, appDataDir } from '@tauri-apps/api/path';
* const appDataDirPath = await appDataDir();
* const dir = await dirname(appDataDirPath);
* ```
*
* @since 1.0.0
*/
async function dirname(path) {
return invoke('plugin:path|dirname', { path });
}
/**
* Returns the extension of the `path`.
* @example
* ```typescript
* import { extname, resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('app.conf');
* const ext = await extname(resourcePath);
* assert(ext === 'conf');
* ```
*
* @since 1.0.0
*/
async function extname(path) {
return invoke('plugin:path|extname', { path });
}
/**
* Returns the last portion of a `path`. Trailing directory separators are ignored.
* @example
* ```typescript
* import { basename, resolveResource } from '@tauri-apps/api/path';
* const resourcePath = await resolveResource('app.conf');
* const base = await basename(resourcePath);
* assert(base === 'app.conf');
* ```
*
* @param ext An optional file extension to be removed from the returned path.
*
* @since 1.0.0
*/
async function basename(path, ext) {
return invoke('plugin:path|basename', { path, ext });
}
/**
* Returns whether the path is absolute or not.
* @example
* ```typescript
* import { isAbsolute } from '@tauri-apps/api/path';
* assert(await isAbsolute('/home/tauri'));
* ```
*
* @since 1.0.0
*/
async function isAbsolute(path) {
return invoke('plugin:path|isAbsolute', { path });
}
export { BaseDirectory, appCacheDir, appConfigDir, appDataDir, appLocalDataDir, appLogDir, audioDir, basename, cacheDir, configDir, dataDir, delimiter, desktopDir, dirname, documentDir, downloadDir, executableDir, extname, fontDir, homeDir, isAbsolute, join, localDataDir, normalize, pictureDir, publicDir, resolve, resolveResource, resourceDir, runtimeDir, sep, tempDir, templateDir, videoDir };

@@ -1,1 +0,100 @@

export { C as Channel, I as InvokeArgs, a as InvokeOptions, P as PluginListener, b as addPluginListener, c as convertFileSrc, i as invoke, t as transformCallback } from './primitives-742a88b2.js';
/**
* Invoke your custom commands.
*
* This package is also accessible with `window.__TAURI__.tauri` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
* @module
*/
/**
* Transforms a callback function to a string identifier that can be passed to the backend.
* The backend uses the identifier to `eval()` the callback.
*
* @return A unique identifier associated with the callback function.
*
* @since 1.0.0
*/
declare function transformCallback<T = unknown>(callback?: (response: T) => void, once?: boolean): number;
declare class Channel<T = unknown> {
#private;
id: number;
private readonly __TAURI_CHANNEL_MARKER__;
constructor();
set onmessage(handler: (response: T) => void);
get onmessage(): (response: T) => void;
toJSON(): string;
}
declare class PluginListener {
plugin: string;
event: string;
channelId: number;
constructor(plugin: string, event: string, channelId: number);
unregister(): Promise<void>;
}
/**
* Adds a listener to a plugin event.
*
* @returns The listener object to stop listening to the events.
*
* @since 2.0.0
*/
declare function addPluginListener<T>(plugin: string, event: string, cb: (payload: T) => void): Promise<PluginListener>;
/**
* Command arguments.
*
* @since 1.0.0
*/
type InvokeArgs = Record<string, unknown> | number[] | ArrayBuffer | Uint8Array;
/**
* @since 2.0.0
*/
interface InvokeOptions {
headers: Headers | Record<string, string>;
}
/**
* Sends a message to the backend.
* @example
* ```typescript
* import { invoke } from '@tauri-apps/api/primitives';
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
* ```
*
* @param cmd The command name.
* @param args The optional arguments to pass to the command.
* @param options The request options.
* @return A promise resolving or rejecting to the backend response.
*
* @since 1.0.0
*/
declare function invoke<T>(cmd: string, args?: InvokeArgs, options?: InvokeOptions): Promise<T>;
/**
* Convert a device file path to an URL that can be loaded by the webview.
* Note that `asset:` and `http://asset.localhost` must be added to [`tauri.security.csp`](https://tauri.app/v1/api/config/#securityconfig.csp) in `tauri.conf.json`.
* Example CSP value: `"csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost"` to use the asset protocol on image sources.
*
* Additionally, `asset` must be added to [`tauri.allowlist.protocol`](https://tauri.app/v1/api/config/#allowlistconfig.protocol)
* in `tauri.conf.json` and its access scope must be defined on the `assetScope` array on the same `protocol` object.
*
* @param filePath The file path.
* @param protocol The protocol to use. Defaults to `asset`. You only need to set this when using a custom protocol.
* @example
* ```typescript
* import { appDataDir, join } from '@tauri-apps/api/path';
* import { convertFileSrc } from '@tauri-apps/api/primitives';
* const appDataDirPath = await appDataDir();
* const filePath = await join(appDataDirPath, 'assets/video.mp4');
* const assetUrl = convertFileSrc(filePath);
*
* const video = document.getElementById('my-video');
* const source = document.createElement('source');
* source.type = 'video/mp4';
* source.src = assetUrl;
* video.appendChild(source);
* video.load();
* ```
*
* @return the URL that can be used as source on the webview.
*
* @since 1.0.0
*/
declare function convertFileSrc(filePath: string, protocol?: string): string;
export type { InvokeArgs, InvokeOptions };
export { transformCallback, Channel, PluginListener, addPluginListener, invoke, convertFileSrc };

@@ -1,1 +0,123 @@

import{a,b,c,d,e,f}from"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{b as Channel,c as PluginListener,d as addPluginListener,f as convertFileSrc,e as invoke,a as transformCallback};
import { __classPrivateFieldGet, __classPrivateFieldSet } from './node_modules/tslib/tslib.es6.js';
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
var _Channel_onmessage;
/**
* Invoke your custom commands.
*
* This package is also accessible with `window.__TAURI__.tauri` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`.
* @module
*/
/**
* Transforms a callback function to a string identifier that can be passed to the backend.
* The backend uses the identifier to `eval()` the callback.
*
* @return A unique identifier associated with the callback function.
*
* @since 1.0.0
*/
function transformCallback(callback, once = false) {
return window.__TAURI_INTERNALS__.transformCallback(callback, once);
}
class Channel {
constructor() {
// @ts-expect-error field used by the IPC serializer
this.__TAURI_CHANNEL_MARKER__ = true;
_Channel_onmessage.set(this, () => {
// no-op
});
this.id = transformCallback((response) => {
__classPrivateFieldGet(this, _Channel_onmessage, "f").call(this, response);
});
}
set onmessage(handler) {
__classPrivateFieldSet(this, _Channel_onmessage, handler, "f");
}
get onmessage() {
return __classPrivateFieldGet(this, _Channel_onmessage, "f");
}
toJSON() {
return `__CHANNEL__:${this.id}`;
}
}
_Channel_onmessage = new WeakMap();
class PluginListener {
constructor(plugin, event, channelId) {
this.plugin = plugin;
this.event = event;
this.channelId = channelId;
}
async unregister() {
return invoke(`plugin:${this.plugin}|remove_listener`, {
event: this.event,
channelId: this.channelId
});
}
}
/**
* Adds a listener to a plugin event.
*
* @returns The listener object to stop listening to the events.
*
* @since 2.0.0
*/
async function addPluginListener(plugin, event, cb) {
const handler = new Channel();
handler.onmessage = cb;
return invoke(`plugin:${plugin}|register_listener`, { event, handler }).then(() => new PluginListener(plugin, event, handler.id));
}
/**
* Sends a message to the backend.
* @example
* ```typescript
* import { invoke } from '@tauri-apps/api/primitives';
* await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
* ```
*
* @param cmd The command name.
* @param args The optional arguments to pass to the command.
* @param options The request options.
* @return A promise resolving or rejecting to the backend response.
*
* @since 1.0.0
*/
async function invoke(cmd, args = {}, options) {
return window.__TAURI_INTERNALS__.invoke(cmd, args, options);
}
/**
* Convert a device file path to an URL that can be loaded by the webview.
* Note that `asset:` and `http://asset.localhost` must be added to [`tauri.security.csp`](https://tauri.app/v1/api/config/#securityconfig.csp) in `tauri.conf.json`.
* Example CSP value: `"csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost"` to use the asset protocol on image sources.
*
* Additionally, `asset` must be added to [`tauri.allowlist.protocol`](https://tauri.app/v1/api/config/#allowlistconfig.protocol)
* in `tauri.conf.json` and its access scope must be defined on the `assetScope` array on the same `protocol` object.
*
* @param filePath The file path.
* @param protocol The protocol to use. Defaults to `asset`. You only need to set this when using a custom protocol.
* @example
* ```typescript
* import { appDataDir, join } from '@tauri-apps/api/path';
* import { convertFileSrc } from '@tauri-apps/api/primitives';
* const appDataDirPath = await appDataDir();
* const filePath = await join(appDataDirPath, 'assets/video.mp4');
* const assetUrl = convertFileSrc(filePath);
*
* const video = document.getElementById('my-video');
* const source = document.createElement('source');
* source.type = 'video/mp4';
* source.src = assetUrl;
* video.appendChild(source);
* video.load();
* ```
*
* @return the URL that can be used as source on the webview.
*
* @since 1.0.0
*/
function convertFileSrc(filePath, protocol = 'asset') {
return window.__TAURI_INTERNALS__.convertFileSrc(filePath, protocol);
}
export { Channel, PluginListener, addPluginListener, convertFileSrc, invoke, transformCallback };

@@ -1,3 +0,1469 @@

export { b as LogicalPosition, L as LogicalSize, a as PhysicalPosition, P as PhysicalSize } from './dpi-1b9c86cc.js';
import './event-bdc5d2c8.js';
export { C as CloseRequestedEvent, i as Color, j as CursorIcon, E as Effect, b as EffectState, e as Effects, F as FileDropEvent, M as Monitor, k as ProgressBarState, P as ProgressBarStatus, S as ScaleFactorChanged, T as Theme, f as TitleBarStyle, U as UserAttentionType, W as Window, l as WindowLabel, h as WindowOptions, d as availableMonitors, c as currentMonitor, a as getAll, g as getCurrent, p as primaryMonitor } from './window-e99b5597.js';
/**
* Provides APIs to create windows, communicate with other windows and manipulate the current window.
*
* ## Window events
*
* Events can be listened to using {@link Window.listen}:
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* getCurrent().listen("my-window-event", ({ event, payload }) => { });
* ```
*
* @module
*/
import { LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize } from './dpi';
import type { Event, EventName, EventCallback, UnlistenFn } from './event';
/**
* Allows you to retrieve information about a given monitor.
*
* @since 1.0.0
*/
export 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;
}
type Theme = 'light' | 'dark';
type TitleBarStyle = 'visible' | 'transparent' | 'overlay';
/**
* 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';
};
/**
* 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
}
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;
}
export 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';
export declare enum ProgressBarStatus {
/**
* Hide progress bar.
*/
None = "none",
/**
* Normal state.
*/
Normal = "normal",
/**
* Indeterminate state. **Treated as Normal on Linux and macOS**
*/
Indeterminate = "indeterminate",
/**
* Paused state. **Treated as Normal on Linux**
*/
Paused = "paused",
/**
* Error state. **Treated as Normal on linux**
*/
Error = "error"
}
export interface ProgressBarState {
/**
* The progress bar status.
*/
status?: ProgressBarStatus;
/**
* The progress bar progress. This can be a value ranging from `0` to `100`
*/
progress?: number;
/**
* The identifier for your app to communicate with the Unity desktop window manager **Linux Only**
*/
unityUri?: string;
}
/**
* Get an instance of `Window` for the current window.
*
* @since 1.0.0
*/
declare function getCurrent(): Window;
/**
* Gets a list of instances of `Window` for all available windows.
*
* @since 1.0.0
*/
declare function getAll(): Window[];
/** @ignore */
export type WindowLabel = string;
/**
* Create new webview window or get a handle to an existing one.
*
* Windows are identified by a *label* a unique identifier that can be used to reference it later.
* It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
*
* @example
* ```typescript
* // loading embedded asset:
* const appWindow = new Window('theUniqueLabel', {
* url: 'path/to/page.html'
* });
* // alternatively, load a remote URL:
* const appWindow = new Window('theUniqueLabel', {
* url: 'https://github.com/tauri-apps/tauri'
* });
*
* 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 backend
* await appWindow.emit("some event", "data");
* // listen to an event from the backend
* const unlisten = await appWindow.listen("event name", e => {});
* unlisten();
* ```
*
* @since 2.0.0
*/
declare class Window {
/** 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>>>;
/**
* Creates a new Window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const appWindow = new Window('my-label', {
* url: 'https://github.com/tauri-apps/tauri'
* });
* appWindow.once('tauri://created', function () {
* // window successfully created
* });
* appWindow.once('tauri://error', function (e) {
* // an error happened creating the window
* });
* ```
*
* @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`.
* @returns The {@link Window} instance to communicate with the webview.
*/
constructor(label: WindowLabel, options?: WindowOptions);
/**
* Gets the Window for the webview associated with the given label.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const mainWindow = Window.getByLabel('main');
* ```
*
* @param label The webview window label.
* @returns The Window instance to communicate with the webview or null if the webview doesn't exist.
*/
static getByLabel(label: string): Window | null;
/**
* Get an instance of `Window` for the current window.
*/
static getCurrent(): Window;
/**
* Gets a list of instances of `Window` for all available windows.
*/
static getAll(): Window[];
/**
* Gets the focused window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const focusedWindow = Window.getFocusedWindow();
* ```
*
* @returns The Window instance to communicate with the webview or `undefined` if there is not any focused window.
*/
static getFocusedWindow(): Promise<Window | null>;
/**
* Listen to an event emitted by the backend that is tied to the webview window.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().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();
* ```
*
* @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.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
listen<T>(event: EventName, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Listen to an one-off event emitted by the backend that is tied to the webview window.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().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();
* ```
*
* @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.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
once<T>(event: string, handler: EventCallback<T>): Promise<UnlistenFn>;
/**
* Emits an event to the backend, tied to the webview window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @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;
/**
* 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();
* ```
*
* @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 { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* const position = await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().outerSize();
* ```
*
* @returns The window's outer size.
*/
outerSize(): Promise<PhysicalSize>;
/**
* Gets the window's current fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const fullscreen = await getCurrent().isFullscreen();
* ```
*
* @returns Whether the window is in fullscreen mode or not.
*/
isFullscreen(): Promise<boolean>;
/**
* Gets the window's current minimized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimized = await getCurrent().isMinimized();
* ```
*/
isMinimized(): Promise<boolean>;
/**
* Gets the window's current maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximized = await getCurrent().isMaximized();
* ```
*
* @returns Whether the window is maximized or not.
*/
isMaximized(): Promise<boolean>;
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const focused = await getCurrent().isFocused();
* ```
*
* @returns Whether the window is focused or not.
*/
isFocused(): Promise<boolean>;
/**
* Gets the window's current decorated state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const decorated = await getCurrent().isDecorated();
* ```
*
* @returns Whether the window is decorated or not.
*/
isDecorated(): Promise<boolean>;
/**
* Gets the window's current resizable state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const resizable = await getCurrent().isResizable();
* ```
*
* @returns Whether the window is resizable or not.
*/
isResizable(): Promise<boolean>;
/**
* Gets the window’s native maximize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximizable = await getCurrent().isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
*/
isMaximizable(): Promise<boolean>;
/**
* Gets the window’s native minimize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimizable = await getCurrent().isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
*/
isMinimizable(): Promise<boolean>;
/**
* Gets the window’s native close button state.
*
* #### Platform-specific
*
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const closable = await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* const visible = await getCurrent().isVisible();
* ```
*
* @returns Whether the window is visible or not.
*/
isVisible(): Promise<boolean>;
/**
* Gets the window's current title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const title = await getCurrent().title();
* ```
*/
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 { getCurrent } from '@tauri-apps/api/window';
* const theme = await getCurrent().theme();
* ```
*
* @returns The window theme.
*/
theme(): Promise<Theme | null>;
/**
* Centers the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().requestUserAttention();
* ```
*
* @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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setResizable(false);
* ```
*
* @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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMaximizable(false);
* ```
*
* @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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMinimizable(false);
* ```
*
* @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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setClosable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
setClosable(closable: boolean): Promise<void>;
/**
* Sets the window title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().maximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
maximize(): Promise<void>;
/**
* Unmaximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unmaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
unmaximize(): Promise<void>;
/**
* Toggles the window maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().toggleMaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
toggleMaximize(): Promise<void>;
/**
* Minimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().minimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
minimize(): Promise<void>;
/**
* Unminimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unminimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
unminimize(): Promise<void>;
/**
* Sets the window visibility to true.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().show();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
show(): Promise<void>;
/**
* Sets the window visibility to false.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().hide();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
hide(): Promise<void>;
/**
* Closes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 or not the window should have shadow.
*
* #### Platform-specific
*
* - **Windows:**
* - `false` has no effect on decorated window, shadows are always ON.
* - `true` will make ndecorated window have a 1px white border,
* and on Windows 11, it will have a rounded corners.
* - **Linux:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setShadow(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
setShadow(enable: boolean): Promise<void>;
/**
* Set window effects.
*/
setEffects(effects: Effects): Promise<void>;
/**
* Clear any applied effects if possible.
*/
clearEffects(): Promise<void>;
/**
* Whether the window should always be on top of other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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>;
/**
* Whether the window should always be below other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setAlwaysOnBottom(true);
* ```
*
* @param alwaysOnBottom Whether the window should always be below other windows or not.
* @returns A promise indicating the success or failure of the operation.
*/
setAlwaysOnBottom(alwaysOnBottom: boolean): Promise<void>;
/**
* Prevents the window contents from being captured by other apps.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setContentProtected(true);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
setContentProtected(protected_: boolean): Promise<void>;
/**
* 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));
* ```
*
* @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 { getCurrent, PhysicalSize } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent, LogicalSize } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setFocus();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
setFocus(): Promise<void>;
/**
* Sets the window icon.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().startDragging();
* ```
*
* @return A promise indicating the success or failure of the operation.
*/
startDragging(): Promise<void>;
/**
* Sets the taskbar progress state.
*
* #### Platform-specific
*
* - **Linux / macOS**: Progress bar is app-wide and not specific to this window.
* - **Linux**: Only supported desktop environments with `libunity` (e.g. GNOME).
*
* @example
* ```typescript
* import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
* await getCurrent().setProgressBar({
* status: ProgressBarStatus.Normal,
* progress: 50,
* });
* ```
*
* @return A promise indicating the success or failure of the operation.
*/
setProgressBar(state: ProgressBarState): Promise<void>;
/**
* Listen to window resize.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
onResized(handler: EventCallback<PhysicalSize>): Promise<UnlistenFn>;
/**
* Listen to window move.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
onMoved(handler: EventCallback<PhysicalPosition>): Promise<UnlistenFn>;
/**
* Listen to window close requested. Emitted when the user requests to closes the window.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* import { confirm } from '@tauri-apps/api/dialog';
* const unlisten = await getCurrent().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.
*/
onCloseRequested(handler: (event: CloseRequestedEvent) => void | Promise<void>): Promise<UnlistenFn>;
/**
* Listen to window focus change.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
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 { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
onScaleChanged(handler: EventCallback<ScaleFactorChanged>): Promise<UnlistenFn>;
/**
* Listen to the window menu item click. The payload is the item id.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
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 { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
onFileDropEvent(handler: EventCallback<FileDropEvent>): Promise<UnlistenFn>;
/**
* Listen to the system theme change.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
onThemeChanged(handler: EventCallback<Theme>): Promise<UnlistenFn>;
}
/**
* an array RGBA colors. Each value has minimum of 0 and maximum of 255.
*
* @since 2.0.0
*/
type Color = [number, number, number, number];
/**
* Platform-specific window effects
*
* @since 2.0.0
*/
declare enum Effect {
/**
* A default material appropriate for the view's effectiveAppearance. **macOS 10.14-**
*
* @deprecated since macOS 10.14. You should instead choose an appropriate semantic material.
*/
AppearanceBased = "appearanceBased",
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Light = "light",
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Dark = "dark",
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
MediumLight = "mediumLight",
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
UltraDark = "ultraDark",
/**
* **macOS 10.10+**
*/
Titlebar = "titlebar",
/**
* **macOS 10.10+**
*/
Selection = "selection",
/**
* **macOS 10.11+**
*/
Menu = "menu",
/**
* **macOS 10.11+**
*/
Popover = "popover",
/**
* **macOS 10.11+**
*/
Sidebar = "sidebar",
/**
* **macOS 10.14+**
*/
HeaderView = "headerView",
/**
* **macOS 10.14+**
*/
Sheet = "sheet",
/**
* **macOS 10.14+**
*/
WindowBackground = "windowBackground",
/**
* **macOS 10.14+**
*/
HudWindow = "hudWindow",
/**
* **macOS 10.14+**
*/
FullScreenUI = "fullScreenUI",
/**
* **macOS 10.14+**
*/
Tooltip = "tooltip",
/**
* **macOS 10.14+**
*/
ContentBackground = "contentBackground",
/**
* **macOS 10.14+**
*/
UnderWindowBackground = "underWindowBackground",
/**
* **macOS 10.14+**
*/
UnderPageBackground = "underPageBackground",
/**
* **Windows 11 Only**
*/
Mica = "mica",
/**
* **Windows 7/10/11(22H1) Only**
*
* ## Notes
*
* This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.
*/
Blur = "blur",
/**
* **Windows 10/11**
*
* ## Notes
*
* This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.
*/
Acrylic = "acrylic",
/**
* Tabbed effect that matches the system dark perefence **Windows 11 Only**
*/
Tabbed = "tabbed",
/**
* Tabbed effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**
*/
TabbedDark = "tabbedDark",
/**
* Tabbed effect with light mode **Windows 11 Only**
*/
TabbedLight = "tabbedLight"
}
/**
* Window effect state **macOS only**
*
* @see https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
*
* @since 2.0.0
*/
declare enum EffectState {
/**
* Make window effect state follow the window's active state **macOS only**
*/
FollowsWindowActiveState = "followsWindowActiveState",
/**
* Make window effect state always active **macOS only**
*/
Active = "active",
/**
* Make window effect state always inactive **macOS only**
*/
Inactive = "inactive"
}
/** The window effects configuration object
*
* @since 2.0.0
*/
interface Effects {
/**
* List of Window effects to apply to the Window.
* Conflicting effects will apply the first one and ignore the rest.
*/
effects: Effect[];
/**
* Window effect state **macOS Only**
*/
state?: EffectState;
/**
* Window effect corner radius **macOS Only**
*/
radius?: number;
/**
* Window effect color. Affects {@link Effect.Blur} and {@link Effect.Acrylic} only
* on Windows 10 v1903+. Doesn't have any effect on Windows 7 or Windows 11.
*/
color?: Color;
}
/**
* 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;
/** Whether the window should always be below other windows. */
alwaysOnBottom?: 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 or not the window has shadow.
*
* #### Platform-specific
*
* - **Windows:**
* - `false` has no effect on decorated window, shadows are always ON.
* - `true` will make ndecorated window have a 1px white border,
* and on Windows 11, it will have a rounded corners.
* - **Linux:** Unsupported.
*
* @since 2.0.0
*/
shadow?: 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 or not the webview should be launched in incognito mode.
*
* #### Platform-specific
*
* - **Android:** Unsupported.
*/
incognito?: boolean;
/**
* 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[]>;
export { Window, CloseRequestedEvent, getCurrent, getAll, LogicalSize, PhysicalSize, LogicalPosition, PhysicalPosition, UserAttentionType, Effect, EffectState, currentMonitor, primaryMonitor, availableMonitors };
export type { Effects, Theme, TitleBarStyle, ScaleFactorChanged, FileDropEvent, WindowOptions, Color };

@@ -1,1 +0,1727 @@

import{a as e,b as f,c as g,d as h,e as i,f as j,g as k,h as l,i as m,j as n,k as o}from"./chunk-5MN3W4J2.js";import{a,b,c,d}from"./chunk-24ATAN64.js";import"./chunk-AFSYT2WA.js";import"./chunk-CTAYYLOC.js";import"./chunk-NDS2DDJC.js";export{f as CloseRequestedEvent,k as Effect,l as EffectState,c as LogicalPosition,a as LogicalSize,d as PhysicalPosition,b as PhysicalSize,g as ProgressBarStatus,e as UserAttentionType,j as Window,o as availableMonitors,m as currentMonitor,i as getAll,h as getCurrent,n as primaryMonitor};
import { PhysicalPosition, PhysicalSize } from './dpi.js';
export { LogicalPosition, LogicalSize } from './dpi.js';
import { listen, once, emit, TauriEvent } from './event.js';
import { invoke } from './primitives.js';
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
/**
* Provides APIs to create windows, communicate with other windows and manipulate the current window.
*
* ## Window events
*
* Events can be listened to using {@link Window.listen}:
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* getCurrent().listen("my-window-event", ({ event, payload }) => { });
* ```
*
* @module
*/
/**
* Attention type to request on a window.
*
* @since 1.0.0
*/
var UserAttentionType;
(function (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.
*/
UserAttentionType[UserAttentionType["Critical"] = 1] = "Critical";
/**
* #### Platform-specific
* - **macOS:** Bounces the dock icon once.
* - **Windows:** Flashes the taskbar button until the application is in focus.
*/
UserAttentionType[UserAttentionType["Informational"] = 2] = "Informational";
})(UserAttentionType || (UserAttentionType = {}));
class CloseRequestedEvent {
constructor(event) {
this._preventDefault = false;
this.event = event.event;
this.windowLabel = event.windowLabel;
this.id = event.id;
}
preventDefault() {
this._preventDefault = true;
}
isPreventDefault() {
return this._preventDefault;
}
}
var ProgressBarStatus;
(function (ProgressBarStatus) {
/**
* Hide progress bar.
*/
ProgressBarStatus["None"] = "none";
/**
* Normal state.
*/
ProgressBarStatus["Normal"] = "normal";
/**
* Indeterminate state. **Treated as Normal on Linux and macOS**
*/
ProgressBarStatus["Indeterminate"] = "indeterminate";
/**
* Paused state. **Treated as Normal on Linux**
*/
ProgressBarStatus["Paused"] = "paused";
/**
* Error state. **Treated as Normal on linux**
*/
ProgressBarStatus["Error"] = "error";
})(ProgressBarStatus || (ProgressBarStatus = {}));
/**
* Get an instance of `Window` for the current window.
*
* @since 1.0.0
*/
function getCurrent() {
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
});
}
/**
* Gets a list of instances of `Window` for all available windows.
*
* @since 1.0.0
*/
function getAll() {
return window.__TAURI_INTERNALS__.metadata.windows.map((w) => new Window(w.label, {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
skip: true
}));
}
/** @ignore */
// events that are emitted right here instead of by the created webview
const localTauriEvents = ['tauri://created', 'tauri://error'];
/**
* Create new webview window or get a handle to an existing one.
*
* Windows are identified by a *label* a unique identifier that can be used to reference it later.
* It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`.
*
* @example
* ```typescript
* // loading embedded asset:
* const appWindow = new Window('theUniqueLabel', {
* url: 'path/to/page.html'
* });
* // alternatively, load a remote URL:
* const appWindow = new Window('theUniqueLabel', {
* url: 'https://github.com/tauri-apps/tauri'
* });
*
* 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 backend
* await appWindow.emit("some event", "data");
* // listen to an event from the backend
* const unlisten = await appWindow.listen("event name", e => {});
* unlisten();
* ```
*
* @since 2.0.0
*/
class Window {
/**
* Creates a new Window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const appWindow = new Window('my-label', {
* url: 'https://github.com/tauri-apps/tauri'
* });
* appWindow.once('tauri://created', function () {
* // window successfully created
* });
* appWindow.once('tauri://error', function (e) {
* // an error happened creating the window
* });
* ```
*
* @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`.
* @returns The {@link Window} instance to communicate with the webview.
*/
constructor(label, options = {}) {
this.label = label;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
this.listeners = Object.create(null);
// @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions
if (!options?.skip) {
invoke('plugin:window|create', {
options: {
...options,
label
}
})
.then(async () => this.emit('tauri://created'))
.catch(async (e) => this.emit('tauri://error', e));
}
}
/**
* Gets the Window for the webview associated with the given label.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const mainWindow = Window.getByLabel('main');
* ```
*
* @param label The webview window label.
* @returns The Window instance to communicate with the webview or null if the webview doesn't exist.
*/
static getByLabel(label) {
if (getAll().some((w) => w.label === label)) {
// @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor
return new Window(label, { skip: true });
}
return null;
}
/**
* Get an instance of `Window` for the current window.
*/
static getCurrent() {
return getCurrent();
}
/**
* Gets a list of instances of `Window` for all available windows.
*/
static getAll() {
return getAll();
}
/**
* Gets the focused window.
* @example
* ```typescript
* import { Window } from '@tauri-apps/api/window';
* const focusedWindow = Window.getFocusedWindow();
* ```
*
* @returns The Window instance to communicate with the webview or `undefined` if there is not any focused window.
*/
static async getFocusedWindow() {
for (const w of getAll()) {
if (await w.isFocused()) {
return w;
}
}
return null;
}
/**
* Listen to an event emitted by the backend that is tied to the webview window.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().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();
* ```
*
* @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.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
async listen(event, handler) {
if (this._handleTauriEvent(event, handler)) {
return Promise.resolve(() => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, security/detect-object-injection
const listeners = this.listeners[event];
listeners.splice(listeners.indexOf(handler), 1);
});
}
return listen(event, handler, { target: this.label });
}
/**
* Listen to an one-off event emitted by the backend that is tied to the webview window.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const unlisten = await getCurrent().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();
* ```
*
* @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.
* Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted.
*/
async once(event, handler) {
if (this._handleTauriEvent(event, handler)) {
return Promise.resolve(() => {
// eslint-disable-next-line security/detect-object-injection
const listeners = this.listeners[event];
listeners.splice(listeners.indexOf(handler), 1);
});
}
return once(event, handler, { target: this.label });
}
/**
* Emits an event to the backend, tied to the webview window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' });
* ```
*
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`.
* @param payload Event payload.
*/
async emit(event, payload) {
if (localTauriEvents.includes(event)) {
// eslint-disable-next-line
for (const handler of this.listeners[event] || []) {
handler({ event, id: -1, windowLabel: this.label, payload });
}
return Promise.resolve();
}
return emit(event, payload, { target: this.label });
}
/** @ignore */
_handleTauriEvent(event, handler) {
if (localTauriEvents.includes(event)) {
if (!(event in this.listeners)) {
// eslint-disable-next-line
this.listeners[event] = [handler];
}
else {
// eslint-disable-next-line
this.listeners[event].push(handler);
}
return true;
}
return false;
}
// Getters
/**
* 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();
* ```
*
* @returns The window's monitor scale factor.
*/
async scaleFactor() {
return invoke('plugin:window|scale_factor', {
label: this.label
});
}
/**
* 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();
* ```
*
* @returns The window's inner position.
*/
async innerPosition() {
return invoke('plugin:window|inner_position', {
label: this.label
}).then(({ x, y }) => new PhysicalPosition(x, y));
}
/**
* 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();
* ```
*
* @returns The window's outer position.
*/
async outerPosition() {
return invoke('plugin:window|outer_position', {
label: this.label
}).then(({ x, y }) => new PhysicalPosition(x, y));
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().innerSize();
* ```
*
* @returns The window's inner size.
*/
async innerSize() {
return invoke('plugin:window|inner_size', {
label: this.label
}).then(({ width, height }) => new PhysicalSize(width, height));
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* const size = await getCurrent().outerSize();
* ```
*
* @returns The window's outer size.
*/
async outerSize() {
return invoke('plugin:window|outer_size', {
label: this.label
}).then(({ width, height }) => new PhysicalSize(width, height));
}
/**
* Gets the window's current fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const fullscreen = await getCurrent().isFullscreen();
* ```
*
* @returns Whether the window is in fullscreen mode or not.
*/
async isFullscreen() {
return invoke('plugin:window|is_fullscreen', {
label: this.label
});
}
/**
* Gets the window's current minimized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimized = await getCurrent().isMinimized();
* ```
*/
async isMinimized() {
return invoke('plugin:window|is_minimized', {
label: this.label
});
}
/**
* Gets the window's current maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximized = await getCurrent().isMaximized();
* ```
*
* @returns Whether the window is maximized or not.
*/
async isMaximized() {
return invoke('plugin:window|is_maximized', {
label: this.label
});
}
/**
* Gets the window's current focus state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const focused = await getCurrent().isFocused();
* ```
*
* @returns Whether the window is focused or not.
*/
async isFocused() {
return invoke('plugin:window|is_focused', {
label: this.label
});
}
/**
* Gets the window's current decorated state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const decorated = await getCurrent().isDecorated();
* ```
*
* @returns Whether the window is decorated or not.
*/
async isDecorated() {
return invoke('plugin:window|is_decorated', {
label: this.label
});
}
/**
* Gets the window's current resizable state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const resizable = await getCurrent().isResizable();
* ```
*
* @returns Whether the window is resizable or not.
*/
async isResizable() {
return invoke('plugin:window|is_resizable', {
label: this.label
});
}
/**
* Gets the window’s native maximize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const maximizable = await getCurrent().isMaximizable();
* ```
*
* @returns Whether the window's native maximize button is enabled or not.
*/
async isMaximizable() {
return invoke('plugin:window|is_maximizable', {
label: this.label
});
}
/**
* Gets the window’s native minimize button state.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const minimizable = await getCurrent().isMinimizable();
* ```
*
* @returns Whether the window's native minimize button is enabled or not.
*/
async isMinimizable() {
return invoke('plugin:window|is_minimizable', {
label: this.label
});
}
/**
* Gets the window’s native close button state.
*
* #### Platform-specific
*
* - **iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const closable = await getCurrent().isClosable();
* ```
*
* @returns Whether the window's native close button is enabled or not.
*/
async isClosable() {
return invoke('plugin:window|is_closable', {
label: this.label
});
}
/**
* Gets the window's current visible state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const visible = await getCurrent().isVisible();
* ```
*
* @returns Whether the window is visible or not.
*/
async isVisible() {
return invoke('plugin:window|is_visible', {
label: this.label
});
}
/**
* Gets the window's current title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* const title = await getCurrent().title();
* ```
*/
async title() {
return invoke('plugin:window|title', {
label: this.label
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* const theme = await getCurrent().theme();
* ```
*
* @returns The window theme.
*/
async theme() {
return invoke('plugin:window|theme', {
label: this.label
});
}
// Setters
/**
* Centers the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().center();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async center() {
return invoke('plugin:window|center', {
label: this.label
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().requestUserAttention();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async requestUserAttention(requestType) {
let requestType_ = null;
if (requestType) {
if (requestType === UserAttentionType.Critical) {
requestType_ = { type: 'Critical' };
}
else {
requestType_ = { type: 'Informational' };
}
}
return invoke('plugin:window|request_user_attention', {
label: this.label,
value: requestType_
});
}
/**
* Updates the window resizable flag.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setResizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setResizable(resizable) {
return invoke('plugin:window|set_resizable', {
label: this.label,
value: resizable
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMaximizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setMaximizable(maximizable) {
return invoke('plugin:window|set_maximizable', {
label: this.label,
value: maximizable
});
}
/**
* Sets whether the window's native minimize button is enabled or not.
*
* #### Platform-specific
*
* - **Linux / iOS / Android:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setMinimizable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setMinimizable(minimizable) {
return invoke('plugin:window|set_minimizable', {
label: this.label,
value: minimizable
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setClosable(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setClosable(closable) {
return invoke('plugin:window|set_closable', {
label: this.label,
value: closable
});
}
/**
* Sets the window title.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setTitle('Tauri');
* ```
*
* @param title The new title
* @returns A promise indicating the success or failure of the operation.
*/
async setTitle(title) {
return invoke('plugin:window|set_title', {
label: this.label,
value: title
});
}
/**
* Maximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().maximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async maximize() {
return invoke('plugin:window|maximize', {
label: this.label
});
}
/**
* Unmaximizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unmaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async unmaximize() {
return invoke('plugin:window|unmaximize', {
label: this.label
});
}
/**
* Toggles the window maximized state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().toggleMaximize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async toggleMaximize() {
return invoke('plugin:window|toggle_maximize', {
label: this.label
});
}
/**
* Minimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().minimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async minimize() {
return invoke('plugin:window|minimize', {
label: this.label
});
}
/**
* Unminimizes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().unminimize();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async unminimize() {
return invoke('plugin:window|unminimize', {
label: this.label
});
}
/**
* Sets the window visibility to true.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().show();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async show() {
return invoke('plugin:window|show', {
label: this.label
});
}
/**
* Sets the window visibility to false.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().hide();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async hide() {
return invoke('plugin:window|hide', {
label: this.label
});
}
/**
* Closes the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().close();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async close() {
return invoke('plugin:window|close', {
label: this.label
});
}
/**
* Whether the window should have borders and bars.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setDecorations(false);
* ```
*
* @param decorations Whether the window should have borders and bars.
* @returns A promise indicating the success or failure of the operation.
*/
async setDecorations(decorations) {
return invoke('plugin:window|set_decorations', {
label: this.label,
value: decorations
});
}
/**
* Whether or not the window should have shadow.
*
* #### Platform-specific
*
* - **Windows:**
* - `false` has no effect on decorated window, shadows are always ON.
* - `true` will make ndecorated window have a 1px white border,
* and on Windows 11, it will have a rounded corners.
* - **Linux:** Unsupported.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setShadow(false);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setShadow(enable) {
return invoke('plugin:window|set_shadow', {
label: this.label,
value: enable
});
}
/**
* Set window effects.
*/
async setEffects(effects) {
return invoke('plugin:window|set_effects', {
label: this.label,
value: effects
});
}
/**
* Clear any applied effects if possible.
*/
async clearEffects() {
return invoke('plugin:window|set_effects', {
label: this.label,
value: null
});
}
/**
* Whether the window should always be on top of other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setAlwaysOnTop(alwaysOnTop) {
return invoke('plugin:window|set_always_on_top', {
label: this.label,
value: alwaysOnTop
});
}
/**
* Whether the window should always be below other windows.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setAlwaysOnBottom(true);
* ```
*
* @param alwaysOnBottom Whether the window should always be below other windows or not.
* @returns A promise indicating the success or failure of the operation.
*/
async setAlwaysOnBottom(alwaysOnBottom) {
return invoke('plugin:window|set_always_on_bottom', {
label: this.label,
value: alwaysOnBottom
});
}
/**
* Prevents the window contents from being captured by other apps.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setContentProtected(true);
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setContentProtected(protected_) {
return invoke('plugin:window|set_content_protected', {
label: this.label,
value: protected_
});
}
/**
* 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));
* ```
*
* @param size The logical or physical inner size.
* @returns A promise indicating the success or failure of the operation.
*/
async setSize(size) {
if (!size || (size.type !== 'Logical' && size.type !== 'Physical')) {
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
}
return invoke('plugin:window|set_size', {
label: this.label,
value: {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
});
}
/**
* 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));
* ```
*
* @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.
*/
async setMinSize(size) {
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
}
return invoke('plugin:window|set_min_size', {
label: this.label,
value: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
});
}
/**
* 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));
* ```
*
* @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.
*/
async setMaxSize(size) {
if (size && size.type !== 'Logical' && size.type !== 'Physical') {
throw new Error('the `size` argument must be either a LogicalSize or a PhysicalSize instance');
}
return invoke('plugin:window|set_max_size', {
label: this.label,
value: size
? {
type: size.type,
data: {
width: size.width,
height: size.height
}
}
: null
});
}
/**
* Sets the window outer position.
* @example
* ```typescript
* import { getCurrent, LogicalPosition } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setPosition(position) {
if (!position ||
(position.type !== 'Logical' && position.type !== 'Physical')) {
throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
}
return invoke('plugin:window|set_position', {
label: this.label,
value: {
type: position.type,
data: {
x: position.x,
y: position.y
}
}
});
}
/**
* Sets the window fullscreen state.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setFullscreen(true);
* ```
*
* @param fullscreen Whether the window should go to fullscreen or not.
* @returns A promise indicating the success or failure of the operation.
*/
async setFullscreen(fullscreen) {
return invoke('plugin:window|set_fullscreen', {
label: this.label,
value: fullscreen
});
}
/**
* Bring the window to front and focus.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setFocus();
* ```
*
* @returns A promise indicating the success or failure of the operation.
*/
async setFocus() {
return invoke('plugin:window|set_focus', {
label: this.label
});
}
/**
* Sets the window icon.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setIcon(icon) {
return invoke('plugin:window|set_icon', {
label: this.label,
value: typeof icon === 'string' ? icon : Array.from(icon)
});
}
/**
* Whether the window icon should be hidden from the taskbar or not.
*
* #### Platform-specific
*
* - **macOS:** Unsupported.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setSkipTaskbar(true);
* ```
*
* @param skip true to hide window icon, false to show it.
* @returns A promise indicating the success or failure of the operation.
*/
async setSkipTaskbar(skip) {
return invoke('plugin:window|set_skip_taskbar', {
label: this.label,
value: skip
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setCursorGrab(grab) {
return invoke('plugin:window|set_cursor_grab', {
label: this.label,
value: grab
});
}
/**
* 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 { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setCursorVisible(visible) {
return invoke('plugin:window|set_cursor_visible', {
label: this.label,
value: visible
});
}
/**
* Modifies the cursor icon of the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().setCursorIcon('help');
* ```
*
* @param icon The new cursor icon.
* @returns A promise indicating the success or failure of the operation.
*/
async setCursorIcon(icon) {
return invoke('plugin:window|set_cursor_icon', {
label: this.label,
value: icon
});
}
/**
* 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));
* ```
*
* @param position The new cursor position.
* @returns A promise indicating the success or failure of the operation.
*/
async setCursorPosition(position) {
if (!position ||
(position.type !== 'Logical' && position.type !== 'Physical')) {
throw new Error('the `position` argument must be either a LogicalPosition or a PhysicalPosition instance');
}
return invoke('plugin:window|set_cursor_position', {
label: this.label,
value: {
type: position.type,
data: {
x: position.x,
y: position.y
}
}
});
}
/**
* Changes the cursor events behavior.
*
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().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.
*/
async setIgnoreCursorEvents(ignore) {
return invoke('plugin:window|set_ignore_cursor_events', {
label: this.label,
value: ignore
});
}
/**
* Starts dragging the window.
* @example
* ```typescript
* import { getCurrent } from '@tauri-apps/api/window';
* await getCurrent().startDragging();
* ```
*
* @return A promise indicating the success or failure of the operation.
*/
async startDragging() {
return invoke('plugin:window|start_dragging', {
label: this.label
});
}
/**
* Sets the taskbar progress state.
*
* #### Platform-specific
*
* - **Linux / macOS**: Progress bar is app-wide and not specific to this window.
* - **Linux**: Only supported desktop environments with `libunity` (e.g. GNOME).
*
* @example
* ```typescript
* import { getCurrent, ProgressBarStatus } from '@tauri-apps/api/window';
* await getCurrent().setProgressBar({
* status: ProgressBarStatus.Normal,
* progress: 50,
* });
* ```
*
* @return A promise indicating the success or failure of the operation.
*/
async setProgressBar(state) {
return invoke('plugin:window|set_progress_bar', {
label: this.label,
value: state
});
}
// Listeners
/**
* Listen to window resize.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onResized(handler) {
return this.listen(TauriEvent.WINDOW_RESIZED, (e) => {
e.payload = mapPhysicalSize(e.payload);
handler(e);
});
}
/**
* Listen to window move.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onMoved(handler) {
return this.listen(TauriEvent.WINDOW_MOVED, (e) => {
e.payload = mapPhysicalPosition(e.payload);
handler(e);
});
}
/**
* Listen to window close requested. Emitted when the user requests to closes the window.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* import { confirm } from '@tauri-apps/api/dialog';
* const unlisten = await getCurrent().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.
*/
/* eslint-disable @typescript-eslint/promise-function-async */
async onCloseRequested(handler) {
return this.listen(TauriEvent.WINDOW_CLOSE_REQUESTED, (event) => {
const evt = new CloseRequestedEvent(event);
void Promise.resolve(handler(evt)).then(() => {
if (!evt.isPreventDefault()) {
return this.close();
}
});
});
}
/* eslint-enable */
/**
* Listen to window focus change.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onFocusChanged(handler) {
const unlistenFocus = await this.listen(TauriEvent.WINDOW_FOCUS, (event) => {
handler({ ...event, payload: true });
});
const unlistenBlur = await this.listen(TauriEvent.WINDOW_BLUR, (event) => {
handler({ ...event, payload: false });
});
return () => {
unlistenFocus();
unlistenBlur();
};
}
/**
* 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 { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onScaleChanged(handler) {
return this.listen(TauriEvent.WINDOW_SCALE_FACTOR_CHANGED, handler);
}
/**
* Listen to the window menu item click. The payload is the item id.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onMenuClicked(handler) {
return this.listen(TauriEvent.MENU, handler);
}
/**
* 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 { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onFileDropEvent(handler) {
const unlistenFileDrop = await this.listen(TauriEvent.WINDOW_FILE_DROP, (event) => {
handler({ ...event, payload: { type: 'drop', paths: event.payload } });
});
const unlistenFileHover = await this.listen(TauriEvent.WINDOW_FILE_DROP_HOVER, (event) => {
handler({ ...event, payload: { type: 'hover', paths: event.payload } });
});
const unlistenCancel = await this.listen(TauriEvent.WINDOW_FILE_DROP_CANCELLED, (event) => {
handler({ ...event, payload: { type: 'cancel' } });
});
return () => {
unlistenFileDrop();
unlistenFileHover();
unlistenCancel();
};
}
/**
* Listen to the system theme change.
*
* @example
* ```typescript
* import { getCurrent } from "@tauri-apps/api/window";
* const unlisten = await getCurrent().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.
*/
async onThemeChanged(handler) {
return this.listen(TauriEvent.WINDOW_THEME_CHANGED, handler);
}
}
/**
* Platform-specific window effects
*
* @since 2.0.0
*/
var Effect;
(function (Effect) {
/**
* A default material appropriate for the view's effectiveAppearance. **macOS 10.14-**
*
* @deprecated since macOS 10.14. You should instead choose an appropriate semantic material.
*/
Effect["AppearanceBased"] = "appearanceBased";
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Effect["Light"] = "light";
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Effect["Dark"] = "dark";
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Effect["MediumLight"] = "mediumLight";
/**
* **macOS 10.14-**
*
* @deprecated since macOS 10.14. Use a semantic material instead.
*/
Effect["UltraDark"] = "ultraDark";
/**
* **macOS 10.10+**
*/
Effect["Titlebar"] = "titlebar";
/**
* **macOS 10.10+**
*/
Effect["Selection"] = "selection";
/**
* **macOS 10.11+**
*/
Effect["Menu"] = "menu";
/**
* **macOS 10.11+**
*/
Effect["Popover"] = "popover";
/**
* **macOS 10.11+**
*/
Effect["Sidebar"] = "sidebar";
/**
* **macOS 10.14+**
*/
Effect["HeaderView"] = "headerView";
/**
* **macOS 10.14+**
*/
Effect["Sheet"] = "sheet";
/**
* **macOS 10.14+**
*/
Effect["WindowBackground"] = "windowBackground";
/**
* **macOS 10.14+**
*/
Effect["HudWindow"] = "hudWindow";
/**
* **macOS 10.14+**
*/
Effect["FullScreenUI"] = "fullScreenUI";
/**
* **macOS 10.14+**
*/
Effect["Tooltip"] = "tooltip";
/**
* **macOS 10.14+**
*/
Effect["ContentBackground"] = "contentBackground";
/**
* **macOS 10.14+**
*/
Effect["UnderWindowBackground"] = "underWindowBackground";
/**
* **macOS 10.14+**
*/
Effect["UnderPageBackground"] = "underPageBackground";
/**
* **Windows 11 Only**
*/
Effect["Mica"] = "mica";
/**
* **Windows 7/10/11(22H1) Only**
*
* ## Notes
*
* This effect has bad performance when resizing/dragging the window on Windows 11 build 22621.
*/
Effect["Blur"] = "blur";
/**
* **Windows 10/11**
*
* ## Notes
*
* This effect has bad performance when resizing/dragging the window on Windows 10 v1903+ and Windows 11 build 22000.
*/
Effect["Acrylic"] = "acrylic";
/**
* Tabbed effect that matches the system dark perefence **Windows 11 Only**
*/
Effect["Tabbed"] = "tabbed";
/**
* Tabbed effect with dark mode but only if dark mode is enabled on the system **Windows 11 Only**
*/
Effect["TabbedDark"] = "tabbedDark";
/**
* Tabbed effect with light mode **Windows 11 Only**
*/
Effect["TabbedLight"] = "tabbedLight";
})(Effect || (Effect = {}));
/**
* Window effect state **macOS only**
*
* @see https://developer.apple.com/documentation/appkit/nsvisualeffectview/state
*
* @since 2.0.0
*/
var EffectState;
(function (EffectState) {
/**
* Make window effect state follow the window's active state **macOS only**
*/
EffectState["FollowsWindowActiveState"] = "followsWindowActiveState";
/**
* Make window effect state always active **macOS only**
*/
EffectState["Active"] = "active";
/**
* Make window effect state always inactive **macOS only**
*/
EffectState["Inactive"] = "inactive";
})(EffectState || (EffectState = {}));
function mapMonitor(m) {
return m === null
? null
: {
name: m.name,
scaleFactor: m.scaleFactor,
position: mapPhysicalPosition(m.position),
size: mapPhysicalSize(m.size)
};
}
function mapPhysicalPosition(m) {
return new PhysicalPosition(m.x, m.y);
}
function mapPhysicalSize(m) {
return new PhysicalSize(m.width, m.height);
}
/**
* 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
*/
async function currentMonitor() {
return invoke('plugin:window|current_monitor').then(mapMonitor);
}
/**
* 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
*/
async function primaryMonitor() {
return invoke('plugin:window|primary_monitor').then(mapMonitor);
}
/**
* 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
*/
async function availableMonitors() {
return invoke('plugin:window|available_monitors').then((ms) => ms.map(mapMonitor));
}
export { CloseRequestedEvent, Effect, EffectState, PhysicalPosition, PhysicalSize, ProgressBarStatus, UserAttentionType, Window, availableMonitors, currentMonitor, getAll, getCurrent, primaryMonitor };

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc