Skip to content

Commit 5fd02b9

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: falsy context menu handlerId
The very first context menu item with ID `0` has not had a click handler Ref: eclipse-theia/theia#12500 Signed-off-by: Akos Kitta <[email protected]>
1 parent 10b3882 commit 5fd02b9

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: arduino-ide-extension/src/electron-main/arduino-electron-main-module.ts

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
22
import { ElectronMainWindowService } from '@theia/core/lib/electron-common/electron-main-window-service';
33
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
4+
import { TheiaMainApi } from '@theia/core/lib/electron-main/electron-api-main';
45
import {
56
ElectronMainApplication as TheiaElectronMainApplication,
67
ElectronMainApplicationContribution,
@@ -17,6 +18,7 @@ import { ElectronArduino } from './electron-arduino';
1718
import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
1819
import { ElectronMainApplication } from './theia/electron-main-application';
1920
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';
21+
import { TheiaMainApiFixFalsyHandlerId } from './theia/theia-api-main';
2022
import { TheiaElectronWindow } from './theia/theia-electron-window';
2123

2224
export default new ContainerModule((bind, unbind, isBound, rebind) => {
@@ -52,4 +54,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
5254

5355
bind(ElectronArduino).toSelf().inSingletonScope();
5456
bind(ElectronMainApplicationContribution).toService(ElectronArduino);
57+
58+
// eclipse-theia/theia#12500
59+
bind(TheiaMainApiFixFalsyHandlerId).toSelf().inSingletonScope();
60+
rebind(TheiaMainApi).toService(TheiaMainApiFixFalsyHandlerId);
5561
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import {
2+
CHANNEL_INVOKE_MENU,
3+
InternalMenuDto,
4+
} from '@theia/core/lib/electron-common/electron-api';
5+
import { TheiaMainApi } from '@theia/core/lib/electron-main/electron-api-main';
6+
import { injectable } from '@theia/core/shared/inversify';
7+
import { MenuItemConstructorOptions } from '@theia/electron/shared/electron';
8+
9+
@injectable()
10+
export class TheiaMainApiFixFalsyHandlerId extends TheiaMainApi {
11+
override fromMenuDto(
12+
sender: Electron.WebContents,
13+
menuId: number,
14+
menuDto: InternalMenuDto[]
15+
): Electron.MenuItemConstructorOptions[] {
16+
return menuDto.map((dto) => {
17+
const result: MenuItemConstructorOptions = {
18+
id: dto.id,
19+
label: dto.label,
20+
type: dto.type,
21+
checked: dto.checked,
22+
enabled: dto.enabled,
23+
visible: dto.visible,
24+
role: dto.role,
25+
accelerator: dto.accelerator,
26+
};
27+
if (dto.submenu) {
28+
result.submenu = this.fromMenuDto(sender, menuId, dto.submenu);
29+
}
30+
// Fix for handlerId === 0
31+
// https://github.com/eclipse-theia/theia/pull/12500#issuecomment-1686074836
32+
if (typeof dto.handlerId === 'number') {
33+
result.click = () => {
34+
sender.send(CHANNEL_INVOKE_MENU, menuId, dto.handlerId);
35+
};
36+
}
37+
return result;
38+
});
39+
}
40+
}

0 commit comments

Comments
 (0)