diff --git a/.changes/window-plugin-refactor.md b/.changes/window-plugin-refactor.md new file mode 100644 index 00000000..000d4c23 --- /dev/null +++ b/.changes/window-plugin-refactor.md @@ -0,0 +1,10 @@ +--- +"window": "patch" +"window-js": "patch" +--- + +The window plugin is recieving a few changes to improve consistency and add new features: + +- Removed `appWindow` variable from JS module, use `getCurrent` or `Window.getCurrent`. +- Removed `WindowManager`, `WebviewWindow` and `WebviewHandle` types and merged them into one `Window` type that matches the name of the rust window type. +- Added `Window.getCurrent` and `Window.getAll` which is a convenient method for `getCurrent` and `getAll` functions. diff --git a/plugins/window/guest-js/index.ts b/plugins/window/guest-js/index.ts index f1ae5e0d..f6d34fe5 100644 --- a/plugins/window/guest-js/index.ts +++ b/plugins/window/guest-js/index.ts @@ -7,10 +7,10 @@ * * ## Window events * - * Events can be listened to using `appWindow.listen`: + * Events can be listened to using {@link Window.listen}: * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * appWindow.listen("my-window-event", ({ event, payload }) => { }); + * import { getCurrent } from "@tauri-apps/plugin-window"; + * getCurrent().listen("my-window-event", ({ event, payload }) => { }); * ``` * * @module @@ -104,7 +104,8 @@ class PhysicalSize { * Converts the physical size to a logical one. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; + * import { getCurrent } from '@tauri-apps/window'; + * const appWindow = getCurrent(); * const factor = await appWindow.scaleFactor(); * const size = await appWindow.innerSize(); * const logical = size.toLogical(factor); @@ -150,7 +151,8 @@ class PhysicalPosition { * Converts the physical position to a logical one. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; + * import { getCurrent } from '@tauri-apps/window'; + * const appWindow = getCurrent(); * const factor = await appWindow.scaleFactor(); * const position = await appWindow.innerPosition(); * const logical = position.toLogical(factor); @@ -196,6 +198,30 @@ enum UserAttentionType { Informational, } +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 = false; + + constructor(event: Event) { + this.event = event.event; + this.windowLabel = event.windowLabel; + this.id = event.id; + } + + preventDefault(): void { + this._preventDefault = true; + } + + isPreventDefault(): boolean { + return this._preventDefault; + } +} + export type CursorIcon = | "default" | "crosshair" @@ -238,26 +264,26 @@ export type CursorIcon = | "rowResize"; /** - * Get an instance of `WebviewWindow` for the current webview window. + * Get an instance of `Window` for the current window. * * @since 2.0.0 */ -function getCurrent(): WebviewWindow { - return new WebviewWindow(window.__TAURI_METADATA__.__currentWindow.label, { +function getCurrent(): Window { + return new Window(window.__TAURI_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 `WebviewWindow` for all available webview windows. + * Gets a list of instances of `Window` for all available windows. * * @since 2.0.0 */ -function getAll(): WebviewWindow[] { +function getAll(): Window[] { return window.__TAURI_METADATA__.__windows.map( (w) => - new WebviewWindow(w.label, { + new Window(w.label, { // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor skip: true, }) @@ -269,23 +295,123 @@ function getAll(): WebviewWindow[] { const localTauriEvents = ["tauri://created", "tauri://error"]; /** @ignore */ export type WindowLabel = string; + /** - * A webview window handle allows emitting and listening to events from the backend that are tied to the window. + * 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(); + * ``` * - * @ignore * @since 2.0.0 */ -class WebviewWindowHandle { +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. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any listeners: Record>>; - constructor(label: WindowLabel) { + /** + * Creates a new WebviewWindow. + * @example + * ```typescript + * import { Window } from '@tauri-apps/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. + * + * @since 2.0.0 + */ + constructor(label: WindowLabel, options: WindowOptions = {}) { 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) { + window + .__TAURI_INVOKE__("plugin:window|create", { + options: { + ...options, + label, + }, + }) + .then(async () => this.emit("tauri://created")) + .catch(async (e: string) => this.emit("tauri://error", e)); + } + } + + /** + * Gets the WebviewWindow for the webview associated with the given label. + * @example + * ```typescript + * import { WebviewWindow } from '@tauri-apps/window'; + * const mainWindow = WebviewWindow.getByLabel('main'); + * ``` + * + * @param label The webview window label. + * @returns The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist. + * + * @since 2.0.0 + */ + static getByLabel(label: string): Window | null { + 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 WebviewWindow(label, { skip: true }); + } + return null; + } + + /** + * Get an instance of `Window` for the current window. + * + * @since 2.0.0 + */ + static getCurrent(): Window { + return getCurrent(); + } + + /** + * Gets a list of instances of `Window` for all available windows. + * + * @since 2.0.0 + */ + static getAll(): Window[] { + return getAll(); } /** @@ -293,8 +419,8 @@ class WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const unlisten = await appWindow.listen('state-changed', (event) => { + * import { getCurrent } from '@tauri-apps/window'; + * const unlisten = await getCurrent().listen('state-changed', (event) => { * console.log(`Got error: ${payload}`); * }); * @@ -328,8 +454,8 @@ class WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const unlisten = await appWindow.once('initialized', (event) => { + * import { getCurrent } from '@tauri-apps/window'; + * const unlisten = await getCurrent().once('initialized', (event) => { * console.log(`Window initialized!`); * }); * @@ -359,8 +485,8 @@ class WebviewWindowHandle { * Emits an event to the backend, tied to the webview window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.emit('window-loaded', { loggedIn: true, token: 'authToken' }); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' }); * ``` * * @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. @@ -391,22 +517,14 @@ class WebviewWindowHandle { } return false; } -} -/** - * Manage the current window object. - * - * @ignore - * @since 2.0.0 - */ -class WindowManager extends WebviewWindowHandle { // Getters /** * The scale factor that can be used to map physical pixels to logical pixels. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const factor = await appWindow.scaleFactor(); + * import { getCurrent } from '@tauri-apps/window'; + * const factor = await getCurrent().scaleFactor(); * ``` * * @returns The window's monitor scale factor. @@ -423,8 +541,8 @@ class WindowManager extends WebviewWindowHandle { * The position of the top-left hand corner of the window's client area relative to the top-left hand corner of the desktop. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const position = await appWindow.innerPosition(); + * import { getCurrent } from '@tauri-apps/window'; + * const position = await getCurrent().innerPosition(); * ``` * * @returns The window's inner position. @@ -446,8 +564,8 @@ class WindowManager extends WebviewWindowHandle { * The position of the top-left hand corner of the window relative to the top-left hand corner of the desktop. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const position = await appWindow.outerPosition(); + * import { getCurrent } from '@tauri-apps/window'; + * const position = await getCurrent().outerPosition(); * ``` * * @returns The window's outer position. @@ -470,8 +588,8 @@ class WindowManager extends WebviewWindowHandle { * The client area is the content of the window, excluding the title bar and borders. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const size = await appWindow.innerSize(); + * import { getCurrent } from '@tauri-apps/window'; + * const size = await getCurrent().innerSize(); * ``` * * @returns The window's inner size. @@ -494,8 +612,8 @@ class WindowManager extends WebviewWindowHandle { * These dimensions include the title bar and borders. If you don't want that (and you usually don't), use inner_size instead. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const size = await appWindow.outerSize(); + * import { getCurrent } from '@tauri-apps/window'; + * const size = await getCurrent().outerSize(); * ``` * * @returns The window's outer size. @@ -517,8 +635,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current fullscreen state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const fullscreen = await appWindow.isFullscreen(); + * import { getCurrent } from '@tauri-apps/window'; + * const fullscreen = await getCurrent().isFullscreen(); * ``` * * @returns Whether the window is in fullscreen mode or not. @@ -535,8 +653,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current minimized state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const minimized = await appWindow.isMinimized(); + * import { getCurrent } from '@tauri-apps/window'; + * const minimized = await getCurrent().isMinimized(); * ``` * * @since 2.0.0 @@ -551,8 +669,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current maximized state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const maximized = await appWindow.isMaximized(); + * import { getCurrent } from '@tauri-apps/window'; + * const maximized = await getCurrent().isMaximized(); * ``` * * @returns Whether the window is maximized or not. @@ -569,8 +687,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current decorated state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const decorated = await appWindow.isDecorated(); + * import { getCurrent } from '@tauri-apps/window'; + * const decorated = await getCurrent().isDecorated(); * ``` * * @returns Whether the window is decorated or not. @@ -587,8 +705,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current resizable state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const resizable = await appWindow.isResizable(); + * import { getCurrent } from '@tauri-apps/window'; + * const resizable = await getCurrent().isResizable(); * ``` * * @returns Whether the window is resizable or not. @@ -605,8 +723,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current visible state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const visible = await appWindow.isVisible(); + * import { getCurrent } from '@tauri-apps/window'; + * const visible = await getCurrent().isVisible(); * ``` * * @returns Whether the window is visible or not. @@ -623,8 +741,8 @@ class WindowManager extends WebviewWindowHandle { * Gets the window's current title. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const title = await appWindow.title(); + * import { getCurrent } from '@tauri-apps/window'; + * const title = await getCurrent().title(); * ``` * * @since 2.0.0 @@ -644,8 +762,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * const theme = await appWindow.theme(); + * import { getCurrent } from '@tauri-apps/window'; + * const theme = await getCurrent().theme(); * ``` * * @returns The window theme. @@ -664,8 +782,8 @@ class WindowManager extends WebviewWindowHandle { * Centers the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.center(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().center(); * ``` * * @param resizable @@ -693,8 +811,8 @@ class WindowManager extends WebviewWindowHandle { * - **Linux:** Urgency levels have the same effect. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.requestUserAttention(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().requestUserAttention(); * ``` * * @param resizable @@ -724,8 +842,8 @@ class WindowManager extends WebviewWindowHandle { * Updates the window resizable flag. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setResizable(false); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setResizable(false); * ``` * * @param resizable @@ -744,8 +862,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window title. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setTitle('Tauri'); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setTitle('Tauri'); * ``` * * @param title The new title @@ -764,8 +882,8 @@ class WindowManager extends WebviewWindowHandle { * Maximizes the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.maximize(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().maximize(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -782,8 +900,8 @@ class WindowManager extends WebviewWindowHandle { * Unmaximizes the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.unmaximize(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().unmaximize(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -800,8 +918,8 @@ class WindowManager extends WebviewWindowHandle { * Toggles the window maximized state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.toggleMaximize(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().toggleMaximize(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -818,8 +936,8 @@ class WindowManager extends WebviewWindowHandle { * Minimizes the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.minimize(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().minimize(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -836,8 +954,8 @@ class WindowManager extends WebviewWindowHandle { * Unminimizes the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.unminimize(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().unminimize(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -854,8 +972,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window visibility to true. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.show(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().show(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -872,8 +990,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window visibility to false. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.hide(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().hide(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -890,8 +1008,8 @@ class WindowManager extends WebviewWindowHandle { * Closes the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.close(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().close(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -908,8 +1026,8 @@ class WindowManager extends WebviewWindowHandle { * Whether the window should have borders and bars. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setDecorations(false); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setDecorations(false); * ``` * * @param decorations Whether the window should have borders and bars. @@ -937,8 +1055,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setShadow(false); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setShadow(false); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -956,8 +1074,8 @@ class WindowManager extends WebviewWindowHandle { * Whether the window should always be on top of other windows. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setAlwaysOnTop(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setAlwaysOnTop(true); * ``` * * @param alwaysOnTop Whether the window should always be on top of other windows or not. @@ -976,8 +1094,8 @@ class WindowManager extends WebviewWindowHandle { * Prevents the window contents from being captured by other apps. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setContentProtected(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setContentProtected(true); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -995,8 +1113,8 @@ class WindowManager extends WebviewWindowHandle { * Resizes the window with a new inner size. * @example * ```typescript - * import { appWindow, LogicalSize } from '@tauri-apps/window'; - * await appWindow.setSize(new LogicalSize(600, 500)); + * import { getCurrent, LogicalSize } from '@tauri-apps/window'; + * await getCurrent().setSize(new LogicalSize(600, 500)); * ``` * * @param size The logical or physical inner size. @@ -1027,8 +1145,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window minimum inner size. If the `size` argument is not provided, the constraint is unset. * @example * ```typescript - * import { appWindow, PhysicalSize } from '@tauri-apps/window'; - * await appWindow.setMinSize(new PhysicalSize(600, 500)); + * import { getCurrent, PhysicalSize } from '@tauri-apps/window'; + * await getCurrent().setMinSize(new PhysicalSize(600, 500)); * ``` * * @param size The logical or physical inner size, or `null` to unset the constraint. @@ -1063,8 +1181,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window maximum inner size. If the `size` argument is undefined, the constraint is unset. * @example * ```typescript - * import { appWindow, LogicalSize } from '@tauri-apps/window'; - * await appWindow.setMaxSize(new LogicalSize(600, 500)); + * import { getCurrent, LogicalSize } from '@tauri-apps/window'; + * await getCurrent().setMaxSize(new LogicalSize(600, 500)); * ``` * * @param size The logical or physical inner size, or `null` to unset the constraint. @@ -1099,8 +1217,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window outer position. * @example * ```typescript - * import { appWindow, LogicalPosition } from '@tauri-apps/window'; - * await appWindow.setPosition(new LogicalPosition(600, 500)); + * import { getCurrent, LogicalPosition } from '@tauri-apps/window'; + * await getCurrent().setPosition(new LogicalPosition(600, 500)); * ``` * * @param position The new position, in logical or physical pixels. @@ -1136,8 +1254,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window fullscreen state. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setFullscreen(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setFullscreen(true); * ``` * * @param fullscreen Whether the window should go to fullscreen or not. @@ -1156,8 +1274,8 @@ class WindowManager extends WebviewWindowHandle { * Bring the window to front and focus. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setFocus(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setFocus(); * ``` * * @returns A promise indicating the success or failure of the operation. @@ -1174,8 +1292,8 @@ class WindowManager extends WebviewWindowHandle { * Sets the window icon. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setIcon('/tauri/awesome.png'); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setIcon('/tauri/awesome.png'); * ``` * * Note that you need the `icon-ico` or `icon-png` Cargo features to use this API. @@ -1205,8 +1323,8 @@ class WindowManager extends WebviewWindowHandle { * - **macOS:** Unsupported. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setSkipTaskbar(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setSkipTaskbar(true); * ``` * * @param skip true to hide window icon, false to show it. @@ -1233,8 +1351,8 @@ class WindowManager extends WebviewWindowHandle { * - **macOS:** This locks the cursor in a fixed location, which looks visually awkward. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setCursorGrab(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setCursorGrab(true); * ``` * * @param grab `true` to grab the cursor icon, `false` to release it. @@ -1259,8 +1377,8 @@ class WindowManager extends WebviewWindowHandle { * outside of the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setCursorVisible(false); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setCursorVisible(false); * ``` * * @param visible If `false`, this will hide the cursor. If `true`, this will show the cursor. @@ -1279,8 +1397,8 @@ class WindowManager extends WebviewWindowHandle { * Modifies the cursor icon of the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setCursorIcon('help'); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setCursorIcon('help'); * ``` * * @param icon The new cursor icon. @@ -1299,8 +1417,8 @@ class WindowManager extends WebviewWindowHandle { * Changes the position of the cursor in window coordinates. * @example * ```typescript - * import { appWindow, LogicalPosition } from '@tauri-apps/window'; - * await appWindow.setCursorPosition(new LogicalPosition(600, 300)); + * import { getCurrent, LogicalPosition } from '@tauri-apps/window'; + * await getCurrent().setCursorPosition(new LogicalPosition(600, 300)); * ``` * * @param position The new cursor position. @@ -1337,8 +1455,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.setIgnoreCursorEvents(true); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().setIgnoreCursorEvents(true); * ``` * * @param ignore `true` to ignore the cursor events; `false` to process them as usual. @@ -1357,8 +1475,8 @@ class WindowManager extends WebviewWindowHandle { * Starts dragging the window. * @example * ```typescript - * import { appWindow } from '@tauri-apps/window'; - * await appWindow.startDragging(); + * import { getCurrent } from '@tauri-apps/window'; + * await getCurrent().startDragging(); * ``` * * @return A promise indicating the success or failure of the operation. @@ -1378,8 +1496,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onResized(({ payload: size }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onResized(({ payload: size }) => { * console.log('Window resized', size); * }); * @@ -1404,8 +1522,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onMoved(({ payload: position }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onMoved(({ payload: position }) => { * console.log('Window moved', position); * }); * @@ -1430,9 +1548,9 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; + * import { getCurrent } from "@tauri-apps/plugin-window"; * import { confirm } from '@tauri-apps/api/dialog'; - * const unlisten = await appWindow.onCloseRequested(async (event) => { + * 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 @@ -1469,8 +1587,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onFocusChanged(({ payload: focused }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onFocusChanged(({ payload: focused }) => { * console.log('Focus changed, window is focused? ' + focused); * }); * @@ -1511,8 +1629,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onScaleChanged(({ payload }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onScaleChanged(({ payload }) => { * console.log('Scale changed', payload.scaleFactor, payload.size); * }); * @@ -1539,8 +1657,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onMenuClicked(({ payload: menuId }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onMenuClicked(({ payload: menuId }) => { * console.log('Menu clicked: ' + menuId); * }); * @@ -1564,8 +1682,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onFileDropEvent((event) => { + * import { getCurrent } from "@tauri-apps/plugin-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') { @@ -1620,8 +1738,8 @@ class WindowManager extends WebviewWindowHandle { * * @example * ```typescript - * import { appWindow } from "@tauri-apps/plugin-window"; - * const unlisten = await appWindow.onThemeChanged(({ payload: theme }) => { + * import { getCurrent } from "@tauri-apps/plugin-window"; + * const unlisten = await getCurrent().onThemeChanged(({ payload: theme }) => { * console.log('New theme: ' + theme); * }); * @@ -1639,146 +1757,6 @@ class WindowManager extends WebviewWindowHandle { } } -/** - * @since 2.0.0 - */ -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 = false; - - constructor(event: Event) { - this.event = event.event; - this.windowLabel = event.windowLabel; - this.id = event.id; - } - - preventDefault(): void { - this._preventDefault = true; - } - - isPreventDefault(): boolean { - return this._preventDefault; - } -} - -/** - * Create new webview windows and get a handle to existing ones. - * - * Windows are identified by a *label* a unique identifier that can be used to reference it later. - * It may only contain alphanumeric characters `a-zA-Z` plus the following special characters `-`, `/`, `:` and `_`. - * - * @example - * ```typescript - * // loading embedded asset: - * const webview = new WebviewWindow('theUniqueLabel', { - * url: 'path/to/page.html' - * }); - * // alternatively, load a remote URL: - * const webview = new WebviewWindow('theUniqueLabel', { - * url: 'https://github.com/tauri-apps/tauri' - * }); - * - * webview.once('tauri://created', function () { - * // webview window successfully created - * }); - * webview.once('tauri://error', function (e) { - * // an error happened creating the webview window - * }); - * - * // emit an event to the backend - * await webview.emit("some event", "data"); - * // listen to an event from the backend - * const unlisten = await webview.listen("event name", e => {}); - * unlisten(); - * ``` - * - * @since 2.0.0 - */ -class WebviewWindow extends WindowManager { - /** - * Creates a new WebviewWindow. - * @example - * ```typescript - * import { WebviewWindow } from '@tauri-apps/window'; - * const webview = new WebviewWindow('my-label', { - * url: 'https://github.com/tauri-apps/tauri' - * }); - * webview.once('tauri://created', function () { - * // webview window successfully created - * }); - * webview.once('tauri://error', function (e) { - * // an error happened creating the webview window - * }); - * ``` - * - * * @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`. - * @returns The WebviewWindow instance to communicate with the webview. - * - * @since 2.0.0 - */ - constructor(label: WindowLabel, options: WindowOptions = {}) { - super(label); - // @ts-expect-error `skip` is not a public API so it is not defined in WindowOptions - if (!options?.skip) { - window - .__TAURI_INVOKE__("plugin:window|create", { - options: { - ...options, - label, - }, - }) - .then(async () => this.emit("tauri://created")) - .catch(async (e: string) => this.emit("tauri://error", e)); - } - } - - /** - * Gets the WebviewWindow for the webview associated with the given label. - * @example - * ```typescript - * import { WebviewWindow } from '@tauri-apps/window'; - * const mainWindow = WebviewWindow.getByLabel('main'); - * ``` - * - * @param label The webview window label. - * @returns The WebviewWindow instance to communicate with the webview or null if the webview doesn't exist. - * - * @since 2.0.0 - */ - static getByLabel(label: string): WebviewWindow | null { - 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 WebviewWindow(label, { skip: true }); - } - return null; - } -} - -/** The WebviewWindow for the current window. */ -let appWindow: WebviewWindow; -if ("__TAURI_METADATA__" in window) { - appWindow = new WebviewWindow( - window.__TAURI_METADATA__.__currentWindow.label, - { - // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor - skip: true, - } - ); -} else { - console.warn( - `Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.` - ); - appWindow = new WebviewWindow("main", { - // @ts-expect-error `skip` is not defined in the public API but it is handled by the constructor - skip: true, - }); -} - /** * Configuration for the window to create. * @@ -1958,13 +1936,9 @@ async function availableMonitors(): Promise { } export { - WebviewWindow, - WebviewWindowHandle, - WindowManager, CloseRequestedEvent, getCurrent, getAll, - appWindow, LogicalSize, PhysicalSize, LogicalPosition, diff --git a/plugins/window/src/api-iife.js b/plugins/window/src/api-iife.js index ffa35ae0..73e827bf 100644 --- a/plugins/window/src/api-iife.js +++ b/plugins/window/src/api-iife.js @@ -1 +1 @@ -if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var n=Object.defineProperty,i=(e,i)=>{for(var t in i)n(e,t,{get:i[t],enumerable:!0})},t=(e,n,i)=>{if(!n.has(e))throw TypeError("Cannot "+i)},l=(e,n,i)=>(t(e,n,"read from private field"),i?i.call(e):n.get(e)),a=(e,n,i,l)=>(t(e,n,"write to private field"),l?l.call(e,i):n.set(e,i),i);function s(e,n=!1){let i=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${i}`;return Object.defineProperty(window,t,{value:i=>(n&&Reflect.deleteProperty(window,t),e?.(i)),writable:!1,configurable:!0}),i}i({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,i)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,i)})(this,r,(()=>{})),this.id=s((e=>{l(this,r).call(this,e)}))}set onmessage(e){a(this,r,e)}get onmessage(){return l(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,n,i){this.plugin=e,this.event=n,this.channelId=i}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,n,i){let t=new o;return t.onmessage=i,u(`plugin:${e}|register_listener`,{event:n,handler:t}).then((()=>new _(e,n,t.id)))}async function u(e,n={}){return new Promise(((i,t)=>{let l=s((e=>{i(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{t(e),Reflect.deleteProperty(window,`_${l}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:l,error:a,...n})}))}function c(e,n="asset"){let i=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${i}`:`${n}://localhost/${i}`}async function d(e,n){await u("plugin:event|unlisten",{event:e,eventId:n})}async function h(e,n,i){return u("plugin:event|listen",{event:e,windowLabel:n,handler:s(i)}).then((n=>async()=>d(e,n)))}i({},{TauriEvent:()=>I,emit:()=>E,listen:()=>b,once:()=>g});var p,y,I=((p=I||{}).WINDOW_RESIZED="tauri://resize",p.WINDOW_MOVED="tauri://move",p.WINDOW_CLOSE_REQUESTED="tauri://close-requested",p.WINDOW_CREATED="tauri://window-created",p.WINDOW_DESTROYED="tauri://destroyed",p.WINDOW_FOCUS="tauri://focus",p.WINDOW_BLUR="tauri://blur",p.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",p.WINDOW_THEME_CHANGED="tauri://theme-changed",p.WINDOW_FILE_DROP="tauri://file-drop",p.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",p.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",p.MENU="tauri://menu",p);async function b(e,n){return h(e,null,n)}async function g(e,n){return async function(e,n,i){return h(e,n,(n=>{i(n),d(e,n.id).catch((()=>{}))}))}(e,null,n)}async function E(e,n){return async function(e,n,i){await u("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,void 0,n)}async function A(e,n){await window.__TAURI_INVOKE__("plugin:event|unlisten",{event:e,eventId:n})}async function O(e,n,i){return window.__TAURI_INVOKE__("plugin:event|listen",{event:e,windowLabel:n,handler:window.__TAURI__.transformCallback(i)}).then((n=>async()=>A(e,n)))}class T{constructor(e,n){this.type="Logical",this.width=e,this.height=n}}class R{constructor(e,n){this.type="Physical",this.width=e,this.height=n}toLogical(e){return new T(this.width/e,this.height/e)}}class v{constructor(e,n){this.type="Logical",this.x=e,this.y=n}}class N{constructor(e,n){this.type="Physical",this.x=e,this.y=n}toLogical(e){return new v(this.x/e,this.y/e)}}function m(){return window.__TAURI_METADATA__.__windows.map((e=>new V(e.label,{skip:!0})))}e.UserAttentionType=void 0,(y=e.UserAttentionType||(e.UserAttentionType={}))[y.Critical=1]="Critical",y[y.Informational=2]="Informational";const U=["tauri://created","tauri://error"];class f{constructor(e){this.label=e,this.listeners=Object.create(null)}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):O(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):async function(e,n,i){return O(e,n,(n=>{i(n),A(e,n.id).catch((()=>{}))}))}(e,this.label,n)}async emit(e,n){if(U.includes(e)){for(const i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return async function(e,n,i){await window.__TAURI_INVOKE__("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,this.label,n)}_handleTauriEvent(e,n){return!!U.includes(e)&&(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0)}}class W extends f{async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:this.label}).then((({x:e,y:n})=>new N(e,n)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:n})=>new N(e,n)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:n})=>new R(e,n)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:n})=>new R(e,n)))}async isFullscreen(){return window.__TAURI_INVOKE__("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return window.__TAURI_INVOKE__("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return window.__TAURI_INVOKE__("plugin:window|is_maximized",{label:this.label})}async isDecorated(){return window.__TAURI_INVOKE__("plugin:window|is_decorated",{label:this.label})}async isResizable(){return window.__TAURI_INVOKE__("plugin:window|is_resizable",{label:this.label})}async isVisible(){return window.__TAURI_INVOKE__("plugin:window|is_visible",{label:this.label})}async title(){return window.__TAURI_INVOKE__("plugin:window|title",{label:this.label})}async theme(){return window.__TAURI_INVOKE__("plugin:window|theme",{label:this.label})}async center(){return window.__TAURI_INVOKE__("plugin:window|center",{label:this.label})}async requestUserAttention(n){let i=null;return n&&(i=n===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:i})}async setResizable(e){return window.__TAURI_INVOKE__("plugin:window|set_resizable",{label:this.label,value:e})}async setTitle(e){return window.__TAURI_INVOKE__("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return window.__TAURI_INVOKE__("plugin:window|maximize",{label:this.label})}async unmaximize(){return window.__TAURI_INVOKE__("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return window.__TAURI_INVOKE__("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return window.__TAURI_INVOKE__("plugin:window|minimize",{label:this.label})}async unminimize(){return window.__TAURI_INVOKE__("plugin:window|unminimize",{label:this.label})}async show(){return window.__TAURI_INVOKE__("plugin:window|show",{label:this.label})}async hide(){return window.__TAURI_INVOKE__("plugin:window|hide",{label:this.label})}async close(){return window.__TAURI_INVOKE__("plugin:window|close",{label:this.label})}async setDecorations(e){return window.__TAURI_INVOKE__("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return window.__TAURI_INVOKE__("plugin:window|set_shadow",{label:this.label,value:e})}async setAlwaysOnTop(e){return window.__TAURI_INVOKE__("plugin:window|set_always_on_top",{label:this.label,value:e})}async setContentProtected(e){return window.__TAURI_INVOKE__("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return window.__TAURI_INVOKE__("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return window.__TAURI_INVOKE__("plugin:window|set_focus",{label:this.label})}async setIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return window.__TAURI_INVOKE__("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return window.__TAURI_INVOKE__("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return window.__TAURI_INVOKE__("plugin:window|start_dragging",{label:this.label})}async onResized(e){return this.listen(I.WINDOW_RESIZED,(n=>{n.payload=C(n.payload),e(n)}))}async onMoved(e){return this.listen(I.WINDOW_MOVED,(n=>{n.payload=P(n.payload),e(n)}))}async onCloseRequested(e){return this.listen(I.WINDOW_CLOSE_REQUESTED,(n=>{const i=new D(n);Promise.resolve(e(i)).then((()=>{if(!i.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const n=await this.listen(I.WINDOW_FOCUS,(n=>{e({...n,payload:!0})})),i=await this.listen(I.WINDOW_BLUR,(n=>{e({...n,payload:!1})}));return()=>{n(),i()}}async onScaleChanged(e){return this.listen(I.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(I.MENU,e)}async onFileDropEvent(e){const n=await this.listen(I.WINDOW_FILE_DROP,(n=>{e({...n,payload:{type:"drop",paths:n.payload}})})),i=await this.listen(I.WINDOW_FILE_DROP_HOVER,(n=>{e({...n,payload:{type:"hover",paths:n.payload}})})),t=await this.listen(I.WINDOW_FILE_DROP_CANCELLED,(n=>{e({...n,payload:{type:"cancel"}})}));return()=>{n(),i(),t()}}async onThemeChanged(e){return this.listen(I.WINDOW_THEME_CHANGED,e)}}class D{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}class V extends W{constructor(e,n={}){super(e),(null==n?void 0:n.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...n,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return m().some((n=>n.label===e))?new V(e,{skip:!0}):null}}function K(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:P(e.position),size:C(e.size)}}function P(e){return new N(e.x,e.y)}function C(e){return new R(e.width,e.height)}return e.appWindow=void 0,"__TAURI_METADATA__"in window?e.appWindow=new V(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0}):(console.warn('Could not find "window.__TAURI_METADATA__". The "appWindow" value will reference the "main" window label.\nNote that this is not an issue if running this frontend on a browser instead of a Tauri window.'),e.appWindow=new V("main",{skip:!0})),e.CloseRequestedEvent=D,e.LogicalPosition=v,e.LogicalSize=T,e.PhysicalPosition=N,e.PhysicalSize=R,e.WebviewWindow=V,e.WebviewWindowHandle=f,e.WindowManager=W,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(K)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(K)},e.getAll=m,e.getCurrent=function(){return new V(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})},e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(K)},e}({});Object.defineProperty(window.__TAURI__,"window",{value:__TAURI_WINDOW__})} +if("__TAURI__"in window){var __TAURI_WINDOW__=function(e){"use strict";var n=Object.defineProperty,i=(e,i)=>{for(var t in i)n(e,t,{get:i[t],enumerable:!0})},t=(e,n,i)=>{if(!n.has(e))throw TypeError("Cannot "+i)},l=(e,n,i)=>(t(e,n,"read from private field"),i?i.call(e):n.get(e)),a=(e,n,i,l)=>(t(e,n,"write to private field"),l?l.call(e,i):n.set(e,i),i);function s(e,n=!1){let i=window.crypto.getRandomValues(new Uint32Array(1))[0],t=`_${i}`;return Object.defineProperty(window,t,{value:i=>(n&&Reflect.deleteProperty(window,t),e?.(i)),writable:!1,configurable:!0}),i}i({},{Channel:()=>o,PluginListener:()=>_,addPluginListener:()=>w,convertFileSrc:()=>c,invoke:()=>u,transformCallback:()=>s});var r,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,n,i)=>{if(n.has(e))throw TypeError("Cannot add the same private member more than once");n instanceof WeakSet?n.add(e):n.set(e,i)})(this,r,(()=>{})),this.id=s((e=>{l(this,r).call(this,e)}))}set onmessage(e){a(this,r,e)}get onmessage(){return l(this,r)}toJSON(){return`__CHANNEL__:${this.id}`}};r=new WeakMap;var _=class{constructor(e,n,i){this.plugin=e,this.event=n,this.channelId=i}async unregister(){return u(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function w(e,n,i){let t=new o;return t.onmessage=i,u(`plugin:${e}|register_listener`,{event:n,handler:t}).then((()=>new _(e,n,t.id)))}async function u(e,n={}){return new Promise(((i,t)=>{let l=s((e=>{i(e),Reflect.deleteProperty(window,`_${a}`)}),!0),a=s((e=>{t(e),Reflect.deleteProperty(window,`_${l}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:l,error:a,...n})}))}function c(e,n="asset"){let i=encodeURIComponent(e);return navigator.userAgent.includes("Windows")?`https://${n}.localhost/${i}`:`${n}://localhost/${i}`}async function d(e,n){await u("plugin:event|unlisten",{event:e,eventId:n})}async function h(e,n,i){return u("plugin:event|listen",{event:e,windowLabel:n,handler:s(i)}).then((n=>async()=>d(e,n)))}i({},{TauriEvent:()=>I,emit:()=>E,listen:()=>b,once:()=>g});var y,p,I=((y=I||{}).WINDOW_RESIZED="tauri://resize",y.WINDOW_MOVED="tauri://move",y.WINDOW_CLOSE_REQUESTED="tauri://close-requested",y.WINDOW_CREATED="tauri://window-created",y.WINDOW_DESTROYED="tauri://destroyed",y.WINDOW_FOCUS="tauri://focus",y.WINDOW_BLUR="tauri://blur",y.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",y.WINDOW_THEME_CHANGED="tauri://theme-changed",y.WINDOW_FILE_DROP="tauri://file-drop",y.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",y.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",y.MENU="tauri://menu",y);async function b(e,n){return h(e,null,n)}async function g(e,n){return async function(e,n,i){return h(e,n,(n=>{i(n),d(e,n.id).catch((()=>{}))}))}(e,null,n)}async function E(e,n){return async function(e,n,i){await u("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,void 0,n)}async function O(e,n){await window.__TAURI_INVOKE__("plugin:event|unlisten",{event:e,eventId:n})}async function A(e,n,i){return window.__TAURI_INVOKE__("plugin:event|listen",{event:e,windowLabel:n,handler:window.__TAURI__.transformCallback(i)}).then((n=>async()=>O(e,n)))}class R{constructor(e,n){this.type="Logical",this.width=e,this.height=n}}class N{constructor(e,n){this.type="Physical",this.width=e,this.height=n}toLogical(e){return new R(this.width/e,this.height/e)}}class v{constructor(e,n){this.type="Logical",this.x=e,this.y=n}}class T{constructor(e,n){this.type="Physical",this.x=e,this.y=n}toLogical(e){return new v(this.x/e,this.y/e)}}e.UserAttentionType=void 0,(p=e.UserAttentionType||(e.UserAttentionType={}))[p.Critical=1]="Critical",p[p.Informational=2]="Informational";class m{constructor(e){this._preventDefault=!1,this.event=e.event,this.windowLabel=e.windowLabel,this.id=e.id}preventDefault(){this._preventDefault=!0}isPreventDefault(){return this._preventDefault}}function U(){return new V(window.__TAURI_METADATA__.__currentWindow.label,{skip:!0})}function f(){return window.__TAURI_METADATA__.__windows.map((e=>new V(e.label,{skip:!0})))}const D=["tauri://created","tauri://error"];class V{constructor(e,n={}){this.label=e,this.listeners=Object.create(null),(null==n?void 0:n.skip)||window.__TAURI_INVOKE__("plugin:window|create",{options:{...n,label:e}}).then((async()=>this.emit("tauri://created"))).catch((async e=>this.emit("tauri://error",e)))}static getByLabel(e){return f().some((n=>n.label===e))?new WebviewWindow(e,{skip:!0}):null}static getCurrent(){return U()}static getAll(){return f()}async listen(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):A(e,this.label,n)}async once(e,n){return this._handleTauriEvent(e,n)?Promise.resolve((()=>{const i=this.listeners[e];i.splice(i.indexOf(n),1)})):async function(e,n,i){return A(e,n,(n=>{i(n),O(e,n.id).catch((()=>{}))}))}(e,this.label,n)}async emit(e,n){if(D.includes(e)){for(const i of this.listeners[e]||[])i({event:e,id:-1,windowLabel:this.label,payload:n});return Promise.resolve()}return async function(e,n,i){await window.__TAURI_INVOKE__("plugin:event|emit",{event:e,windowLabel:n,payload:i})}(e,this.label,n)}_handleTauriEvent(e,n){return!!D.includes(e)&&(e in this.listeners?this.listeners[e].push(n):this.listeners[e]=[n],!0)}async scaleFactor(){return window.__TAURI_INVOKE__("plugin:window|scale_factor",{label:this.label})}async innerPosition(){return window.__TAURI_INVOKE__("plugin:window|inner_position",{label:this.label}).then((({x:e,y:n})=>new T(e,n)))}async outerPosition(){return window.__TAURI_INVOKE__("plugin:window|outer_position",{label:this.label}).then((({x:e,y:n})=>new T(e,n)))}async innerSize(){return window.__TAURI_INVOKE__("plugin:window|inner_size",{label:this.label}).then((({width:e,height:n})=>new N(e,n)))}async outerSize(){return window.__TAURI_INVOKE__("plugin:window|outer_size",{label:this.label}).then((({width:e,height:n})=>new N(e,n)))}async isFullscreen(){return window.__TAURI_INVOKE__("plugin:window|is_fullscreen",{label:this.label})}async isMinimized(){return window.__TAURI_INVOKE__("plugin:window|is_minimized",{label:this.label})}async isMaximized(){return window.__TAURI_INVOKE__("plugin:window|is_maximized",{label:this.label})}async isDecorated(){return window.__TAURI_INVOKE__("plugin:window|is_decorated",{label:this.label})}async isResizable(){return window.__TAURI_INVOKE__("plugin:window|is_resizable",{label:this.label})}async isVisible(){return window.__TAURI_INVOKE__("plugin:window|is_visible",{label:this.label})}async title(){return window.__TAURI_INVOKE__("plugin:window|title",{label:this.label})}async theme(){return window.__TAURI_INVOKE__("plugin:window|theme",{label:this.label})}async center(){return window.__TAURI_INVOKE__("plugin:window|center",{label:this.label})}async requestUserAttention(n){let i=null;return n&&(i=n===e.UserAttentionType.Critical?{type:"Critical"}:{type:"Informational"}),window.__TAURI_INVOKE__("plugin:window|request_user_attention",{label:this.label,value:i})}async setResizable(e){return window.__TAURI_INVOKE__("plugin:window|set_resizable",{label:this.label,value:e})}async setTitle(e){return window.__TAURI_INVOKE__("plugin:window|set_title",{label:this.label,value:e})}async maximize(){return window.__TAURI_INVOKE__("plugin:window|maximize",{label:this.label})}async unmaximize(){return window.__TAURI_INVOKE__("plugin:window|unmaximize",{label:this.label})}async toggleMaximize(){return window.__TAURI_INVOKE__("plugin:window|toggle_maximize",{label:this.label})}async minimize(){return window.__TAURI_INVOKE__("plugin:window|minimize",{label:this.label})}async unminimize(){return window.__TAURI_INVOKE__("plugin:window|unminimize",{label:this.label})}async show(){return window.__TAURI_INVOKE__("plugin:window|show",{label:this.label})}async hide(){return window.__TAURI_INVOKE__("plugin:window|hide",{label:this.label})}async close(){return window.__TAURI_INVOKE__("plugin:window|close",{label:this.label})}async setDecorations(e){return window.__TAURI_INVOKE__("plugin:window|set_decorations",{label:this.label,value:e})}async setShadow(e){return window.__TAURI_INVOKE__("plugin:window|set_shadow",{label:this.label,value:e})}async setAlwaysOnTop(e){return window.__TAURI_INVOKE__("plugin:window|set_always_on_top",{label:this.label,value:e})}async setContentProtected(e){return window.__TAURI_INVOKE__("plugin:window|set_content_protected",{label:this.label,value:e})}async setSize(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_size",{label:this.label,value:{type:e.type,data:{width:e.width,height:e.height}}})}async setMinSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_min_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setMaxSize(e){if(e&&"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `size` argument must be either a LogicalSize or a PhysicalSize instance");return window.__TAURI_INVOKE__("plugin:window|set_max_size",{label:this.label,value:e?{type:e.type,data:{width:e.width,height:e.height}}:null})}async setPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setFullscreen(e){return window.__TAURI_INVOKE__("plugin:window|set_fullscreen",{label:this.label,value:e})}async setFocus(){return window.__TAURI_INVOKE__("plugin:window|set_focus",{label:this.label})}async setIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_icon",{label:this.label,value:"string"==typeof e?e:Array.from(e)})}async setSkipTaskbar(e){return window.__TAURI_INVOKE__("plugin:window|set_skip_taskbar",{label:this.label,value:e})}async setCursorGrab(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_grab",{label:this.label,value:e})}async setCursorVisible(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_visible",{label:this.label,value:e})}async setCursorIcon(e){return window.__TAURI_INVOKE__("plugin:window|set_cursor_icon",{label:this.label,value:e})}async setCursorPosition(e){if(!e||"Logical"!==e.type&&"Physical"!==e.type)throw new Error("the `position` argument must be either a LogicalPosition or a PhysicalPosition instance");return window.__TAURI_INVOKE__("plugin:window|set_cursor_position",{label:this.label,value:{type:e.type,data:{x:e.x,y:e.y}}})}async setIgnoreCursorEvents(e){return window.__TAURI_INVOKE__("plugin:window|set_ignore_cursor_events",{label:this.label,value:e})}async startDragging(){return window.__TAURI_INVOKE__("plugin:window|start_dragging",{label:this.label})}async onResized(e){return this.listen(I.WINDOW_RESIZED,(n=>{n.payload=P(n.payload),e(n)}))}async onMoved(e){return this.listen(I.WINDOW_MOVED,(n=>{n.payload=K(n.payload),e(n)}))}async onCloseRequested(e){return this.listen(I.WINDOW_CLOSE_REQUESTED,(n=>{const i=new m(n);Promise.resolve(e(i)).then((()=>{if(!i.isPreventDefault())return this.close()}))}))}async onFocusChanged(e){const n=await this.listen(I.WINDOW_FOCUS,(n=>{e({...n,payload:!0})})),i=await this.listen(I.WINDOW_BLUR,(n=>{e({...n,payload:!1})}));return()=>{n(),i()}}async onScaleChanged(e){return this.listen(I.WINDOW_SCALE_FACTOR_CHANGED,e)}async onMenuClicked(e){return this.listen(I.MENU,e)}async onFileDropEvent(e){const n=await this.listen(I.WINDOW_FILE_DROP,(n=>{e({...n,payload:{type:"drop",paths:n.payload}})})),i=await this.listen(I.WINDOW_FILE_DROP_HOVER,(n=>{e({...n,payload:{type:"hover",paths:n.payload}})})),t=await this.listen(I.WINDOW_FILE_DROP_CANCELLED,(n=>{e({...n,payload:{type:"cancel"}})}));return()=>{n(),i(),t()}}async onThemeChanged(e){return this.listen(I.WINDOW_THEME_CHANGED,e)}}function W(e){return null===e?null:{name:e.name,scaleFactor:e.scaleFactor,position:K(e.position),size:P(e.size)}}function K(e){return new T(e.x,e.y)}function P(e){return new N(e.width,e.height)}return e.CloseRequestedEvent=m,e.LogicalPosition=v,e.LogicalSize=R,e.PhysicalPosition=T,e.PhysicalSize=N,e.availableMonitors=async function(){return window.__TAURI_INVOKE__("plugin:window|available_monitors").then((e=>e.map(W)))},e.currentMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|current_monitor").then(W)},e.getAll=f,e.getCurrent=U,e.primaryMonitor=async function(){return window.__TAURI_INVOKE__("plugin:window|primary_monitor").then(W)},e}({});Object.defineProperty(window.__TAURI__,"window",{value:__TAURI_WINDOW__})}