From 27b25e6008909733e73dffbef94fdb2b8a875313 Mon Sep 17 00:00:00 2001 From: Hiroshiba Date: Tue, 27 Aug 2024 02:33:46 +0900 Subject: [PATCH] =?UTF-8?q?=E3=81=93=E3=82=93=E3=81=AA=E3=81=8B=E3=82=93?= =?UTF-8?q?=E3=81=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/backend/electron/ipc.ts | 29 ++++++++++++++++++++++++++++- src/backend/electron/preload.ts | 2 +- src/type/ipc.ts | 27 --------------------------- src/type/preload.ts | 9 +++++++-- 4 files changed, 36 insertions(+), 31 deletions(-) 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;