()
| 29 | } |
| 30 | |
| 31 | private setupIPC(): void { |
| 32 | // 发送输入事件到插件 |
| 33 | ipcMain.handle( |
| 34 | 'send-input-event', |
| 35 | ( |
| 36 | _event, |
| 37 | inputEvent: |
| 38 | | Electron.MouseInputEvent |
| 39 | | Electron.MouseWheelInputEvent |
| 40 | | Electron.KeyboardInputEvent |
| 41 | ) => this.sendInputEvent(inputEvent) |
| 42 | ) |
| 43 | |
| 44 | // 模拟键盘按键 |
| 45 | ipcMain.on('simulate-keyboard-tap', (event, key: string, modifiers: string[]) => { |
| 46 | event.returnValue = this.simulateKeyboardTap(key, modifiers) |
| 47 | }) |
| 48 | |
| 49 | // 模拟鼠标移动 |
| 50 | ipcMain.on('simulate-mouse-move', (event, x: number, y: number) => { |
| 51 | event.returnValue = this.simulateMouseMove(x, y) |
| 52 | }) |
| 53 | |
| 54 | // 模拟鼠标左键单击 |
| 55 | ipcMain.on('simulate-mouse-click', (event, x: number, y: number) => { |
| 56 | event.returnValue = this.simulateMouseClick(x, y) |
| 57 | }) |
| 58 | |
| 59 | // 模拟鼠标左键双击 |
| 60 | ipcMain.on('simulate-mouse-double-click', (event, x: number, y: number) => { |
| 61 | event.returnValue = this.simulateMouseDoubleClick(x, y) |
| 62 | }) |
| 63 | |
| 64 | // 模拟鼠标右键单击 |
| 65 | ipcMain.on('simulate-mouse-right-click', (event, x: number, y: number) => { |
| 66 | event.returnValue = this.simulateMouseRightClick(x, y) |
| 67 | }) |
| 68 | |
| 69 | // 检查当前插件是否处于开发模式 |
| 70 | ipcMain.on('is-dev', (event) => { |
| 71 | event.returnValue = this.pluginManager?.isPluginDev(event.sender.id) ?? false |
| 72 | }) |
| 73 | |
| 74 | // 获取当前 WebContents ID |
| 75 | ipcMain.on('get-web-contents-id', (event) => { |
| 76 | event.returnValue = event.sender.id |
| 77 | }) |
| 78 | |
| 79 | // 在当前插件页面中查找文本 |
| 80 | ipcMain.handle('find-in-page', (event, text: string, options?: Electron.FindInPageOptions) => { |
| 81 | try { |
| 82 | const webContents = event.sender |
| 83 | if (webContents.isDestroyed()) { |
| 84 | return { success: false, error: '页面已销毁' } |
| 85 | } |
| 86 | // 确保监听 found-in-page 事件以转发结果 |
| 87 | this.ensureFoundInPageListener(webContents) |
| 88 | const requestId = webContents.findInPage(text, options) |
no test coverage detected