preload.cjs 1.2 KB

1234567891011121314151617181920212223
  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) => ipcRenderer.invoke('capture-screenshot', ipPort),
  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. });