preload.cjs 1.9 KB

1234567891011121314151617181920212223242526272829303132
  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. sendScroll: (ipPort, direction, width, height, scrollDistance, duration) => ipcRenderer.invoke('send-scroll', ipPort, direction, width, height, scrollDistance, duration),
  13. sendKeyEvent: (ipPort, keyCode) => ipcRenderer.invoke('send-key-event', ipPort, keyCode),
  14. // 监听设备发现事件
  15. onDeviceFound: (callback) => {
  16. ipcRenderer.on('device-found', (event, device) => callback(device));
  17. },
  18. // 移除设备发现事件监听器
  19. removeDeviceFoundListener: () => {
  20. ipcRenderer.removeAllListeners('device-found');
  21. },
  22. // 获取 static 目录下的文件夹列表
  23. getStaticFolders: () => ipcRenderer.invoke('get-static-folders'),
  24. // 图像匹配并获取坐标
  25. matchImageAndGetCoordinate: (ipPort, templateImagePath) => ipcRenderer.invoke('match-image-and-get-coordinate', ipPort, templateImagePath),
  26. // 读取 processing.json 文件
  27. readProcessingJson: (folderName) => ipcRenderer.invoke('read-processing-json', folderName),
  28. // 文字识别并获取坐标
  29. findTextAndGetCoordinate: (ipPort, targetText) => ipcRenderer.invoke('find-text-and-get-coordinate', ipPort, targetText),
  30. });