30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
import { ipcMain } from "electron";
|
|
import type { CaptureOptions, CaptureResult, CaptureSourceInfo, ClickResult, ScrollResult, AutomationGuard, KeyPressResult } from "../../src/types/global.js";
|
|
|
|
interface CaptureCommandDependencies {
|
|
listSources: () => Promise<CaptureSourceInfo[]>;
|
|
captureSource: (sourceId: string, delayMs?: number, focusGenshin?: boolean, options?: CaptureOptions) => Promise<CaptureResult>;
|
|
clickScreen: (x: number, y: number) => Promise<ClickResult>;
|
|
scrollScreen: (notches: number, anchorX?: number, anchorY?: number) => Promise<ScrollResult>;
|
|
keyPress: (key: string) => Promise<KeyPressResult>;
|
|
getAutomationGuard: () => Promise<AutomationGuard>;
|
|
}
|
|
|
|
export function registerCaptureHandlers({
|
|
listSources,
|
|
captureSource,
|
|
clickScreen,
|
|
scrollScreen,
|
|
keyPress,
|
|
getAutomationGuard,
|
|
}: CaptureCommandDependencies) {
|
|
ipcMain.handle("capture:listSources", async () => listSources());
|
|
ipcMain.handle("capture:captureSource", async (_event, sourceId: string, delayMs = 0, focusGenshin = false, options?: CaptureOptions) => {
|
|
return captureSource(sourceId, delayMs, focusGenshin, options);
|
|
});
|
|
ipcMain.handle("automation:clickScreen", async (_event, x: number, y: number) => clickScreen(x, y));
|
|
ipcMain.handle("automation:scrollScreen", async (_event, notches: number, anchorX?: number, anchorY?: number) => scrollScreen(notches, anchorX, anchorY));
|
|
ipcMain.handle("automation:keyPress", async (_event, key: string) => keyPress(key));
|
|
ipcMain.handle("automation:getGuard", async () => getAutomationGuard());
|
|
}
|