Skip to content

Commit

Permalink
こんなかんじ
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiroshiba committed Aug 26, 2024
1 parent 3b0c162 commit 27b25e6
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
29 changes: 28 additions & 1 deletion src/backend/electron/ipc.ts
Original file line number Diff line number Diff line change
@@ -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<IpcIHData[K]["return"]>;
};

export type IpcMainHandle = {
[K in keyof IpcIHData]: (
event: import("electron").IpcMainInvokeEvent,
...args: IpcIHData[K]["args"]
) => Promise<IpcIHData[K]["return"]> | 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"]> | IpcSOData[K]["return"];
};

export function registerIpcMainHandle<T extends IpcMainHandle>(
listeners: T,
Expand Down
2 changes: 1 addition & 1 deletion src/backend/electron/preload.ts
Original file line number Diff line number Diff line change
@@ -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(
{},
Expand Down
27 changes: 0 additions & 27 deletions src/type/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,30 +344,3 @@ export type IpcSOData = {
return: void;
};
};

export type IpcRendererInvoke = {
[K in keyof IpcIHData]: (
...args: IpcIHData[K]["args"]
) => Promise<IpcIHData[K]["return"]>;
};

export type IpcMainHandle = {
[K in keyof IpcIHData]: (
event: import("electron").IpcMainInvokeEvent,
...args: IpcIHData[K]["args"]
) => Promise<IpcIHData[K]["return"]> | 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"]> | IpcSOData[K]["return"];
};
9 changes: 7 additions & 2 deletions src/type/preload.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -264,7 +264,12 @@ export interface Sandbox {
readFile(obj: { filePath: string }): Promise<Result<ArrayBuffer>>;
isAvailableGPUMode(): Promise<boolean>;
isMaximizedWindow(): Promise<boolean>;
onReceivedIPCMsg(listeners: IpcRendererOn): void;
onReceivedIPCMsg(listeners: {
[K in keyof IpcSOData]: (
event: unknown,
...args: IpcSOData[K]["args"]
) => Promise<IpcSOData[K]["return"]> | IpcSOData[K]["return"];
}): void;
closeWindow(): void;
minimizeWindow(): void;
maximizeWindow(): void;
Expand Down

0 comments on commit 27b25e6

Please sign in to comment.