Skip to content
Tauri
Releases

tauri

Invoke your custom commands.

This package is also accessible with window.__TAURI__.tauri when build.withGlobalTauri in tauri.conf.json is set to true.

Type Aliases

InvokeArgs

InvokeArgs: Record<string, unknown>;

Command arguments.

Since

1.0.0

Source: tauri.ts:66

Functions

convertFileSrc()

convertFileSrc(filePath, protocol = 'asset'): string

Convert a device file path to an URL that can be loaded by the webview. Note that asset: and https://asset.localhost must be added to tauri.security.csp in tauri.conf.json. Example CSP value: "csp": "default-src 'self'; img-src 'self' asset: https://asset.localhost" to use the asset protocol on image sources.

Additionally, asset must be added to tauri.allowlist.protocol in tauri.conf.json and its access scope must be defined on the assetScope array on the same protocol object.

Example

import { appDataDir, join } from '@tauri-apps/api/path';
import { convertFileSrc } from '@tauri-apps/api/tauri';
const appDataDirPath = await appDataDir();
const filePath = await join(appDataDirPath, 'assets/video.mp4');
const assetUrl = convertFileSrc(filePath);
const video = document.getElementById('my-video');
const source = document.createElement('source');
source.type = 'video/mp4';
source.src = assetUrl;
video.appendChild(source);
video.load();

Since

1.0.0

Parameters

ParameterTypeDefault valueDescription
filePathstringundefinedThe file path.
protocolstring'asset'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 source on the webview.

Source: tauri.ts:132


transformCallback()

transformCallback(callback?, once? = false): number

Transforms a callback function to a string identifier that can be passed to the backend. The backend uses the identifier to eval() the callback.

Since

1.0.0

Parameters

ParameterTypeDefault value
callback?(response) => voidundefined
once?booleanfalse

Returns

number

A unique identifier associated with the callback function.

Source: tauri.ts:39


© 2024 Tauri Contributors. CC-BY / MIT