### Window Initialization Example Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Example of creating a new window with a label and setting up listeners for creation and error events. ```typescript import { Window } from '@tauri-apps/api/window'; const appWindow = new Window('my-label'); appWindow.once('tauri://created', function () { // window successfully created }); appWindow.once('tauri://error', function (e) { // an error happened creating the window }); ``` -------------------------------- ### isFullscreen Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the window’s current fullscreen state. ```APIDOC ## isFullscreen() ### Description Gets the window’s current fullscreen state. ### Method `isFullscreen(): Promise` ### Returns `Promise` - Whether the window is in fullscreen mode or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const fullscreen = await getCurrentWindow().isFullscreen(); ``` ``` -------------------------------- ### Get Video Directory Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the path to the user's video directory. The exact path is platform-dependent. ```javascript import { videoDir } from '@tauri-apps/api/path'; const videoDirPath = await videoDir(); ``` -------------------------------- ### isDecorated Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the window’s current decorated state. ```APIDOC ## isDecorated() ### Description Gets the window’s current decorated state. ### Method `isDecorated(): Promise` ### Returns `Promise` - Whether the window is decorated or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const decorated = await getCurrentWindow().isDecorated(); ``` ``` -------------------------------- ### Get Template Directory Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Retrieves the path to the user's template directory. This path varies by operating system. ```javascript import { templateDir } from '@tauri-apps/api/path'; const templateDirPath = await templateDir(); ``` -------------------------------- ### isMaximizable Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the window’s native maximize button state. ```APIDOC ## isMaximizable() ### Description Gets the window’s native maximize button state. Platform-specific * **Linux / iOS / Android:** Unsupported. ### Method `isMaximizable(): Promise` ### Returns `Promise` - Whether the window’s native maximize button is enabled or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const maximizable = await getCurrentWindow().isMaximizable(); ``` ``` -------------------------------- ### Enable or Disable Window Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Sets the enabled state of the window. This example demonstrates disabling the window. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; await getCurrentWindow().setEnabled(false); ``` -------------------------------- ### Get Resource Directory Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Use this function to get the path to the resource directory. This is useful for accessing application assets. ```javascript import { resourceDir } from '@tauri-apps/api/path'; const resourceDirPath = await resourceDir(); ``` -------------------------------- ### Get Runtime Directory Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Retrieves the path to the user's runtime directory. Note that this is not supported on macOS and Windows. ```javascript import { runtimeDir } from '@tauri-apps/api/path'; const runtimeDirPath = await runtimeDir(); ``` -------------------------------- ### isFocused Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the window’s current focus state. ```APIDOC ## isFocused() ### Description Gets the window’s current focus state. ### Method `isFocused(): Promise` ### Returns `Promise` - Whether the window is focused or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const focused = await getCurrentWindow().isFocused(); ``` ``` -------------------------------- ### Get Temporary Directory Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Use this function to get the path to a temporary directory. This is useful for storing temporary files. ```javascript import { tempDir } from '@tauri-apps/api/path'; const temp = await tempDir(); ``` -------------------------------- ### Get Window Scale Factor and Size Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Retrieves the current window's scale factor and inner size, then converts the physical size to logical size. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const appWindow = getCurrentWindow(); const factor = await appWindow.scaleFactor(); const size = await appWindow.innerSize(); // PhysicalSize const logical = size.toLogical(factor); ``` -------------------------------- ### innerSize Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the physical size of the window's client area, excluding the title bar and borders. ```APIDOC ## innerSize() ### Description Gets the physical size of the window's client area. The client area is the content of the window, excluding the title bar and borders. ### Method `innerSize(): Promise` ### Returns `Promise` - The window's inner size. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const size = await getCurrentWindow().innerSize(); ``` ``` -------------------------------- ### isClosable Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the window’s native close button state. ```APIDOC ## isClosable() ### Description Gets the window’s native close button state. Platform-specific * **iOS / Android:** Unsupported. ### Method `isClosable(): Promise` ### Returns `Promise` - Whether the window’s native close button is enabled or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const closable = await getCurrentWindow().isClosable(); ``` ``` -------------------------------- ### Get Image Size Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Retrieves the dimensions (width and height) of an image. This is useful for layout and rendering. ```typescript image.size() ``` -------------------------------- ### Check if Window is Focused Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the current focus state of the window. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const focused = await getCurrentWindow().isFocused(); ``` -------------------------------- ### Get Path Segment Separator Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the platform-specific path segment separator. Use '\' on Windows and '/' on POSIX systems. ```javascript function sep(): string Returns the platform-specific path segment separator: * \ on Windows * / on POSIX ``` -------------------------------- ### Get Image RGBA Data Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Retrieves the RGBA data of an image. Ensure the image resource is properly managed. ```typescript image.rgba() ``` -------------------------------- ### Get Window Inner Position Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Retrieves the position of the top-left corner of the window's client area relative to the desktop. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const position = await getCurrentWindow().innerPosition(); ``` -------------------------------- ### Check if Window is Maximizable Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the state of the window's native maximize button. This functionality is unsupported on Linux, iOS, and Android. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const maximizable = await getCurrentWindow().isMaximizable(); ``` -------------------------------- ### Get Window Inner Size Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Retrieves the physical size of the window's client area, excluding the title bar and borders. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const size = await getCurrentWindow().innerSize(); ``` -------------------------------- ### Check if Window is Closable Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Gets the state of the window's native close button. This functionality is unsupported on iOS and Android. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const closable = await getCurrentWindow().isClosable(); ``` -------------------------------- ### Window Creation and Event Handling Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Demonstrates creating a new window with a unique label and listening for 'tauri://created' and 'tauri://error' events. Also shows emitting and listening to custom events. ```typescript import { Window } from "@tauri-apps/api/window" const appWindow = new Window('theUniqueLabel'); 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(); ``` -------------------------------- ### Invoke Command with Size (Using Size Class) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Shows how to use the Size class to automatically handle conversion for Tauri command invocation. ```javascript import { invoke } from '@tauri-apps/api/core'; import { LogicalSize, PhysicalSize, Size } from '@tauri-apps/api/dpi'; const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize const validSize = new Size(size); await invoke("do_something_with_size", { size: validSize }); ``` -------------------------------- ### Invoke Command with Size (Manual Conversion) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Demonstrates manually converting a LogicalSize or PhysicalSize to a format suitable for invoking a Tauri command. ```javascript import { invoke } from '@tauri-apps/api/core'; import { LogicalSize, PhysicalSize } from '@tauri-apps/api/dpi'; const size: LogicalSize | PhysicalSize = someFunction(); // where someFunction returns either LogicalSize or PhysicalSize const validSize = size instanceof LogicalSize ? { Logical: { width: size.width, height: size.height } } : { Physical: { width: size.width, height: size.height } } await invoke("do_something_with_size", { size: validSize }); ``` -------------------------------- ### Image Static Methods Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Static methods for creating new Image instances. ```APIDOC ### Static Methods #### fromBytes() ```javascript static fromBytes(bytes: number[] | ArrayBuffer | Uint8Array): Promise ``` Creates a new image using the provided bytes by inferring the file format. Only `ico` and `png` are supported. #### fromPath() ```javascript static fromPath(path: string): Promise ``` Creates a new image using the provided path. Only `ico` and `png` are supported. #### new() ```javascript static new(rgba: number[] | ArrayBuffer | Uint8Array, width: number, height: number): Promise ``` Creates a new Image using RGBA data, in row-major order from top to bottom, and with specified width and height. ``` -------------------------------- ### videoDir() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the path to the user's video directory. ```APIDOC ## videoDir() ### Description Returns the path to the user's video directory. Platform-specific * **Linux:** Resolves to `xdg-user-dirs`’ `XDG_VIDEOS_DIR`. * **macOS:** Resolves to `$HOME/Movies`. * **Windows:** Resolves to `{FOLDERID_Videos}`. ### Returns `Promise` ### Example ```javascript import { videoDir } from '@tauri-apps/api/path'; const videoDirPath = await videoDir(); ``` ### Since 1.0.0 ``` -------------------------------- ### Window Constructor Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Creates a new Window instance with a specified label and options. The label must be alphanumeric with allowed special characters. ```typescript new Window(label, options): Window ``` -------------------------------- ### Invoke Command with Position (Using Position Class) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Shows how to use the Position class to automatically handle conversion for Tauri command invocation. ```javascript import { invoke } from '@tauri-apps/api/core'; import { LogicalPosition, PhysicalPosition, Position } from '@tauri-apps/api/dpi'; const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition const validPosition = new Position(position); await invoke("do_something_with_position", { position: validPosition }); ``` -------------------------------- ### runtimeDir() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the path to the user's runtime directory. ```APIDOC ## runtimeDir() ### Description Returns the path to the user's runtime directory. Platform-specific * **Linux:** Resolves to `$XDG_RUNTIME_DIR`. * **macOS:** Not supported. * **Windows:** Not supported. ### Returns `Promise` ### Example ```javascript import { runtimeDir } from '@tauri-apps/api/path'; const runtimeDirPath = await runtimeDir(); ``` ### Since 1.0.0 ``` -------------------------------- ### Invoke Command with Position (Manual Conversion) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Demonstrates manually converting a LogicalPosition or PhysicalPosition to a format suitable for invoking a Tauri command. ```javascript import { invoke } from '@tauri-apps/api/core'; import { LogicalPosition, PhysicalPosition } from '@tauri-apps/api/dpi'; const position: LogicalPosition | PhysicalPosition = someFunction(); // where someFunction returns either LogicalPosition or PhysicalPosition const validPosition = position instanceof LogicalPosition ? { Logical: { x: position.x, y: position.y } } : { Physical: { x: position.x, y: position.y } } await invoke("do_something_with_position", { position: validPosition }); ``` -------------------------------- ### templateDir() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the path to the user's template directory. ```APIDOC ## templateDir() ### Description Returns the path to the user's template directory. Platform-specific * **Linux:** Resolves to `xdg-user-dirs`’ `XDG_TEMPLATES_DIR`. * **macOS:** Not supported. * **Windows:** Resolves to `{FOLDERID_Templates}`. ### Returns `Promise` ### Example ```javascript import { templateDir } from '@tauri-apps/api/path'; const templateDirPath = await templateDir(); ``` ### Since 1.0.0 ``` -------------------------------- ### isAlwaysOnTop Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Checks if the window is configured to be always on top of other windows. ```APIDOC ## isAlwaysOnTop() ### Description Checks whether the window is configured to be always on top of other windows or not. ### Method `isAlwaysOnTop(): Promise` ### Returns `Promise` - Whether the window is visible or not. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const alwaysOnTop = await getCurrentWindow().isAlwaysOnTop(); ``` ``` -------------------------------- ### Window Class Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow The Window class allows for the creation of new windows or obtaining handles to existing ones. Windows are identified by a unique label. ```APIDOC ## new Window(label, options) ### Description Creates a new Window. ### Parameters #### Path Parameters - **label** (string) - Required - The unique window label. Must be alphanumeric: `a-zA-Z-/:_`. - **options** (WindowOptions) - Required - Options for the window. ### Returns - `Window` - The Window instance to communicate with the window. ### Example ```javascript import { Window } from '@tauri-apps/api/window'; const appWindow = new Window('my-label'); appWindow.once('tauri://created', function () { // window successfully created }); appWindow.once('tauri://error', function (e) { // an error happened creating the window }); ``` ``` -------------------------------- ### Create LogicalSize with width and height Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Constructs a LogicalSize instance using explicit width and height values. ```typescript new LogicalSize(width, height): LogicalSize ``` -------------------------------- ### Create Image from File Path Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Creates a new Image instance from a file path. Supports PNG and ICO formats if the corresponding Cargo features are enabled. Ensure your Cargo.toml includes the necessary image features. ```typescript static fromPath(path): Promise ``` -------------------------------- ### Listen to Window Resize Events Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Attach a listener to detect when the window's size changes. The handler receives the new physical size of the window. Ensure you call the `unlisten` function to properly clean up the event listener. ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onResized(({ payload: size }) => { console.log('Window resized', size); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` -------------------------------- ### tempDir() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns a temporary directory path. ```APIDOC ## tempDir() ### Description Returns a temporary directory. ### Returns `Promise` ### Example ```javascript import { tempDir } from '@tauri-apps/api/path'; const temp = await tempDir(); ``` ### Since 2.0.0 ``` -------------------------------- ### onResized Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Listen to events when the window is resized. This provides the new physical size of the window. ```APIDOC ## onResized(handler: EventCallback) ### Description Listen to window resize. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method - None (This is an SDK method) ### Endpoint - None (This is an SDK method) ### Returns `Promise` 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. ### Request Example ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onResized(({ payload: size }) => { console.log('Window resized', size); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` ### Response #### Success Response (200) - None (This is an SDK method) #### Response Example - None (This is an SDK method) ``` -------------------------------- ### sep() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the platform-specific path segment separator. ```APIDOC ## sep() ### Description Returns the platform-specific path segment separator: * `\` on Windows * `/` on POSIX ### Returns `string` ### Since 2.0.0 ``` -------------------------------- ### resourceDir() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacepath Returns the path to the directory where resources are stored. ```APIDOC ## resourceDir() ### Description Returns the path to the directory where resources are stored. ### Returns `Promise` ### Example ```javascript import { resourceDir } from '@tauri-apps/api/path'; const resourceDirPath = await resourceDir(); ``` ### Since 1.0.0 ``` -------------------------------- ### Convert File Path to Webview URL Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Converts a local file path into a URL that can be used within the webview. Requires specific CSP configurations in `tauri.conf.json` for the `asset` protocol. ```javascript function convertFileSrc(filePath, protocol): string ``` -------------------------------- ### LogicalPosition __TAURI_TO_IPC_KEY__ method Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Returns an object representation suitable for IPC, containing x and y coordinates. ```typescript __TAURI_TO_IPC_KEY__(): object ``` -------------------------------- ### LogicalSize Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Represents a size in logical pixels, which are scaled according to the window's DPI. This is useful for UI elements that need to adapt to different screen resolutions and scaling factors. ```APIDOC ## Class: LogicalSize A size represented in logical pixels. Logical pixels are scaled according to the window’s DPI scale. Most browser APIs (i.e. `MouseEvent`’s `clientX`) will return logical pixels. For logical-pixel-based position, see `LogicalPosition`. ### Since 2.0.0 ### Constructors #### new LogicalSize(width: number, height: number) Creates a new LogicalSize instance. ##### Parameters - `width` (number) - The width in logical pixels. - `height` (number) - The height in logical pixels. ##### Returns `LogicalSize` #### new LogicalSize(object: { Logical: { width: number, height: number } }) Creates a new LogicalSize instance from an object with a nested Logical property. ##### Parameters - `object` (object) - An object containing the logical size. - `object.Logical` (object) - The logical size object. - `object.Logical.width` (number) - The width in logical pixels. - `object.Logical.height` (number) - The height in logical pixels. ##### Returns `LogicalSize` ``` -------------------------------- ### Create LogicalSize with object Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Constructs a LogicalSize instance from an object, supporting nested Logical properties for width and height. ```typescript new LogicalSize(object): LogicalSize ``` -------------------------------- ### Listen to Window Move Events Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Subscribe to events triggered when the window is moved. The handler is provided with the new physical position of the window. Remember to call `unlisten` when the listener is no longer required. ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onMoved(({ payload: position }) => { console.log('Window moved', position); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` -------------------------------- ### Mock convertFileSrc Function Source: https://tauri.app/zh-cn/reference/javascript/api/namespacemocks Mocks the `convertFileSrc` function to simulate file source conversion for a specified operating system. Useful for testing file path handling. ```typescript import { mockConvertFileSrc } from "@tauri-apps/api/mocks"; import { convertFileSrc } from "@tauri-apps/api/core"; mockConvertFileSrc("windows") const url = convertFileSrc("C:\\Users\\user\\file.txt") ``` -------------------------------- ### onMoved Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Listen to events when the window is moved. This provides the new physical position of the window. ```APIDOC ## onMoved(handler: EventCallback) ### Description Listen to window move. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method - None (This is an SDK method) ### Endpoint - None (This is an SDK method) ### Returns `Promise` 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. ### Request Example ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onMoved(({ payload: position }) => { console.log('Window moved', position); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` ### Response #### Success Response (200) - None (This is an SDK method) #### Response Example - None (This is an SDK method) ``` -------------------------------- ### Create Image from Bytes Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Creates a new Image instance from raw byte data. Supports PNG and ICO formats if the corresponding Cargo features are enabled. Ensure your Cargo.toml includes the necessary image features. ```typescript static fromBytes(bytes): Promise ``` -------------------------------- ### mockConvertFileSrc(osName) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacemocks Mocks the `convertFileSrc` function for testing purposes. ```APIDOC ## mockConvertFileSrc(osName) ### Description Mock `convertFileSrc` function. ### Method `mockConvertFileSrc(osName: string): void` ### Parameters #### Path Parameters - **osName** (string) - The operating system to mock, can be one of linux, macos, or windows ### Returns `void` ### Since 1.6.0 ### Example ```javascript import { mockConvertFileSrc } from "@tauri-apps/api/mocks"; import { convertFileSrc } from "@tauri-apps/api/core"; mockConvertFileSrc("windows") const url = convertFileSrc("C:\\Users\\user\\file.txt") ``` ``` -------------------------------- ### ImageSize Interface Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Interface defining the dimensions of an image. ```APIDOC ### Interfaces #### ImageSize Properties: - **height** (number): The height of the image. - **width** (number): The width of the image. ``` -------------------------------- ### Check Plugin Permissions Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Retrieves the permission state for a specified plugin. This function is intended for plugin authors to wrap their permission checking logic. ```javascript function checkPermissions(plugin): Promise ``` -------------------------------- ### checkPermissions() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Retrieves the permission state for a given plugin. This is intended for plugin authors to wrap their implementations. ```APIDOC ## checkPermissions(plugin: string): Promise ### Description Get permission state for a plugin. This should be used by plugin authors to wrap their actual implementation. ### Type Parameters * `T`: The type representing the permission state. ### Parameters * `plugin` (string): The name of the plugin for which to check permissions. ### Returns `Promise`: A promise that resolves with the permission state. ``` -------------------------------- ### Check if Window is Fullscreen Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Retrieves the current fullscreen state of the window. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const fullscreen = await getCurrentWindow().isFullscreen(); ``` -------------------------------- ### Create Image from RGBA Data Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Creates a new Image instance using provided RGBA data, width, and height. The RGBA data should be in row-major order. ```typescript static new( rgba, width, height): Promise ``` -------------------------------- ### Check if Window is Decorated Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Retrieves the current decorated state of the window. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const decorated = await getCurrentWindow().isDecorated(); ``` -------------------------------- ### FluentOverlay Scrollbar Style Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Represents the Fluent UI style overlay scrollbars. This is Windows-only and requires a specific WebView2 Runtime version. ```typescript FluentOverlay: "fluentOverlay"; ``` -------------------------------- ### Listen to Drag and Drop Events Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Listen for file drop events, including hovering, dropping, and cancellation. The handler receives an event object detailing the type and payload of the drop interaction. Ensure `unlisten` is called to clean up the listener. ```javascript import { getCurrentWindow } from "@tauri-apps/api/webview"; const unlisten = await getCurrentWindow().onDragDropEvent((event) => { if (event.payload.type === 'over') { console.log('User hovering', event.payload.position); } 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(); ``` -------------------------------- ### convertFileSrc() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Converts a local file path into a URL that can be used within the webview. Requires specific CSP configurations and asset protocol enablement in `tauri.conf.json`. ```APIDOC ## convertFileSrc(filePath: string, protocol?: string): string ### Description Convert a device file path to an URL that can be loaded by the webview. Note that `asset:` and `http://asset.localhost` must be added to `app.security.csp` in `tauri.conf.json`. Example CSP value: `"csp": "default-src 'self' ipc: http://ipc.localhost; img-src 'self' asset: http://asset.localhost"` to use the asset protocol on image sources. Additionally, `"enable" : "true"` must be added to `app.security.assetProtocol` in `tauri.conf.json` and its access scope must be defined on the `scope` array on the same `assetProtocol` object. ### Parameters * `filePath` (string): The file path to convert. * `protocol` (string, optional): The protocol to use. Defaults to `asset`. You only need to set this when using a custom protocol. ### Returns `string`: The URL that can be used as a source in the webview. ``` -------------------------------- ### Create LogicalPosition with x and y Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Constructs a LogicalPosition instance using explicit x and y coordinates. ```typescript new LogicalPosition(x, y): LogicalPosition ``` -------------------------------- ### close() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Destroys and cleans up a resource from memory. After calling this method, no other methods should be called on the object, and any references to it should be dropped. ```APIDOC ## close() ### Description Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it. ### Returns `Promise` ``` -------------------------------- ### LogicalPosition Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Represents a position in logical pixels, scaled according to the window's DPI. Useful for UI elements that need to maintain consistent size across different screen densities. ```APIDOC ## Class: LogicalPosition A position represented in logical pixels. For an explanation of what logical pixels are, see description of `LogicalSize`. ### Since 2.0.0 ### Constructors #### new LogicalPosition(x: number, y: number) Creates a new LogicalPosition instance. ##### Parameters - `x` (number) - The x-coordinate in logical pixels. - `y` (number) - The y-coordinate in logical pixels. ##### Returns `LogicalPosition` #### new LogicalPosition(object: { Logical: { x: number, y: number } }) Creates a new LogicalPosition instance from an object with a nested Logical property. ##### Parameters - `object` (object) - An object containing the logical position. - `object.Logical` (object) - The logical position object. - `object.Logical.x` (number) - The x-coordinate in logical pixels. - `object.Logical.y` (number) - The y-coordinate in logical pixels. ##### Returns `LogicalPosition` #### new LogicalPosition(object: { x: number, y: number }) Creates a new LogicalPosition instance from an object with x and y properties. ##### Parameters - `object` (object) - An object containing the position. - `object.x` (number) - The x-coordinate in logical pixels. - `object.y` (number) - The y-coordinate in logical pixels. ##### Returns `LogicalPosition` ### Properties - `type` (readonly string) - Always "Logical". - `x` (public number) - The x-coordinate in logical pixels. - `y` (public number) - The y-coordinate in logical pixels. ### Methods #### __TAURI_TO_IPC_KEY__() Internal method for IPC serialization. ##### Returns `object` - An object containing the x and y coordinates. #### toJSON() Converts the LogicalPosition to a plain JavaScript object. ##### Returns `object` - An object with `x` and `y` properties. #### toPhysical(scaleFactor: number) Converts the logical position to a physical one. ##### Parameters - `scaleFactor` (number) - The DPI scale factor of the window. ##### Returns `PhysicalPosition` ##### Example ```javascript import { LogicalPosition } from '@tauri-apps/api/dpi'; import { getCurrentWindow } from '@tauri-apps/api/window'; const appWindow = getCurrentWindow(); const factor = await appWindow.scaleFactor(); const position = new LogicalPosition(400, 500); const physical = position.toPhysical(factor); ``` ##### Since 2.0.0 ``` -------------------------------- ### Mock IPC and Events Source: https://tauri.app/zh-cn/reference/javascript/api/namespacemocks Enables mocking of both IPC requests and event listening/emitting. Use the `shouldMockEvents` option to activate event mocking. This allows testing event handling logic without a real backend. ```typescript import { mockIPC, clearMocks } from "@tauri-apps/api/mocks" import { emit, listen } from "@tauri-apps/api/event" afterEach(() => { clearMocks() }) test("mocked event", () => { mockIPC(() => {}, { shouldMockEvents: true }); // enable event mocking const eventHandler = vi.fn(); listen('test-event', eventHandler); // typically in component setup or similar emit('test-event', { foo: 'bar' }); expect(eventHandler).toHaveBeenCalledWith({ event: 'test-event', payload: { foo: 'bar' } }); }) ``` -------------------------------- ### innerPosition Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Retrieves the position of the top-left corner of the window's client area relative to the top-left corner of the desktop. ```APIDOC ## innerPosition() ### Description Retrieves the position of the top-left corner of the window's client area relative to the top-left corner of the desktop. ### Method `innerPosition(): Promise` ### Returns `Promise` - The window's inner position. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const position = await getCurrentWindow().innerPosition(); ``` ``` -------------------------------- ### onFocusChanged Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Listen to changes in the window's focus state. This event fires when the window gains or loses focus. ```APIDOC ## onFocusChanged(handler: EventCallback) ### Description Listen to window focus change. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method - None (This is an SDK method) ### Endpoint - None (This is an SDK method) ### Returns `Promise` 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. ### Request Example ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onFocusChanged(({ payload: focused }) => { console.log('Focus changed, window is focused? ' + focused); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` ### Response #### Success Response (200) - None (This is an SDK method) #### Response Example - None (This is an SDK method) ``` -------------------------------- ### Listen to Window Focus Change Events Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Register a listener for changes in window focus. The handler receives a boolean indicating whether the window is now focused. It's crucial to call the returned `unlisten` function to prevent memory leaks. ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; const unlisten = await getCurrentWindow().onFocusChanged(({ payload: focused }) => { console.log('Focus changed, window is focused? ' + focused); }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` -------------------------------- ### Convert LogicalPosition to PhysicalPosition Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Converts a logical position to a physical position using a provided scale factor. Requires importing LogicalPosition and getCurrentWindow. ```typescript import { LogicalPosition } from '@tauri-apps/api/dpi'; import { getCurrentWindow } from '@tauri-apps/api/window'; const appWindow = getCurrentWindow(); const factor = await appWindow.scaleFactor(); const position = new LogicalPosition(400, 500); const physical = position.toPhysical(factor); ``` -------------------------------- ### Listen to Window Close Request Event Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Use this to intercept the window close request. You can prevent the window from closing by calling `event.preventDefault()`. Remember to call the returned `unlisten` function when the listener is no longer needed. ```javascript import { getCurrentWindow } from "@tauri-apps/api/window"; import { confirm } from '@tauri-apps/api/dialog'; const unlisten = await getCurrentWindow().onCloseRequested(async (event) => { const confirmed = await confirm('Are you sure?'); if (!confirmed) { // user did not confirm closing the window; let's prevent it event.preventDefault(); } }); // you need to call unlisten if your handler goes out of scope e.g. the component is unmounted unlisten(); ``` -------------------------------- ### isEnabled Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Checks whether the window is enabled or disabled. ```APIDOC ## isEnabled() ### Description Checks whether the window is enabled or disabled. ### Method `isEnabled(): Promise` ### Returns `Promise` - A promise indicating the success or failure of the operation. ### Example ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; await getCurrentWindow().setEnabled(false); ``` ### Since 2.0.0 ``` -------------------------------- ### NativeIcon Enumeration Source: https://tauri.app/zh-cn/reference/javascript/api/namespacemenu Represents native icons that can be used for menu items. Note that some icons are platform-specific and may not be supported on all operating systems. ```APIDOC ## Enumeration: NativeIcon A native Icon to be used for the menu item. Platform-specific: * **Windows / Linux** : Unsupported. ### Members * **Add**: "Add" An add item template image. * **Advanced**: "Advanced" Advanced preferences toolbar icon for the preferences window. * **Bluetooth**: "Bluetooth" A Bluetooth template image. * **Bookmarks**: "Bookmarks" Bookmarks image suitable for a template. * **Caution**: "Caution" A caution image. * **ColorPanel**: "ColorPanel" A color panel toolbar icon. * **ColumnView**: "ColumnView" A column view mode template image. * **Computer**: "Computer" A computer icon. * **EnterFullScreen**: "EnterFullScreen" An enter full-screen mode template image. * **Everyone**: "Everyone" Permissions for all users. * **ExitFullScreen**: "ExitFullScreen" An exit full-screen mode template image. * **FlowView**: "FlowView" A cover flow view mode template image. * **Folder**: "Folder" A folder image. * **FolderBurnable**: "FolderBurnable" A burnable folder icon. * **FolderSmart**: "FolderSmart" A smart folder icon. * **FollowLinkFreestanding**: "FollowLinkFreestanding" A link template image. * **FontPanel**: "FontPanel" A font panel toolbar icon. * **GoLeft**: "GoLeft" A `go back` template image. * **GoRight**: "GoRight" A `go forward` template image. * **Home**: "Home" Home image suitable for a template. * **IChatTheater**: "IChatTheater" An iChat Theater template image. * **IconView**: "IconView" An icon view mode template image. ``` -------------------------------- ### UserAttentionType Enumeration Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Defines types of user attention requests for a window. ```APIDOC ## UserAttentionType ### Description Attention type to request on a window. ### Enumeration Members #### Critical - **Value**: `1` - **Description**: Platform-specific attention request. On macOS, it bounces the dock icon until the application is in focus. On Windows, it flashes both the window and the taskbar button until the application is in focus. #### Informational - **Value**: `2` - **Description**: Platform-specific attention request. On macOS, it bounces the dock icon once. On Windows, it flashes the taskbar button until the application is in focus. ``` -------------------------------- ### mockIPC(cb, options?) Source: https://tauri.app/zh-cn/reference/javascript/api/namespacemocks Intercepts all IPC requests with the given mock handler. This function can be used when testing Tauri frontend applications or when running the frontend in a Node.js context during static site generation. ```APIDOC ## mockIPC(cb, options?) ### Description Intercepts all IPC requests with the given mock handler. This function can be used when testing tauri frontend applications or when running the frontend in a Node.js context during static site generation. ### Method `mockIPC(cb: (cmd: string, payload?: unknown) => unknown, options?: MockIPCOptions): void` ### Parameters #### Path Parameters - **cb** ((cmd, payload?) => unknown) - The callback function to handle IPC requests. - **options?** (MockIPCOptions) - Optional configuration for mocking IPC. ### Returns `void` ### Since 1.0.0 ### Examples #### Testing setup using Vitest: ```javascript import { mockIPC, clearMocks } from "@tauri-apps/api/mocks" import { invoke } from "@tauri-apps/api/core" afterEach(() => { clearMocks() }) test("mocked command", () => { mockIPC((cmd, payload) => { switch (cmd) { case "add": return (payload.a as number) + (payload.b as number); default: break; } }); expect(invoke('add', { a: 12, b: 15 })).resolves.toBe(27); }) ``` #### The callback function can also return a Promise: ```javascript import { mockIPC, clearMocks } from "@tauri-apps/api/mocks" import { invoke } from "@tauri-apps/api/core" afterEach(() => { clearMocks() }) test("mocked command", () => { mockIPC((cmd, payload) => { if(cmd === "get_data") { return fetch("https://example.com/data.json") .then((response) => response.json()) } }); expect(invoke('get_data')).resolves.toBe({ foo: 'bar' }); }) ``` #### `listen` can also be mocked with direct calls to the `emit` function. This functionality is opt-in via the `shouldMockEvents` option: ```javascript import { mockIPC, clearMocks } from "@tauri-apps/api/mocks" import { emit, listen } from "@tauri-apps/api/event" afterEach(() => { clearMocks() }) test("mocked event", () => { mockIPC(() => {}, { shouldMockEvents: true }); // enable event mocking const eventHandler = vi.fn(); listen('test-event', eventHandler); // typically in component setup or similar emit('test-event', { foo: 'bar' }); expect(eventHandler).toHaveBeenCalledWith({ event: 'test-event', payload: { foo: 'bar' } }); }) ``` `emitTo` is currently **not** supported by this mock implementation. ``` -------------------------------- ### Size Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Represents a size in either physical or logical pixels. This type simplifies handling of `tauri::Size` in Rust by automatically serializing into a valid format. ```APIDOC ## Size A size represented either in physical or in logical pixels. This type is basically a union type of `LogicalSize` and `PhysicalSize` but comes in handy when using `tauri::Size` in Rust as an argument to a command, as this class automatically serializes into a valid format so it can be deserialized correctly into `tauri::Size`. ### Constructors #### new Size() ```javascript new Size(size: LogicalSize | PhysicalSize): Size ``` ##### Parameters - **size** (LogicalSize | PhysicalSize) - The size to initialize with. ##### Returns - `Size` - A new Size object. ### Methods #### toJSON() ```javascript toJSON(): object ``` ##### Returns - `object` - A JSON representation of the size. #### toLogical() ```javascript toLogical(scaleFactor: number): LogicalSize ``` ##### Parameters - **scaleFactor** (number) - The scaling factor to convert to logical pixels. ##### Returns - `LogicalSize` - The size in logical pixels. #### toPhysical() ```javascript toPhysical(scaleFactor: number): PhysicalSize ``` ##### Parameters - **scaleFactor** (number) - The scaling factor to convert to physical pixels. ##### Returns - `PhysicalSize` - The size in physical pixels. ``` -------------------------------- ### Create LogicalPosition with object Source: https://tauri.app/zh-cn/reference/javascript/api/namespacedpi Constructs a LogicalPosition instance from an object, supporting nested Logical properties. ```typescript new LogicalPosition(object): LogicalPosition ``` -------------------------------- ### Check if Window is Always on Top Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Determines if the window is configured to stay on top of other windows. Requires importing `getCurrentWindow` from `@tauri-apps/api/window`. ```javascript import { getCurrentWindow } from '@tauri-apps/api/window'; const alwaysOnTop = await getCurrentWindow().isAlwaysOnTop(); ``` -------------------------------- ### Add Plugin Listener Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Adds a listener to a plugin event. Ensure the plugin and event names are correct. The callback function will be invoked with the payload when the event is emitted. ```javascript function addPluginListener( plugin, event, cb): Promise ``` -------------------------------- ### addPluginListener() Source: https://tauri.app/zh-cn/reference/javascript/api/namespacecore Adds a listener to a plugin event. This function is generic and accepts a type parameter `T` for the event payload. ```APIDOC ## addPluginListener(plugin: string, event: string, cb: (payload) => void): Promise ### Description Adds a listener to a plugin event. ### Type Parameters * `T`: The type of the event payload. ### Parameters * `plugin` (string): The name of the plugin. * `event` (string): The name of the event to listen for. * `cb` ((payload) => void): The callback function to execute when the event is triggered. ### Returns `Promise`: A promise that resolves with the listener object, which can be used to stop listening to the events. ``` -------------------------------- ### Image Class Methods Source: https://tauri.app/zh-cn/reference/javascript/api/namespaceimage Methods available on the Image class for accessing and manipulating image data. ```APIDOC ## Image Class An RGBA Image in row-major order from top to bottom. ### Accessors #### rid() ```javascript get rid(): number ``` Returns the resource identifier for this image. ### Methods #### close() ```javascript close(): Promise ``` Destroys and cleans up this resource from memory. You should not call any method on this object anymore and should drop any reference to it. #### rgba() ```javascript rgba(): Promise> ``` Returns the RGBA data for this image, in row-major order from top to bottom. #### size() ```javascript size(): Promise ``` Returns the size of this image. ``` -------------------------------- ### ScrollbarStyle Enumeration Source: https://tauri.app/zh-cn/reference/javascript/api/namespacewindow Defines styles for scrollbars in webviews. ```APIDOC ## ScrollbarStyle ### Description Defines styles for scrollbars in webviews. ### Enumeration Members #### Default - **Value**: `"default"` - **Description**: The default scrollbar style for the webview. #### FluentOverlay - **Value**: `"fluentOverlay"` - **Description**: Fluent UI style overlay scrollbars. **Windows Only**. Requires WebView2 Runtime version 125.0.2535.41 or higher. ```