More tweaking

This commit is contained in:
Gregory Schier
2026-03-12 08:59:02 -07:00
parent 5e3ef70d93
commit 0b7705d915
11 changed files with 208 additions and 125 deletions

View File

@@ -1,12 +1,11 @@
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';
import { command, subscribe } from './tauri';
export type Req<K extends keyof RpcSchema> = RpcSchema[K][0];
export 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>>;
return command<Res<K>>('rpc', { cmd, payload });
}
/** Subscribe to a backend event. Returns an unsubscribe function. */
@@ -14,11 +13,5 @@ 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?.();
return subscribe<RpcEventSchema[K]>(event, callback);
}