Download electron/src/preload.ts from qf46578/OmniCS: direct link, hf CLI and curl.
- Browser
- Download file 2.73 kB
-
https://huggingface.co/qf46578/OmniCS/resolve/main/electron/src/preload.ts
- Command line
-
hf download hf://qf46578/OmniCS/electron/src/preload.ts
-
curl -L -o preload.ts https://huggingface.co/qf46578/OmniCS/resolve/main/electron/src/preload.ts
2.73 kB
| import { contextBridge, ipcRenderer } from 'electron'; | |
| // 暴露安全的API给渲染进程 | |
| contextBridge.exposeInMainWorld('electronAPI', { | |
| // 截屏 | |
| captureScreen: (region?: { x: number; y: number; width: number; height: number }) => | |
| ipcRenderer.invoke('capture-screen', region), | |
| // OCR识别 | |
| ocrRecognize: (imageBase64: string) => | |
| ipcRenderer.invoke('ocr-recognize', imageBase64), | |
| // 自动化控制 | |
| automation: { | |
| click: (x: number, y: number, button?: 'left' | 'right' | 'middle') => | |
| ipcRenderer.invoke('automation-click', x, y, button), | |
| type: (text: string) => | |
| ipcRenderer.invoke('automation-type', text), | |
| move: (x: number, y: number) => | |
| ipcRenderer.invoke('automation-move', x, y), | |
| hotKey: (keys: string[]) => | |
| ipcRenderer.invoke('automation-hotkey', keys), | |
| findImage: (templateBase64: string) => | |
| ipcRenderer.invoke('automation-find-image', templateBase64), | |
| }, | |
| // 平台自动化 | |
| platform: { | |
| init: (platform: string, config: any) => | |
| ipcRenderer.invoke(`platform-${platform}-init`, config), | |
| poll: (platform: string) => | |
| ipcRenderer.invoke(`platform-${platform}-poll`), | |
| send: (platform: string, customerId: string, message: string) => | |
| ipcRenderer.invoke(`platform-${platform}-send`, customerId, message), | |
| }, | |
| // 事件监听 | |
| on: (channel: string, callback: (...args: any[]) => void) => { | |
| ipcRenderer.on(channel, (_, ...args) => callback(...args)); | |
| }, | |
| removeListener: (channel: string, callback: (...args: any[]) => void) => { | |
| ipcRenderer.removeListener(channel, callback); | |
| }, | |
| }); | |
| // 类型定义 | |
| export interface ElectronAPI { | |
| captureScreen: (region?: { x: number; y: number; width: number; height: number }) => Promise<string>; | |
| ocrRecognize: (imageBase64: string) => Promise<{ text: string; confidence: number }>; | |
| automation: { | |
| click: (x: number, y: number, button?: 'left' | 'right' | 'middle') => Promise<{ success: boolean }>; | |
| type: (text: string) => Promise<{ success: boolean }>; | |
| move: (x: number, y: number) => Promise<{ success: boolean }>; | |
| hotKey: (keys: string[]) => Promise<{ success: boolean }>; | |
| findImage: (templateBase64: string) => Promise<{ x: number; y: number } | null>; | |
| }; | |
| platform: { | |
| init: (platform: string, config: any) => Promise<{ success: boolean }>; | |
| poll: (platform: string) => Promise<any>; | |
| send: (platform: string, customerId: string, message: string) => Promise<{ success: boolean }>; | |
| }; | |
| on: (channel: string, callback: (...args: any[]) => void) => void; | |
| removeListener: (channel: string, callback: (...args: any[]) => void) => void; | |
| } | |
| declare global { | |
| interface Window { | |
| electronAPI: ElectronAPI; | |
| } | |
| } | |