@tauri-apps/api
Advanced tools
Comparing version 2.0.0-alpha.14 to 2.0.0-beta.0
# Changelog | ||
## \[2.0.0-beta.0] | ||
### New Features | ||
- [`74a2a603`](https://www.github.com/tauri-apps/tauri/commit/74a2a6036a5e57462f161d728cbd8a6f121028ca)([#8661](https://www.github.com/tauri-apps/tauri/pull/8661)) Implement access control list for IPC usage. | ||
- [`a093682d`](https://www.github.com/tauri-apps/tauri/commit/a093682d2df7169b024bb4f736c7f1fd2ea8b327)([#8621](https://www.github.com/tauri-apps/tauri/pull/8621)) Added `emitTo` api to `event` module which is equivalent to the rust `emit_to` method. Also added `emitTo` method on `Window`, `Webivew` and `WebviewWindow` classes. | ||
- [`a2fc3a63`](https://www.github.com/tauri-apps/tauri/commit/a2fc3a63579ca739646d696870cbecbb3a169d33)([#8657](https://www.github.com/tauri-apps/tauri/pull/8657)) Add `visibleOnAllWorkspaces` option when creating the window in JS and `Window.setVisibleOnAllWorkspaces` method. | ||
- [`7f033f6d`](https://www.github.com/tauri-apps/tauri/commit/7f033f6dcd54c69a4193765a5c1584755ba92c61)([#8537](https://www.github.com/tauri-apps/tauri/pull/8537)) Add `Window.startResizeDragging`. | ||
- [`9eaeb5a8`](https://www.github.com/tauri-apps/tauri/commit/9eaeb5a8cd95ae24b5e66205bdc2763cb7f965ce)([#8622](https://www.github.com/tauri-apps/tauri/pull/8622)) Add `parent` option when creating a window. | ||
- [`af610232`](https://www.github.com/tauri-apps/tauri/commit/af6102327376884364b2075b468bdf08ee0d02aa)([#8710](https://www.github.com/tauri-apps/tauri/pull/8710)) Added `Window::destroy` to force close a window. | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) Added support to multiwebview via the new `window` and `webview` modules. | ||
### Breaking Changes | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) Removed event callback's `windowLabel`. | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) The event target is now an object so you can target either a window or a webview. | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) Moved webview-specific APIs from the `Window` class to the `Webview` class. | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) Renamed `TauriEvent.WINDOW_FILE_DROP` to `TauriEvent.WEBVIEW_FILE_DROP`, `TauriEvent.WINDOW_FILE_DROP_HOVER` to `TauriEvent.WEBVIEW_FILE_DROP_HOVER` and `TauriEvent.WINDOW_FILE_DROP_CANCELLED` to `TauriEvent.WEBVIEW_FILE_DROP_CANCELLED`. | ||
- [`c77b4032`](https://www.github.com/tauri-apps/tauri/commit/c77b40324ea9bf580871fc11aed69ba0c9b6b8cf)([#8280](https://www.github.com/tauri-apps/tauri/pull/8280)) Added back the `WebviewWindow` API that exposes functionality of a window that hosts a single webview. The dedicated `Window` and `Webview` types are exposed for multiwebview features. | ||
- [`af610232`](https://www.github.com/tauri-apps/tauri/commit/af6102327376884364b2075b468bdf08ee0d02aa)([#8710](https://www.github.com/tauri-apps/tauri/pull/8710)) `Window::close` now triggers a close requested event instead of forcing the window to be closed. | ||
## \[2.0.0-alpha.14] | ||
@@ -4,0 +25,0 @@ |
/** | ||
* 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`. | ||
* This package is also accessible with `window.__TAURI__.tauri` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
@@ -6,0 +6,0 @@ */ |
@@ -10,3 +10,3 @@ import { __classPrivateFieldGet, __classPrivateFieldSet } from './external/tslib/tslib.es6.js'; | ||
* | ||
* 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`. | ||
* This package is also accessible with `window.__TAURI__.tauri` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
@@ -13,0 +13,0 @@ */ |
@@ -0,6 +1,21 @@ | ||
type EventTarget = { | ||
kind: 'Any'; | ||
} | { | ||
kind: 'AnyLabel'; | ||
label: string; | ||
} | { | ||
kind: 'App'; | ||
} | { | ||
kind: 'Window'; | ||
label: string; | ||
} | { | ||
kind: 'Webview'; | ||
label: string; | ||
} | { | ||
kind: 'WebviewWindow'; | ||
label: string; | ||
}; | ||
interface Event<T> { | ||
/** Event name */ | ||
event: EventName; | ||
/** The label of the window that emitted this event. */ | ||
windowLabel: string; | ||
/** Event identifier used to unlisten */ | ||
@@ -16,10 +31,7 @@ id: number; | ||
/** | ||
* Label of the window the function targets. | ||
* The event target to listen to, defaults to `{ kind: 'Any' }`, see {@link EventTarget}. | ||
* | ||
* 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. | ||
* If a string is provided, {@link EventTarget.AnyLabel} is used. | ||
*/ | ||
target?: string; | ||
target?: string | EventTarget; | ||
} | ||
@@ -33,3 +45,2 @@ /** | ||
WINDOW_CLOSE_REQUESTED = "tauri://close-requested", | ||
WINDOW_CREATED = "tauri://window-created", | ||
WINDOW_DESTROYED = "tauri://destroyed", | ||
@@ -40,9 +51,9 @@ WINDOW_FOCUS = "tauri://focus", | ||
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" | ||
WEBVIEW_CREATED = "tauri://webview-created", | ||
WEBVIEW_FILE_DROP = "tauri://file-drop", | ||
WEBVIEW_FILE_DROP_HOVER = "tauri://file-drop-hover", | ||
WEBVIEW_FILE_DROP_CANCELLED = "tauri://file-drop-cancelled" | ||
} | ||
/** | ||
* Listen to an event. The event can be either global or window-specific. | ||
* See {@link Event.windowLabel} to check the event source. | ||
* Listen to an emitted event to any {@link EventTarget|target}. | ||
* | ||
@@ -53,3 +64,3 @@ * @example | ||
* const unlisten = await listen<string>('error', (event) => { | ||
* console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`); | ||
* console.log(`Got error, payload: ${event.payload}`); | ||
* }); | ||
@@ -63,2 +74,3 @@ * | ||
* @param handler Event handler callback. | ||
* @param options Event listening options. | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -71,3 +83,3 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. | ||
/** | ||
* Listen to an one-off event. See {@link listen} for more information. | ||
* Listens once to an emitted event to any {@link EventTarget|target}. | ||
* | ||
@@ -90,2 +102,4 @@ * @example | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param handler Event handler callback. | ||
* @param options Event listening options. | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -98,3 +112,4 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. | ||
/** | ||
* Emits an event to the backend and all Tauri windows. | ||
* Emits an event to all {@link EventTarget|targets}. | ||
* | ||
* @example | ||
@@ -107,7 +122,24 @@ * ```typescript | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
* | ||
* @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 }; | ||
declare function emit(event: string, payload?: unknown): Promise<void>; | ||
/** | ||
* Emits an event to all {@link EventTarget|targets} matching the given target. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { emit } from '@tauri-apps/api/event'; | ||
* await emit('frontend-loaded', { loggedIn: true, token: 'authToken' }); | ||
* ``` | ||
* | ||
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object. | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
declare function emitTo(target: EventTarget | string, event: string, payload?: unknown): Promise<void>; | ||
export type { Event, EventTarget, EventCallback, UnlistenFn, EventName, Options }; | ||
export { listen, once, emit, emitTo, TauriEvent }; |
57
event.js
@@ -9,3 +9,3 @@ import { invoke, transformCallback } from './core.js'; | ||
* | ||
* 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`. | ||
* This package is also accessible with `window.__TAURI__.event` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
@@ -21,3 +21,2 @@ */ | ||
TauriEvent["WINDOW_CLOSE_REQUESTED"] = "tauri://close-requested"; | ||
TauriEvent["WINDOW_CREATED"] = "tauri://window-created"; | ||
TauriEvent["WINDOW_DESTROYED"] = "tauri://destroyed"; | ||
@@ -28,5 +27,6 @@ TauriEvent["WINDOW_FOCUS"] = "tauri://focus"; | ||
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["WEBVIEW_CREATED"] = "tauri://webview-created"; | ||
TauriEvent["WEBVIEW_FILE_DROP"] = "tauri://file-drop"; | ||
TauriEvent["WEBVIEW_FILE_DROP_HOVER"] = "tauri://file-drop-hover"; | ||
TauriEvent["WEBVIEW_FILE_DROP_CANCELLED"] = "tauri://file-drop-cancelled"; | ||
})(TauriEvent || (TauriEvent = {})); | ||
@@ -48,4 +48,3 @@ /** | ||
/** | ||
* Listen to an event. The event can be either global or window-specific. | ||
* See {@link Event.windowLabel} to check the event source. | ||
* Listen to an emitted event to any {@link EventTarget|target}. | ||
* | ||
@@ -56,3 +55,3 @@ * @example | ||
* const unlisten = await listen<string>('error', (event) => { | ||
* console.log(`Got error in window ${event.windowLabel}, payload: ${event.payload}`); | ||
* console.log(`Got error, payload: ${event.payload}`); | ||
* }); | ||
@@ -66,2 +65,3 @@ * | ||
* @param handler Event handler callback. | ||
* @param options Event listening options. | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -73,5 +73,8 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. | ||
async function listen(event, handler, options) { | ||
const target = typeof options?.target === 'string' | ||
? { kind: 'AnyLabel', label: options.target } | ||
: options?.target ?? { kind: 'Any' }; | ||
return invoke('plugin:event|listen', { | ||
event, | ||
windowLabel: options?.target, | ||
target, | ||
handler: transformCallback(handler) | ||
@@ -83,3 +86,3 @@ }).then((eventId) => { | ||
/** | ||
* Listen to an one-off event. See {@link listen} for more information. | ||
* Listens once to an emitted event to any {@link EventTarget|target}. | ||
* | ||
@@ -102,2 +105,4 @@ * @example | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param handler Event handler callback. | ||
* @param options Event listening options. | ||
* @returns A promise resolving to a function to unlisten to the event. | ||
@@ -115,3 +120,4 @@ * Note that removing the listener is required if your listener goes out of scope e.g. the component is unmounted. | ||
/** | ||
* Emits an event to the backend and all Tauri windows. | ||
* Emits an event to all {@link EventTarget|targets}. | ||
* | ||
* @example | ||
@@ -124,13 +130,36 @@ * ```typescript | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
async function emit(event, payload, options) { | ||
async function emit(event, payload) { | ||
await invoke('plugin:event|emit', { | ||
event, | ||
windowLabel: options?.target, | ||
payload | ||
}); | ||
} | ||
/** | ||
* Emits an event to all {@link EventTarget|targets} matching the given target. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { emit } from '@tauri-apps/api/event'; | ||
* await emit('frontend-loaded', { loggedIn: true, token: 'authToken' }); | ||
* ``` | ||
* | ||
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object. | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
* | ||
* @since 1.0.0 | ||
*/ | ||
async function emitTo(target, event, payload) { | ||
const eventTarget = typeof target === 'string' ? { kind: 'AnyLabel', label: target } : target; | ||
await invoke('plugin:event|emit_to', { | ||
target: eventTarget, | ||
event, | ||
payload | ||
}); | ||
} | ||
export { TauriEvent, emit, listen, once }; | ||
export { TauriEvent, emit, emitTo, listen, once }; |
@@ -15,2 +15,3 @@ /** | ||
import * as window from './window'; | ||
import * as webview from './webview'; | ||
import * as path from './path'; | ||
@@ -20,2 +21,2 @@ import * as dpi from './dpi'; | ||
import * as menu from './menu'; | ||
export { app, dpi, event, path, core, window, tray, menu }; | ||
export { app, dpi, event, path, core, window, webview, tray, menu }; |
@@ -9,2 +9,4 @@ import * as app from './app.js'; | ||
export { window }; | ||
import * as webview from './webview.js'; | ||
export { webview }; | ||
import * as path from './path.js'; | ||
@@ -11,0 +13,0 @@ export { path }; |
@@ -10,4 +10,4 @@ export * from './menu/submenu'; | ||
* | ||
* This package is also accessible with `window.__TAURI__.menu` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* This package is also accessible with `window.__TAURI__.menu` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
*/ |
@@ -14,4 +14,4 @@ export { Submenu } from './menu/submenu.js'; | ||
* | ||
* This package is also accessible with `window.__TAURI__.menu` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* This package is also accessible with `window.__TAURI__.menu` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
*/ |
@@ -49,3 +49,3 @@ import { MenuItem } from './menuItem.js'; | ||
static async default() { | ||
return invoke('plugin:menu|default').then(([rid, id]) => new Menu(rid, id)); | ||
return invoke('plugin:menu|create_default').then(([rid, id]) => new Menu(rid, id)); | ||
} | ||
@@ -52,0 +52,0 @@ /** |
@@ -130,3 +130,8 @@ // Copyright 2019-2023 Tauri Programme within The Commons Conservancy | ||
windows: [current, ...additionalWindows].map((label) => ({ label })), | ||
currentWindow: { label: current } | ||
currentWindow: { label: current }, | ||
webviews: [current, ...additionalWindows].map((label) => ({ | ||
windowLabel: label, | ||
label | ||
})), | ||
currentWebview: { windowLabel: current, label: current } | ||
}; | ||
@@ -133,0 +138,0 @@ } |
{ | ||
"name": "@tauri-apps/api", | ||
"version": "2.0.0-alpha.14", | ||
"version": "2.0.0-beta.0", | ||
"description": "Tauri API definitions", | ||
@@ -5,0 +5,0 @@ "funding": { |
@@ -319,3 +319,3 @@ /** | ||
* @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 (`../`). | ||
* Must follow the same syntax as defined in `tauri.conf.json > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`). | ||
* @returns The full path to the resource. | ||
@@ -322,0 +322,0 @@ * |
@@ -9,3 +9,3 @@ import { invoke } from './core.js'; | ||
* | ||
* 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`. | ||
* This package is also accessible with `window.__TAURI__.path` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* | ||
@@ -406,3 +406,3 @@ * It is recommended to allowlist only the APIs you use for optimal bundle size and security. | ||
* @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 (`../`). | ||
* Must follow the same syntax as defined in `tauri.conf.json > bundle > resources`, i.e. keeping subfolders and parent dir components (`../`). | ||
* @returns The full path to the resource. | ||
@@ -409,0 +409,0 @@ * |
@@ -35,3 +35,3 @@ import type { Menu, Submenu } from './menu'; | ||
* | ||
* This package is also accessible with `window.__TAURI__.tray` when [`build.withGlobalTauri`](https://tauri.app/v1/api/config/#buildconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* This package is also accessible with `window.__TAURI__.tray` when [`app.withGlobalTauri`](https://tauri.app/v1/api/config/#appconfig.withglobaltauri) in `tauri.conf.json` is set to `true`. | ||
* @module | ||
@@ -38,0 +38,0 @@ */ |
167
window.d.ts
@@ -16,2 +16,4 @@ /** | ||
import type { Event, EventName, EventCallback, UnlistenFn } from './event'; | ||
import { type EventTarget } from './event'; | ||
import { WebviewWindow } from './webview'; | ||
/** | ||
@@ -34,2 +36,3 @@ * Allows you to retrieve information about a given monitor. | ||
type TitleBarStyle = 'visible' | 'transparent' | 'overlay'; | ||
type ResizeDirection = 'East' | 'North' | 'NorthEast' | 'NorthWest' | 'South' | 'SouthEast' | 'SouthWest' | 'West'; | ||
/** | ||
@@ -46,14 +49,2 @@ * The payload for the `scaleChange` event. | ||
} | ||
interface FileDropPayload { | ||
paths: string[]; | ||
position: PhysicalPosition; | ||
} | ||
/** The file drop event types. */ | ||
type FileDropEvent = ({ | ||
type: 'hover'; | ||
} & FileDropPayload) | ({ | ||
type: 'drop'; | ||
} & FileDropPayload) | { | ||
type: 'cancel'; | ||
}; | ||
/** | ||
@@ -81,4 +72,2 @@ * Attention type to request on a window. | ||
event: EventName; | ||
/** The label of the window that emitted this event. */ | ||
windowLabel: string; | ||
/** Event identifier used to unlisten */ | ||
@@ -143,3 +132,3 @@ id: number; | ||
/** | ||
* Create new webview window or get a handle to an existing one. | ||
* Create new window or get a handle to an existing one. | ||
* | ||
@@ -197,8 +186,8 @@ * Windows are identified by a *label* a unique identifier that can be used to reference it later. | ||
* | ||
* @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`. | ||
* @returns The {@link Window} instance to communicate with the webview. | ||
* @param label The unique window label. Must be alphanumeric: `a-zA-Z-/:_`. | ||
* @returns The {@link Window} instance to communicate with the window. | ||
*/ | ||
constructor(label: WindowLabel, options?: WindowOptions); | ||
/** | ||
* Gets the Window for the webview associated with the given label. | ||
* Gets the Window associated with the given label. | ||
* @example | ||
@@ -210,4 +199,4 @@ * ```typescript | ||
* | ||
* @param label The webview window label. | ||
* @returns The Window instance to communicate with the webview or null if the webview doesn't exist. | ||
* @param label The window label. | ||
* @returns The Window instance to communicate with the window or null if the window doesn't exist. | ||
*/ | ||
@@ -231,7 +220,7 @@ static getByLabel(label: string): Window | null; | ||
* | ||
* @returns The Window instance to communicate with the webview or `undefined` if there is not any focused window. | ||
* @returns The Window instance 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. | ||
* Listen to an emitted event on this window. | ||
* | ||
@@ -256,3 +245,3 @@ * @example | ||
/** | ||
* Listen to an one-off event emitted by the backend that is tied to the webview window. | ||
* Listen to an emitted event on this window only once. | ||
* | ||
@@ -277,3 +266,3 @@ * @example | ||
/** | ||
* Emits an event to the backend, tied to the webview window. | ||
* Emits an event to all {@link EventTarget|targets}. | ||
* @example | ||
@@ -289,2 +278,15 @@ * ```typescript | ||
emit(event: string, payload?: unknown): Promise<void>; | ||
/** | ||
* Emits an event to all {@link EventTarget|targets} matching the given target. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' }); | ||
* ``` | ||
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object. | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
*/ | ||
emitTo(target: string | EventTarget, event: string, payload?: unknown): Promise<void>; | ||
/** @ignore */ | ||
@@ -682,2 +684,4 @@ _handleTauriEvent<T>(event: string, handler: EventCallback<T>): boolean; | ||
* Closes the window. | ||
* | ||
* Note this emits a closeRequested event so you can intercept it. To force window close, use {@link Window.destroy}. | ||
* @example | ||
@@ -693,2 +697,13 @@ * ```typescript | ||
/** | ||
* Destroys the window. Behaves like {@link Window.close} but forces the window close instead of emitting a closeRequested event. | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().destroy(); | ||
* ``` | ||
* | ||
* @returns A promise indicating the success or failure of the operation. | ||
*/ | ||
destroy(): Promise<void>; | ||
/** | ||
* Whether the window should have borders and bars. | ||
@@ -961,2 +976,13 @@ * @example | ||
/** | ||
* Starts resize-dragging the window. | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().startResizeDragging(); | ||
* ``` | ||
* | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
startResizeDragging(direction: ResizeDirection): Promise<void>; | ||
/** | ||
* Sets the taskbar progress state. | ||
@@ -982,2 +1008,12 @@ * | ||
/** | ||
* Sets whether the window should be visible on all workspaces or virtual desktops. | ||
* | ||
* ## Platform-specific | ||
* | ||
* - **Windows / iOS / Android:** Unsupported. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
setVisibleOnAllWorkspaces(visible: boolean): Promise<void>; | ||
/** | ||
* Listen to window resize. | ||
@@ -1082,28 +1118,2 @@ * | ||
/** | ||
* 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. | ||
@@ -1309,10 +1319,2 @@ * | ||
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.. */ | ||
@@ -1346,3 +1348,3 @@ center?: 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`. | ||
* Note that on `macOS` this requires the `macos-private-api` feature flag, enabled under `tauri.conf.json > app > macOSPrivateApi`. | ||
* WARNING: Using private APIs on `macOS` prevents your application from being accepted to the `App Store`. | ||
@@ -1380,8 +1382,2 @@ */ | ||
/** | ||
* 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. | ||
@@ -1401,6 +1397,2 @@ * | ||
/** | ||
* 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. | ||
@@ -1413,14 +1405,2 @@ * | ||
/** | ||
* 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`. | ||
@@ -1437,2 +1417,25 @@ */ | ||
closable?: boolean; | ||
/** | ||
* Sets a parent to the window to be created. Can be either a {@linkcode Window} or a label of the window. | ||
* | ||
* #### Platform-specific | ||
* | ||
* - **Windows**: This sets the passed parent as an owner window to the window to be created. | ||
* From [MSDN owned windows docs](https://docs.microsoft.com/en-us/windows/win32/winmsg/window-features#owned-windows): | ||
* - An owned window is always above its owner in the z-order. | ||
* - The system automatically destroys an owned window when its owner is destroyed. | ||
* - An owned window is hidden when its owner is minimized. | ||
* - **Linux**: This makes the new window transient for parent, see <https://docs.gtk.org/gtk3/method.Window.set_transient_for.html> | ||
* - **macOS**: This adds the window as a child of parent, see <https://developer.apple.com/documentation/appkit/nswindow/1419152-addchildwindow?language=objc> | ||
*/ | ||
parent?: Window | WebviewWindow | string; | ||
/** Whether the window should be visible on all workspaces or virtual desktops. | ||
* | ||
* ## Platform-specific | ||
* | ||
* - **Windows / iOS / Android:** Unsupported. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
visibleOnAllWorkspaces?: boolean; | ||
} | ||
@@ -1475,2 +1478,2 @@ /** | ||
export { Window, CloseRequestedEvent, getCurrent, getAll, LogicalSize, PhysicalSize, LogicalPosition, PhysicalPosition, UserAttentionType, Effect, EffectState, currentMonitor, primaryMonitor, availableMonitors }; | ||
export type { Effects, Theme, TitleBarStyle, ScaleFactorChanged, FileDropPayload, FileDropEvent, WindowOptions, Color }; | ||
export type { Effects, Theme, TitleBarStyle, ScaleFactorChanged, WindowOptions, Color }; |
181
window.js
import { PhysicalPosition, PhysicalSize } from './dpi.js'; | ||
export { LogicalPosition, LogicalSize } from './dpi.js'; | ||
import { listen, once, emit, TauriEvent } from './event.js'; | ||
import { listen, once, emit, emitTo, TauriEvent } from './event.js'; | ||
import { invoke } from './core.js'; | ||
@@ -46,3 +46,2 @@ | ||
this.event = event.event; | ||
this.windowLabel = event.windowLabel; | ||
this.id = event.id; | ||
@@ -103,6 +102,6 @@ } | ||
/** @ignore */ | ||
// events that are emitted right here instead of by the created webview | ||
// events that are emitted right here instead of by the created window | ||
const localTauriEvents = ['tauri://created', 'tauri://error']; | ||
/** | ||
* Create new webview window or get a handle to an existing one. | ||
* Create new window or get a handle to an existing one. | ||
* | ||
@@ -156,4 +155,4 @@ * Windows are identified by a *label* a unique identifier that can be used to reference it later. | ||
* | ||
* @param label The unique webview window label. Must be alphanumeric: `a-zA-Z-/:_`. | ||
* @returns The {@link Window} instance to communicate with the webview. | ||
* @param label The unique window label. Must be alphanumeric: `a-zA-Z-/:_`. | ||
* @returns The {@link Window} instance to communicate with the window. | ||
*/ | ||
@@ -169,2 +168,5 @@ constructor(label, options = {}) { | ||
...options, | ||
parent: typeof options.parent === 'string' | ||
? options.parent | ||
: options.parent?.label, | ||
label | ||
@@ -178,3 +180,3 @@ } | ||
/** | ||
* Gets the Window for the webview associated with the given label. | ||
* Gets the Window associated with the given label. | ||
* @example | ||
@@ -186,11 +188,7 @@ * ```typescript | ||
* | ||
* @param label The webview window label. | ||
* @returns The Window instance to communicate with the webview or null if the webview doesn't exist. | ||
* @param label The window label. | ||
* @returns The Window instance to communicate with the window or null if the window 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; | ||
return getAll().find((w) => w.label === label) ?? null; | ||
} | ||
@@ -217,3 +215,3 @@ /** | ||
* | ||
* @returns The Window instance to communicate with the webview or `undefined` if there is not any focused window. | ||
* @returns The Window instance or `undefined` if there is not any focused window. | ||
*/ | ||
@@ -229,3 +227,3 @@ static async getFocusedWindow() { | ||
/** | ||
* Listen to an event emitted by the backend that is tied to the webview window. | ||
* Listen to an emitted event on this window. | ||
* | ||
@@ -256,6 +254,8 @@ * @example | ||
} | ||
return listen(event, handler, { target: this.label }); | ||
return listen(event, handler, { | ||
target: { kind: 'Window', label: this.label } | ||
}); | ||
} | ||
/** | ||
* Listen to an one-off event emitted by the backend that is tied to the webview window. | ||
* Listen to an emitted event on this window only once. | ||
* | ||
@@ -286,6 +286,8 @@ * @example | ||
} | ||
return once(event, handler, { target: this.label }); | ||
return once(event, handler, { | ||
target: { kind: 'Window', label: this.label } | ||
}); | ||
} | ||
/** | ||
* Emits an event to the backend, tied to the webview window. | ||
* Emits an event to all {@link EventTarget|targets}. | ||
* @example | ||
@@ -304,8 +306,38 @@ * ```typescript | ||
for (const handler of this.listeners[event] || []) { | ||
handler({ event, id: -1, windowLabel: this.label, payload }); | ||
handler({ | ||
event, | ||
id: -1, | ||
payload | ||
}); | ||
} | ||
return Promise.resolve(); | ||
} | ||
return emit(event, payload, { target: this.label }); | ||
return emit(event, payload); | ||
} | ||
/** | ||
* Emits an event to all {@link EventTarget|targets} matching the given target. | ||
* | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().emit('window-loaded', { loggedIn: true, token: 'authToken' }); | ||
* ``` | ||
* @param target Label of the target Window/Webview/WebviewWindow or raw {@link EventTarget} object. | ||
* @param event Event name. Must include only alphanumeric characters, `-`, `/`, `:` and `_`. | ||
* @param payload Event payload. | ||
*/ | ||
async emitTo(target, event, payload) { | ||
if (localTauriEvents.includes(event)) { | ||
// eslint-disable-next-line | ||
for (const handler of this.listeners[event] || []) { | ||
handler({ | ||
event, | ||
id: -1, | ||
payload | ||
}); | ||
} | ||
return Promise.resolve(); | ||
} | ||
return emitTo(target, event, payload); | ||
} | ||
/** @ignore */ | ||
@@ -857,2 +889,4 @@ _handleTauriEvent(event, handler) { | ||
* Closes the window. | ||
* | ||
* Note this emits a closeRequested event so you can intercept it. To force window close, use {@link Window.destroy}. | ||
* @example | ||
@@ -872,2 +906,17 @@ * ```typescript | ||
/** | ||
* Destroys the window. Behaves like {@link Window.close} but forces the window close instead of emitting a closeRequested event. | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().destroy(); | ||
* ``` | ||
* | ||
* @returns A promise indicating the success or failure of the operation. | ||
*/ | ||
async destroy() { | ||
return invoke('plugin:window|destroy', { | ||
label: this.label | ||
}); | ||
} | ||
/** | ||
* Whether the window should have borders and bars. | ||
@@ -1294,2 +1343,18 @@ * @example | ||
/** | ||
* Starts resize-dragging the window. | ||
* @example | ||
* ```typescript | ||
* import { getCurrent } from '@tauri-apps/api/window'; | ||
* await getCurrent().startResizeDragging(); | ||
* ``` | ||
* | ||
* @return A promise indicating the success or failure of the operation. | ||
*/ | ||
async startResizeDragging(direction) { | ||
return invoke('plugin:window|start_resize_dragging', { | ||
label: this.label, | ||
value: direction | ||
}); | ||
} | ||
/** | ||
* Sets the taskbar progress state. | ||
@@ -1319,2 +1384,17 @@ * | ||
} | ||
/** | ||
* Sets whether the window should be visible on all workspaces or virtual desktops. | ||
* | ||
* ## Platform-specific | ||
* | ||
* - **Windows / iOS / Android:** Unsupported. | ||
* | ||
* @since 2.0.0 | ||
*/ | ||
async setVisibleOnAllWorkspaces(visible) { | ||
return invoke('plugin:window|set_visible_on_all_workspaces', { | ||
label: this.label, | ||
value: visible | ||
}); | ||
} | ||
// Listeners | ||
@@ -1395,3 +1475,3 @@ /** | ||
if (!evt.isPreventDefault()) { | ||
return this.close(); | ||
return this.destroy(); | ||
} | ||
@@ -1456,57 +1536,2 @@ }); | ||
/** | ||
* 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.paths, | ||
position: mapPhysicalPosition(event.payload.position) | ||
} | ||
}); | ||
}); | ||
const unlistenFileHover = await this.listen(TauriEvent.WINDOW_FILE_DROP_HOVER, (event) => { | ||
handler({ | ||
...event, | ||
payload: { | ||
type: 'hover', | ||
paths: event.payload.paths, | ||
position: mapPhysicalPosition(event.payload.position) | ||
} | ||
}); | ||
}); | ||
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. | ||
@@ -1513,0 +1538,0 @@ * |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
514068
61
12954