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), 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'); }, });