Skip to content

fix: falsy context menu handlerId #2183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 21, 2023
commit 1500df71c97fe8bb6a90b10b6afc9b7d6312c192
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { JsonRpcConnectionHandler } from '@theia/core/lib/common/messaging/proxy-factory';
import { ElectronMainWindowService } from '@theia/core/lib/electron-common/electron-main-window-service';
import { ElectronConnectionHandler } from '@theia/core/lib/electron-common/messaging/electron-connection-handler';
import { TheiaMainApi } from '@theia/core/lib/electron-main/electron-api-main';
import {
ElectronMainApplication as TheiaElectronMainApplication,
ElectronMainApplicationContribution,
Expand All @@ -17,6 +18,7 @@ import { ElectronArduino } from './electron-arduino';
import { IDEUpdaterImpl } from './ide-updater/ide-updater-impl';
import { ElectronMainApplication } from './theia/electron-main-application';
import { ElectronMainWindowServiceImpl } from './theia/electron-main-window-service';
import { TheiaMainApiFixFalsyHandlerId } from './theia/theia-api-main';
import { TheiaElectronWindow } from './theia/theia-electron-window';

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

bind(ElectronArduino).toSelf().inSingletonScope();
bind(ElectronMainApplicationContribution).toService(ElectronArduino);

// eclipse-theia/theia#12500
bind(TheiaMainApiFixFalsyHandlerId).toSelf().inSingletonScope();
rebind(TheiaMainApi).toService(TheiaMainApiFixFalsyHandlerId);
});
40 changes: 40 additions & 0 deletions arduino-ide-extension/src/electron-main/theia/theia-api-main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
CHANNEL_INVOKE_MENU,
InternalMenuDto,
} from '@theia/core/lib/electron-common/electron-api';
import { TheiaMainApi } from '@theia/core/lib/electron-main/electron-api-main';
import { injectable } from '@theia/core/shared/inversify';
import { MenuItemConstructorOptions } from '@theia/electron/shared/electron';

@injectable()
export class TheiaMainApiFixFalsyHandlerId extends TheiaMainApi {
override fromMenuDto(
sender: Electron.WebContents,
menuId: number,
menuDto: InternalMenuDto[]
): Electron.MenuItemConstructorOptions[] {
return menuDto.map((dto) => {
const result: MenuItemConstructorOptions = {
id: dto.id,
label: dto.label,
type: dto.type,
checked: dto.checked,
enabled: dto.enabled,
visible: dto.visible,
role: dto.role,
accelerator: dto.accelerator,
};
if (dto.submenu) {
result.submenu = this.fromMenuDto(sender, menuId, dto.submenu);
}
// Fix for handlerId === 0
// https://github.com/eclipse-theia/theia/pull/12500#issuecomment-1686074836
if (typeof dto.handlerId === 'number') {
result.click = () => {
sender.send(CHANNEL_INVOKE_MENU, menuId, dto.handlerId);
};
}
return result;
});
}
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy