示例工程 07-project-process-explorer

07-project-process-explorer/app/preload/index.ts

typescript · 0.5 KB

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);