Files
DndGamePlayer/app/preload/index.ts
T

25 lines
606 B
TypeScript

import { contextBridge } from 'electron';
import type { IpcEventMap, IpcInvokeMap } from '../shared/ipc/contracts';
import { invoke, on } from './ipcClient';
export type DndApi = {
invoke: <K extends keyof IpcInvokeMap>(
channel: K,
payload: IpcInvokeMap[K]['req'],
) => Promise<IpcInvokeMap[K]['res']>;
on: <K extends keyof IpcEventMap>(channel: K, listener: (payload: IpcEventMap[K]) => void) => () => void;
};
const api: DndApi = { invoke, on };
contextBridge.exposeInMainWorld('dnd', api);
declare global {
var dnd: DndApi | undefined;
interface Window {
dnd: DndApi;
}
}