示例工程 04-lifecycle-and-windows

04-lifecycle-and-windows/app/shared/ipc.ts

typescript · 0.9 KB

/**
 * 三端唯一来源:通道名与类型。
 * 本文件不 import electron,渲染进程也能安全引用。
 */
export const CH = {
  info: "lifecycle:info",
  open: "window:open",
  minimize: "window:minimize",
  maximize: "window:maximize",
  close: "window:close",
} as const;

export type Bounds = {
  x: number;
  y: number;
  width: number;
  height: number;
};

export type WindowSnapshot = {
  id: number;
  bounds: Bounds;
  focused: boolean;
  minimized: boolean;
  maximized: boolean;
};

export type LifecycleEvent = {
  at: number;
  name: string;
  detail?: string;
};

export type LifecycleInfo = {
  events: LifecycleEvent[];
  windows: WindowSnapshot[];
  singleInstance: boolean;
  ready: boolean;
};

export type Api = {
  info(): Promise<LifecycleInfo>;
  open(): Promise<{ ok: boolean }>;
  minimize(): Promise<{ ok: boolean }>;
  maximize(): Promise<{ ok: boolean }>;
  close(): Promise<{ ok: boolean }>;
};