Skip to content

Commit 423ea57

Browse files
committed
ipc.ts: Add helper method for tests
1 parent 8dcc372 commit 423ea57

File tree

3 files changed

+51
-2
lines changed

3 files changed

+51
-2
lines changed

src/ElectronNET.Host/api/ipc.js

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/ipc.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ElectronNET.Host/api/ipc.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ipcMain, BrowserWindow, BrowserView } from 'electron';
1+
import { ipcMain, BrowserWindow, BrowserView, Menu } from 'electron';
22
import { Socket } from 'net';
33
let electronSocket;
44

@@ -54,4 +54,28 @@ export = (socket: Socket) => {
5454
view.webContents.send(channel, ...data);
5555
}
5656
});
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+
});
5781
};

0 commit comments

Comments
 (0)