CH-J ToolsSSH-এর মাধ্যমে সার্ভার ব্যবস্থাপনা
মেনু
প্রকাশিত সোর্স

CH-J Tools

নির্দিষ্ট একটি অ্যাপ্লিকেশন রিলিজের ডিরেক্টরি ও ফাইল ব্রাউজ করুন।

সোর্স ZIP ডাউনলোড করুন
CH-J / Server Manager 872 টি ফাইল
core-20261030T220507Z-61e4558d889f যোগ করা হয়েছে: · বিল্ড হয়েছে:
transport.ts যোগ করা হয়েছে: তারিখ নথিভুক্ত নেই ২.৮ KB · 58 লাইন
কোড ফাইল ডাউনলোড করুন
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 calling
5 * window and checks its permissions. This wrapper is a convenience, NOT a security
6 * boundary.
7 *
8 * Errors are converted to the message format of the Electron 0.1.0 IPC layer
9 * ("Error invoking remote method '<channel>': Error: <message>"), because existing UI
10 * code and third-party modules parse error codes out of that text.
11 */
12import { invoke } from "@tauri-apps/api/core";
13import { listen, type UnlistenFn } from "@tauri-apps/api/event";
14import { getCurrentWebviewWindow } from "@tauri-apps/api/webviewWindow";
15import type { CoreErrorPayload } from "./types";
17export type Unsubscribe = () => void;
19function 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}`);
25/** Invokes a Core command. `channel` is the stable 0.1.0 channel name used in error texts. */
26export 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 }
34/** Fire-and-forget command (Electron `ipcRenderer.send`): failures are logged by the Core only. */
35export function send(command: string, payload: unknown): void {
36 void invoke(command, { payload }).catch(() => {});
39/** Subscribes to a Core push event; returns a synchronous unsubscribe function like 0.1.0. */
40export 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 };
54/** Like `subscribe`, but throws for a non-function callback (module API contract of 0.1.0). */
55export 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);
SHA-256d569ed5d1037ce4c06f388832bda3677b34240582b4f20bc7265146379e8679a

CH-J Proprietary Software License 1.14 · সোর্স CH-J Proprietary Software License 1.14-এর অধীনে দেওয়া হয়। এর প্রাপ্যতা লাইসেন্সের শর্ত বদলায় না এবং অতিরিক্ত কোনো অধিকারও দেয় না।

আর্কাইভ SHA-25677380d4805485ffa4027fbe7858b5836f197a4aa9d52358a43e2d12d018744df
ফাইল