@zturnlibs/ztron-api


core

Classes

Channel

Defined in: core.ts:34

A channel used to receive ordered streaming messages from the backend.

The ordering logic is preserved from the Tauri implementation: messages carry a monotonically increasing index and are delivered in order, with out-of-order messages queued until the gap is filled.

Type Parameters

T

T = unknown

Constructors

Constructor

new Channel<T>(onmessage?): Channel<T>

Defined in: core.ts:44

Parameters
onmessage?

(response) => void

Returns

Channel<T>

Properties

id

id: number

Defined in: core.ts:36

The callback id returned from transformCallback.

Accessors

onmessage
Get Signature

get onmessage(): (response) => void

Defined in: core.ts:101

Returns

(response) => void

Set Signature

set onmessage(handler): void

Defined in: core.ts:97

Parameters
handler

(response) => void

Returns

void

Methods

__ZTRON_TO_IPC_KEY__()

__ZTRON_TO_IPC_KEY__(): string

Defined in: core.ts:105

Returns

string

dispose()

dispose(): void

Defined in: core.ts:93

Client-side end: unregisters this channel's callback from the bridge registry immediately, without waiting for an in-order end marker from the backend. Call it when a stream is abandoned client-side (e.g. the consuming component unmounted) so late backend messages can no longer reach the dead callback. Idempotent.

Returns

void

toJSON()

toJSON(): string

Defined in: core.ts:109

Returns

string


Resource

Defined in: core.ts:147

A backend-owned resource stored through the resource table. Lives in the main process and is released explicitly via close.

Constructors

Constructor

new Resource(rid): Resource

Defined in: core.ts:154

Parameters
rid

number

Returns

Resource

Accessors

rid
Get Signature

get rid(): number

Defined in: core.ts:150

Returns

number

Methods

close()

close(): Promise<void>

Defined in: core.ts:159

Destroys and cleans up this resource from memory.

Returns

Promise<void>

Variables

SERIALIZE_TO_IPC_FN

const SERIALIZE_TO_IPC_FN: "__ZTRON_TO_IPC_KEY__" = "__ZTRON_TO_IPC_KEY__"

Defined in: core.ts:12

A key used by special types to define how they serialize across the IPC. If this value changes, keep it in sync with the inject package.

Functions

addPluginListener()

addPluginListener<T>(plugin, event, cb): Promise<() => Promise<void>>

Defined in: core.ts:181

Registers a backend plugin listener, mirroring Tauri's addPluginListener (plugin:<plugin>|__listener / __unlistener commands). Plugins like log use this instead of named events because event names cannot contain |.

Type Parameters

T

T = unknown

Parameters

plugin

string

event

string

cb

(payload) => void

Returns

Promise<() => Promise<void>>

A promise resolving to an unlisten function.


convertFileSrc()

convertFileSrc(filePath, protocol?): string

Defined in: core.ts:137

Converts a device file path to an URL that can be loaded by the WebView.

Parameters

filePath

string

The file path.

protocol?

string

The protocol to use. Defaults to asset.

Returns

string

The URL usable as a source in the WebView.


invoke()

invoke<T>(cmd, args?, options?): Promise<T>

Defined in: core.ts:122

Sends a message to the backend.

Type Parameters

T

T

Parameters

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.


isZtron()

isZtron(): boolean

Defined in: core.ts:165

Whether the current context is a Ztron WebView.

Returns

boolean


transformCallback()

transformCallback<T>(callback?, once?): number

Defined in: core.ts:20

Stores a callback in a known location and returns an identifier the backend can use to eval() it later.

Type Parameters

T

T = unknown

Parameters

callback?

(response) => void

once?

boolean = false

Returns

number

A unique identifier associated with the callback.

References

InvokeArgs

Re-exports InvokeArgs


InvokeOptions

Re-exports InvokeOptions