core
Invoke your custom commands.
This package is also accessible with window.__TAURIFY__.core
.
Classes
Channel<T>
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Constructors
new Channel()
new Channel<T>(): Channel<T>
Returns
Channel
<T
>
Properties
Property | Type | Defined in |
---|---|---|
id | number |
Accessors
onmessage
Get Signature
get onmessage(): (response) => void
Returns
Function
Parameters
Parameter | Type |
---|---|
response | T |
Returns
void
Set Signature
set onmessage(handler): void
Parameters
Parameter | Type |
---|---|
handler | (response ) => void |
Returns
void
Methods
__TAURI_TO_IPC_KEY__()
__TAURI_TO_IPC_KEY__(): string
Returns
string
toJSON()
toJSON(): string
Returns
string
PluginListener
Constructors
new PluginListener()
new PluginListener( plugin, event, channelId): PluginListener
Parameters
Parameter | Type |
---|---|
plugin | string |
event | string |
channelId | number |
Returns
Properties
Property | Type | Defined in |
---|---|---|
channelId | number | |
event | string | |
plugin | string |
Methods
unregister()
unregister(): Promise<void>
Returns
Promise
<void
>
Resource
A rust-backed resource.
The resource lives in the main process and does not exist
in the JavaScript world, and thus will not be cleaned up automatically
except on application exit. If you want to clean it up early, call Resource.close
Extended by
Constructors
new Resource()
new Resource(rid): Resource
Parameters
Parameter | Type |
---|---|
rid | number |
Returns
Accessors
rid
Get Signature
get rid(): number
Returns
number
Methods
close()
close(): Promise<void>
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
<void
>
Interfaces
InvokeOptions
Properties
Property | Type | Defined in |
---|---|---|
headers | Record <string , string > | Headers |
Type Aliases
InvokeArgs
type InvokeArgs: Record<string, unknown> | number[] | ArrayBuffer | Uint8Array;
Command arguments.
PermissionState
type PermissionState: "granted" | "denied" | "prompt" | "prompt-with-rationale";
Variables
SERIALIZE_TO_IPC_FN
const SERIALIZE_TO_IPC_FN: "__TAURI_TO_IPC_KEY__" = '__TAURI_TO_IPC_KEY__';
Functions
addPluginListener()
function addPluginListener<T>( plugin, event,cb): Promise<PluginListener>
Adds a listener to a plugin event.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
plugin | string |
event | string |
cb | (payload ) => void |
Returns
The listener object to stop listening to the events.
checkPermissions()
function checkPermissions<T>(plugin): Promise<T>
Get permission state for a plugin.
This should be used by plugin authors to wrap their actual implementation.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
plugin | string |
Returns
Promise
<T
>
convertFileSrc()
function convertFileSrc(filePath, protocol): string
Convert a device file path to an URL that can be loaded by the webview.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
filePath | string | undefined | The file path. |
protocol | string | '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.
Example
import { appDataDir, join } from '@crabnebula/taurify-api/path';import { convertFileSrc } from '@crabnebula/taurify-api/core';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();
invoke()
function invoke<T>( cmd, args,options?): Promise<T>
Sends a message to the backend.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type | Description |
---|---|---|
cmd | string | The command name. |
args | InvokeArgs | The optional arguments to pass to the command. |
options ? | InvokeOptions | The request options. |
Returns
Promise
<T
>
A promise resolving or rejecting to the backend response.
Example
import { invoke } from '@crabnebula/taurify-api/core';await invoke('login', { user: 'tauri', password: 'poiwe3h4r5ip3yrhtew9ty' });
isTauri()
function isTauri(): boolean
Returns
boolean
requestPermissions()
function requestPermissions<T>(plugin): Promise<T>
Request permissions.
This should be used by plugin authors to wrap their actual implementation.
Type Parameters
Type Parameter |
---|
T |
Parameters
Parameter | Type |
---|---|
plugin | string |
Returns
Promise
<T
>
transformCallback()
function transformCallback<T>(callback?, once?): 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.
Type Parameters
Type Parameter | Default type |
---|---|
T | unknown |
Parameters
Parameter | Type | Default value |
---|---|---|
callback ? | (response ) => void | undefined |
once ? | boolean | false |
Returns
number
A unique identifier associated with the callback function.