示例工程 01-what-is-electron
01-what-is-electron/app/shared/ipc.ts
/**
* 三端唯一来源:通道名、请求/响应类型。
* 本文件同时被 main / preload / renderer 引用,禁止在这里 import electron。
*/
export const CH = {
info: "app:info",
setTab: "ui:set-tab",
} as const;
export type TabId = "overview" | "processes" | "security";
export type AppInfo = {
electron: string;
node: string;
chrome: string;
platform: string;
arch: string;
mainPid: number;
rendererPid: number;
memoryMB: number;
};
export type Api = {
info(): Promise<AppInfo>;
};
/** 手写校验:不引入第三方库。 */
export function isTabId(value: unknown): value is TabId {
return value === "overview" || value === "processes" || value === "security";
}