mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-19 16:21:13 +01:00
Decouple Tree from client app's hotkey system by adding getSelectedItems() to TreeHandle and having callers register hotkeys externally. Extract shared action callbacks to eliminate duplication between hotkey and context menu handlers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
31 lines
895 B
TypeScript
31 lines
895 B
TypeScript
import { invoke } from "@tauri-apps/api/core";
|
|
import { listen as tauriListen } from "@tauri-apps/api/event";
|
|
import type {
|
|
RpcEventSchema,
|
|
RpcSchema,
|
|
} from "@yaakapp-internal/proxy-lib";
|
|
|
|
type Req<K extends keyof RpcSchema> = RpcSchema[K][0];
|
|
type Res<K extends keyof RpcSchema> = RpcSchema[K][1];
|
|
|
|
export async function rpc<K extends keyof RpcSchema>(
|
|
cmd: K,
|
|
payload: Req<K>,
|
|
): Promise<Res<K>> {
|
|
return invoke("rpc", { cmd, payload }) as Promise<Res<K>>;
|
|
}
|
|
|
|
/** Subscribe to a backend event. Returns an unsubscribe function. */
|
|
export function listen<K extends keyof RpcEventSchema>(
|
|
event: K & string,
|
|
callback: (payload: RpcEventSchema[K]) => void,
|
|
): () => void {
|
|
let unsub: (() => void) | null = null;
|
|
tauriListen<RpcEventSchema[K]>(event, (e) => callback(e.payload))
|
|
.then((fn) => {
|
|
unsub = fn;
|
|
})
|
|
.catch(console.error);
|
|
return () => unsub?.();
|
|
}
|