|
1 | | -import { ipcMain, BrowserWindow, BrowserView } from 'electron'; |
| 1 | +import { ipcMain, BrowserWindow, BrowserView, Menu } from 'electron'; |
2 | 2 | import { Socket } from 'net'; |
3 | 3 | let electronSocket; |
4 | 4 |
|
@@ -54,4 +54,28 @@ export = (socket: Socket) => { |
54 | 54 | view.webContents.send(channel, ...data); |
55 | 55 | } |
56 | 56 | }); |
| 57 | + |
| 58 | + // Integration helpers: programmatically click menu items from renderer tests |
| 59 | + ipcMain.on('integration-click-application-menu', (event, id: string) => { |
| 60 | + try { |
| 61 | + const menu = Menu.getApplicationMenu(); |
| 62 | + const mi = menu ? menu.getMenuItemById(id) : null; |
| 63 | + if (mi && typeof (mi as any).click === 'function') { |
| 64 | + const bw = BrowserWindow.fromWebContents(event.sender); |
| 65 | + (mi as any).click(undefined, bw, undefined); |
| 66 | + } |
| 67 | + } catch { /* ignore */ } |
| 68 | + }); |
| 69 | + |
| 70 | + ipcMain.on('integration-click-context-menu', (event, windowId: number, id: string) => { |
| 71 | + try { |
| 72 | + const entries = (global as any)['contextMenuItems'] || []; |
| 73 | + const entry = entries.find((x: any) => x.browserWindowId === windowId); |
| 74 | + const mi = entry?.menu?.items?.find((i: any) => i.id === id); |
| 75 | + if (mi && typeof (mi as any).click === 'function') { |
| 76 | + const bw = BrowserWindow.fromId(windowId); |
| 77 | + (mi as any).click(undefined, bw, undefined); |
| 78 | + } |
| 79 | + } catch { /* ignore */ } |
| 80 | + }); |
57 | 81 | }; |
0 commit comments