| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- const { contextBridge, ipcRenderer } = require('electron');
- contextBridge.exposeInMainWorld('electronAPI', {
- getAdbPathConfig: () => ipcRenderer.invoke('get-adb-path-config'),
- scanADBDevices: () => ipcRenderer.invoke('scan-adb-devices'),
- getADBDevices: () => ipcRenderer.invoke('get-adb-devices'),
- connectADBDevice: (ipPort) => ipcRenderer.invoke('connect-adb-device', ipPort),
- getDeviceResolution: (ipPort) => ipcRenderer.invoke('get-device-resolution', ipPort),
- captureScreenshot: (ipPort, options) => ipcRenderer.invoke('capture-screenshot', ipPort, options),
- sendTap: (ipPort, x, y) => ipcRenderer.invoke('send-tap', ipPort, x, y),
- sendSwipe: (ipPort, x1, y1, x2, y2, duration) => ipcRenderer.invoke('send-swipe', ipPort, x1, y1, x2, y2, duration),
- sendText: (ipPort, text) => ipcRenderer.invoke('send-text', ipPort, text),
- sendScroll: (ipPort, direction, width, height, scrollDistance, duration) => ipcRenderer.invoke('send-scroll', ipPort, direction, width, height, scrollDistance, duration),
- sendKeyEvent: (ipPort, keyCode) => ipcRenderer.invoke('send-key-event', ipPort, keyCode),
- // 监听设备发现事件
- onDeviceFound: (callback) => {
- ipcRenderer.on('device-found', (event, device) => callback(device));
- },
- // 移除设备发现事件监听器
- removeDeviceFoundListener: () => {
- ipcRenderer.removeAllListeners('device-found');
- },
- // 获取 static 目录下的文件夹列表
- getStaticFolders: () => ipcRenderer.invoke('get-static-folders'),
- // 图像匹配并获取坐标
- matchImageAndGetCoordinate: (ipPort, templateImagePath) => ipcRenderer.invoke('match-image-and-get-coordinate', ipPort, templateImagePath),
- // 图像区域定位:在完整截图中查找区域截图位置,返回四个顶点坐标
- matchImageRegionLocation: (screenshotPath, regionPath, device) => ipcRenderer.invoke('match-image-region-location', screenshotPath, regionPath, device),
- // 读取 processing.json 文件
- readProcessingJson: (folderName) => ipcRenderer.invoke('read-processing-json', folderName),
- // 文字识别并获取坐标
- findTextAndGetCoordinate: (ipPort, targetText) => ipcRenderer.invoke('find-text-and-get-coordinate', ipPort, targetText),
- // OCR识别最后一条消息(兼容旧API)
- ocrLastMessage: (ipPort, method, avatarPath, area, folderPath) => ipcRenderer.invoke('ocr-last-message', ipPort, method, avatarPath, area, folderPath),
- // 提取聊天记录
- extractChatHistory: (ipPort, friendAvatarPath, myAvatarPath, workflowFolderPath) => ipcRenderer.invoke('extract-chat-history', ipPort, friendAvatarPath, myAvatarPath, workflowFolderPath),
- // OCR 聊天记录(向后兼容,重定向到 extract-chat-history)
- ocrChatHistory: (ipPort, friendAvatarPath, myAvatarPath, workflowFolderPath) => ipcRenderer.invoke('ocr-chat-history', ipPort, friendAvatarPath, myAvatarPath, workflowFolderPath),
- // 获取最后一条消息(带发送者信息)
- getLastChatMessage: (ipPort, friendAvatarPath, myAvatarPath) => ipcRenderer.invoke('get-last-chat-message', ipPort, friendAvatarPath, myAvatarPath),
- // 保存工作流(支持图片)
- saveWorkflow: (workflowJson, imagesData) => ipcRenderer.invoke('save-workflow', workflowJson, imagesData),
- // 删除工作流
- deleteWorkflow: (folderName) => ipcRenderer.invoke('delete-workflow', folderName),
- // 确保目录存在
- ensureDirectory: (dirPath) => ipcRenderer.invoke('ensure-directory', dirPath),
- // 写入文本文件
- writeTextFile: (filePath, content) => ipcRenderer.invoke('write-text-file', filePath, content),
- // 读取文本文件
- readTextFile: (filePath) => ipcRenderer.invoke('read-text-file', filePath),
- // 追加日志到文件
- appendLog: (workflowFolderPath, logMessage) => ipcRenderer.invoke('append-log', workflowFolderPath, logMessage),
- // 保存聊天记录
- saveChatHistory: (workflowFolderPath, historyData) => ipcRenderer.invoke('save-chat-history', workflowFolderPath, historyData),
- // 保存聊天记录总结
- saveChatHistorySummary: (workflowFolderPath, summary) => ipcRenderer.invoke('save-chat-history-summary', workflowFolderPath, summary),
- // 获取聊天记录总结
- getChatHistorySummary: (workflowFolderPath) => ipcRenderer.invoke('get-chat-history-summary', workflowFolderPath),
- // 读取最新聊天记录的所有消息
- readLatestChatHistory: (workflowFolderPath) => ipcRenderer.invoke('read-latest-chat-history', workflowFolderPath),
- // 读取最新聊天记录的最后一条消息
- readLastMessage: (workflowFolderPath) => ipcRenderer.invoke('read-last-message', workflowFolderPath),
- // 读取聊天记录(合并所有历史文件)
- readChatHistory: (workflowFolderPath) => ipcRenderer.invoke('read-chat-history', workflowFolderPath),
- // 向后兼容
- readAllChatHistory: (workflowFolderPath) => ipcRenderer.invoke('read-chat-history', workflowFolderPath),
- });
|