preload.cjs 1.8 KB

12345678910111213141516171819202122232425262728293031
  1. const { contextBridge, ipcRenderer } = require('electron');
  2. contextBridge.exposeInMainWorld('electronAPI', {
  3. getAdbPathConfig: () => ipcRenderer.invoke('get-adb-path-config'),
  4. scanADBDevices: () => ipcRenderer.invoke('scan-adb-devices'),
  5. getADBDevices: () => ipcRenderer.invoke('get-adb-devices'),
  6. connectADBDevice: (ipPort) => ipcRenderer.invoke('connect-adb-device', ipPort),
  7. getDeviceResolution: (ipPort) => ipcRenderer.invoke('get-device-resolution', ipPort),
  8. captureScreenshot: (ipPort, options) => ipcRenderer.invoke('capture-screenshot', ipPort, options),
  9. sendTap: (ipPort, x, y) => ipcRenderer.invoke('send-tap', ipPort, x, y),
  10. sendSwipe: (ipPort, x1, y1, x2, y2, duration) => ipcRenderer.invoke('send-swipe', ipPort, x1, y1, x2, y2, duration),
  11. sendText: (ipPort, text) => ipcRenderer.invoke('send-text', ipPort, text),
  12. sendKeyEvent: (ipPort, keyCode) => ipcRenderer.invoke('send-key-event', ipPort, keyCode),
  13. // 监听设备发现事件
  14. onDeviceFound: (callback) => {
  15. ipcRenderer.on('device-found', (event, device) => callback(device));
  16. },
  17. // 移除设备发现事件监听器
  18. removeDeviceFoundListener: () => {
  19. ipcRenderer.removeAllListeners('device-found');
  20. },
  21. // 获取 static 目录下的文件夹列表
  22. getStaticFolders: () => ipcRenderer.invoke('get-static-folders'),
  23. // 图像匹配并获取坐标
  24. matchImageAndGetCoordinate: (ipPort, templateImagePath) => ipcRenderer.invoke('match-image-and-get-coordinate', ipPort, templateImagePath),
  25. // 读取 processing.json 文件
  26. readProcessingJson: (folderName) => ipcRenderer.invoke('read-processing-json', folderName),
  27. // 文字识别并获取坐标
  28. findTextAndGetCoordinate: (ipPort, targetText) => ipcRenderer.invoke('find-text-and-get-coordinate', ipPort, targetText),
  29. });