DNDGamePlayer: Electron редактор сцен, презентация, упаковка electron-builder
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
import { ipcMain } from 'electron';
|
||||
|
||||
import type { IpcInvokeMap } from '../../shared/ipc/contracts';
|
||||
|
||||
type Handler<K extends keyof IpcInvokeMap> = (
|
||||
payload: IpcInvokeMap[K]['req'],
|
||||
) => Promise<IpcInvokeMap[K]['res']> | IpcInvokeMap[K]['res'];
|
||||
|
||||
const handlers = new Map<string, (payload: unknown) => Promise<unknown>>();
|
||||
|
||||
export function registerHandler<K extends keyof IpcInvokeMap>(channel: K, handler: Handler<K>) {
|
||||
handlers.set(channel as string, async (payload: unknown) => handler(payload as IpcInvokeMap[K]['req']));
|
||||
}
|
||||
|
||||
export function installIpcRouter() {
|
||||
for (const [channel, handler] of handlers.entries()) {
|
||||
ipcMain.handle(channel, async (_event, payload: unknown) => handler(payload));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user