-
-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]>
- Loading branch information
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
arduino-ide-extension/src/electron-main/theia/theia-api-main.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} | ||
} |