DNDGamePlayer: Electron редактор сцен, презентация, упаковка electron-builder
Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
|
||||
import type { IpcEventMap, IpcInvokeMap } from '../shared/ipc/contracts';
|
||||
|
||||
export async function invoke<K extends keyof IpcInvokeMap>(
|
||||
channel: K,
|
||||
payload: IpcInvokeMap[K]['req'],
|
||||
): Promise<IpcInvokeMap[K]['res']> {
|
||||
return (await ipcRenderer.invoke(channel as string, payload)) as IpcInvokeMap[K]['res'];
|
||||
}
|
||||
|
||||
export function on<K extends keyof IpcEventMap>(
|
||||
channel: K,
|
||||
listener: (payload: IpcEventMap[K]) => void,
|
||||
): () => void {
|
||||
const wrapped = (_: Electron.IpcRendererEvent, payload: unknown) => {
|
||||
listener(payload as IpcEventMap[K]);
|
||||
};
|
||||
ipcRenderer.on(channel as string, wrapped);
|
||||
return () => {
|
||||
ipcRenderer.off(channel as string, wrapped);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"noEmit": false,
|
||||
"outDir": "../../dist/preload",
|
||||
"moduleResolution": "NodeNext",
|
||||
"module": "NodeNext",
|
||||
"types": ["node", "electron"],
|
||||
"lib": ["ES2022", "DOM"]
|
||||
},
|
||||
"include": ["./**/*.ts"],
|
||||
"exclude": ["../../dist", "../../node_modules"]
|
||||
}
|
||||
Reference in New Issue
Block a user