Vydané zdroje
Stáhnout zdroje ZIP
CH-J Tools
Procházejte adresáře a soubory konkrétního vydání aplikace.
CH-J / Server Manager
872 souborů
core-20261030T220507Z-61e4558d889f
Přidáno: · Sestaveno:
1
/**2
* Transport between the web UI and the Rust Core.3
*4
* Every call goes to one named Tauri command; the Rust Core identifies the calling5
* window and checks its permissions. This wrapper is a convenience, NOT a security6
* boundary.7
*8
* Errors are converted to the message format of the Electron 0.1.0 IPC layer9
* ("Error invoking remote method '<channel>': Error: <message>"), because existing UI10
* code and third-party modules parse error codes out of that text.11
*/12
import { invoke } from "@tauri-apps/api/core";13
import { listen, type UnlistenFn } from "@tauri-apps/api/event";14
import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";15
import type { CoreErrorPayload } from "./types";17
export type Unsubscribe = () => void;19
function errorFrom(channel: string, reason: unknown): Error {20
const payload = (reason && typeof reason === "object" ? reason : { message: String(reason ?? "Unknown error") }) as Partial<CoreErrorPayload>;21
const message = typeof payload.message === "string" && payload.message ? payload.message : String(payload.code || "Operation failed.");22
return new Error(`Error invoking remote method '${channel}': Error: ${message}`);23
}25
/** Invokes a Core command. `channel` is the stable 0.1.0 channel name used in error texts. */26
export async function call<T>(command: string, channel: string, payload?: unknown): Promise<T> {27
try {28
return await invoke<T>(command, payload === undefined ? {} : { payload });29
} catch (reason) {30
throw errorFrom(channel, reason);31
}32
}34
/** Fire-and-forget command (Electron `ipcRenderer.send`): failures are logged by the Core only. */35
export function send(command: string, payload: unknown): void {36
void invoke(command, { payload }).catch(() => {});37
}39
/** Subscribes to a Core push event; returns a synchronous unsubscribe function like 0.1.0. */40
export function subscribe<T>(event: string, callback: (payload: T) => void): Unsubscribe {41
if (typeof callback !== "function") return () => {};42
let active = true;43
let unlisten: UnlistenFn | null = null;44
// Without a target a window hears events addressed to every other window as well.45
void listen<T>(event, (message) => { if (active) callback(message.payload); }, { target: { kind: "WebviewWindow", label: getCurrentWebviewWindow().label } })46
.then((fn) => { if (active) unlisten = fn; else fn(); })47
.catch(() => {});48
return () => {49
active = false;50
if (unlisten) { unlisten(); unlisten = null; }51
};52
}54
/** Like `subscribe`, but throws for a non-function callback (module API contract of 0.1.0). */55
export function subscribeStrict<T>(event: string, callback: (payload: T) => void, what: string): Unsubscribe {56
if (typeof callback !== "function") throw new TypeError(`${what} callback must be a function.`);57
return subscribe(event, callback);58
}SHA-256
d569ed5d1037ce4c06f388832bda3677b34240582b4f20bc7265146379e8679aCH-J Proprietary Software License 1.14 · Zdroje jsou zveřejněny pod CH-J Proprietary Software License 1.14. Jejich dostupnost nemění licenční podmínky ani neposkytuje další oprávnění.
SHA-256 archivu
77380d4805485ffa4027fbe7858b5836f197a4aa9d52358a43e2d12d018744df