diff --git a/src/backend/electron/ipc.ts b/src/backend/electron/ipc.ts index 891689c182..004e08b65a 100644 --- a/src/backend/electron/ipc.ts +++ b/src/backend/electron/ipc.ts @@ -1,6 +1,33 @@ import { BrowserWindow, ipcMain, IpcMainInvokeEvent } from "electron"; import log from "electron-log/main"; -import { IpcMainHandle, IpcMainSend } from "@/type/ipc"; +import { IpcIHData, IpcSOData } from "@/type/ipc"; + +export type IpcRendererInvoke = { + [K in keyof IpcIHData]: ( + ...args: IpcIHData[K]["args"] + ) => Promise; +}; + +export type IpcMainHandle = { + [K in keyof IpcIHData]: ( + event: import("electron").IpcMainInvokeEvent, + ...args: IpcIHData[K]["args"] + ) => Promise | IpcIHData[K]["return"]; +}; + +export type IpcMainSend = { + [K in keyof IpcSOData]: ( + win: import("electron").BrowserWindow, + ...args: IpcSOData[K]["args"] + ) => void; +}; + +export type IpcRendererOn = { + [K in keyof IpcSOData]: ( + event: import("electron").IpcRendererEvent, + ...args: IpcSOData[K]["args"] + ) => Promise | IpcSOData[K]["return"]; +}; export function registerIpcMainHandle( listeners: T, diff --git a/src/backend/electron/preload.ts b/src/backend/electron/preload.ts index 5fa2680c5c..46f942228a 100644 --- a/src/backend/electron/preload.ts +++ b/src/backend/electron/preload.ts @@ -1,7 +1,7 @@ import { contextBridge, ipcRenderer } from "electron"; +import { IpcRendererInvoke } from "./ipc"; import { Sandbox, ConfigType, EngineId, SandboxKey } from "@/type/preload"; -import { IpcRendererInvoke } from "@/type/ipc"; const ipcRendererInvoke = new Proxy( {}, diff --git a/src/type/ipc.ts b/src/type/ipc.ts index eb23fe0d60..006aca3532 100644 --- a/src/type/ipc.ts +++ b/src/type/ipc.ts @@ -344,30 +344,3 @@ export type IpcSOData = { return: void; }; }; - -export type IpcRendererInvoke = { - [K in keyof IpcIHData]: ( - ...args: IpcIHData[K]["args"] - ) => Promise; -}; - -export type IpcMainHandle = { - [K in keyof IpcIHData]: ( - event: import("electron").IpcMainInvokeEvent, - ...args: IpcIHData[K]["args"] - ) => Promise | IpcIHData[K]["return"]; -}; - -export type IpcMainSend = { - [K in keyof IpcSOData]: ( - win: import("electron").BrowserWindow, - ...args: IpcSOData[K]["args"] - ) => void; -}; - -export type IpcRendererOn = { - [K in keyof IpcSOData]: ( - event: import("electron").IpcRendererEvent, - ...args: IpcSOData[K]["args"] - ) => Promise | IpcSOData[K]["return"]; -}; diff --git a/src/type/preload.ts b/src/type/preload.ts index da5882abae..cef9db48d1 100644 --- a/src/type/preload.ts +++ b/src/type/preload.ts @@ -1,5 +1,5 @@ import { z } from "zod"; -import { IpcRendererOn } from "./ipc"; +import { IpcSOData } from "./ipc"; import { AltPortInfos } from "@/store/type"; import { Result } from "@/type/result"; @@ -264,7 +264,12 @@ export interface Sandbox { readFile(obj: { filePath: string }): Promise>; isAvailableGPUMode(): Promise; isMaximizedWindow(): Promise; - onReceivedIPCMsg(listeners: IpcRendererOn): void; + onReceivedIPCMsg(listeners: { + [K in keyof IpcSOData]: ( + event: unknown, + ...args: IpcSOData[K]["args"] + ) => Promise | IpcSOData[K]["return"]; + }): void; closeWindow(): void; minimizeWindow(): void; maximizeWindow(): void;