示例工程 07-project-process-explorer
07-project-process-explorer/app/preload/index.ts
import { contextBridge, ipcRenderer } from "electron";
import {
CH,
type Api,
type CreateResult,
type ExplorerInfo,
type FocusResult,
type KillResult,
} from "../shared/ipc";
const api: Api = {
list: (): Promise<ExplorerInfo> => ipcRenderer.invoke(CH.list),
kill: (id: number): Promise<KillResult> => ipcRenderer.invoke(CH.kill, id),
focus: (id: number): Promise<FocusResult> => ipcRenderer.invoke(CH.focus, id),
create: (): Promise<CreateResult> => ipcRenderer.invoke(CH.create),
};
contextBridge.exposeInMainWorld("api", api);