cvpilot-tool/apps/desktop/electron/preload.ts

28 lines
943 B
TypeScript
Raw Normal View History

2024-08-29 16:59:25 +08:00
import { ipcRenderer, contextBridge } from "electron";
// --------- Expose some API to the Renderer process ---------
contextBridge.exposeInMainWorld("ipcRenderer", {
on(...args: Parameters<typeof ipcRenderer.on>) {
const [channel, listener] = args;
return ipcRenderer.on(channel, (event, ...args) =>
listener(event, ...args)
);
},
off(...args: Parameters<typeof ipcRenderer.off>) {
const [channel, ...omit] = args;
return ipcRenderer.off(channel, ...omit);
},
send(...args: Parameters<typeof ipcRenderer.send>) {
const [channel, ...omit] = args;
return ipcRenderer.send(channel, ...omit);
},
invoke(...args: Parameters<typeof ipcRenderer.invoke>) {
const [channel, ...omit] = args;
return ipcRenderer.invoke(channel, ...omit);
},
2024-09-02 09:41:19 +08:00
once: (...args: Parameters<typeof ipcRenderer.once>) => {
const [channel, ...omit] = args;
return ipcRenderer.once(channel, ...omit);
},
2024-08-29 16:59:25 +08:00
});