Skip to content
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

Start menu handler ids at one, not zero #14282

Merged
merged 1 commit into from
Oct 10, 2024

Conversation

tsmaeder
Copy link
Contributor

What it does

In order to handle native menu invocations on the browser side, we allocate handler ids when that we send over to the electron-main side. On the electron-main side, we check for the handler id with if (menu.handlerId) before invoking the menu action. Since the handler ids start at 0, the very first menu action created could never be invoked.

Fixes #14279

Contributed on behalf of STMicroelectronics

How to test

This can't really be tested in our example applications. But I think I can convince a reviewer that the change at least does no harm: we just need to make sure menus and context menus still work as advertised.

Follow-ups

Review checklist

Reminder for reviewers

Fixes eclipse-theia#14279

Contributed on behalf of STMicroelectronics

Signed-off-by: Thomas Mäder <t.s.maeder@gmail.com>
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, however, regarding:

On the electron-main side, we check for the handler id with if (menu.handlerId) before invoking the menu action.

Does it make sense to rewrite this to if (typeof menu.handlerId === 'number')? We also do this in the plugin system to ensure that 0 is a valid value.

@tsmaeder
Copy link
Contributor Author

Looks good, however, regarding:

On the electron-main side, we check for the handler id with if (menu.handlerId) before invoking the menu action.

Does it make sense to rewrite this to if (typeof menu.handlerId === 'number')? We also do this in the plugin system to ensure that 0 is a valid value.

While it is the better check in this case, I think it's better to fix this problem at the source, i.e. the generation of the id's in general. Here's why: the client does not have to care whether the id is a number or a string or undefined: the empty string might well be the in indication of "no id" and is often not considered a valid id. It is hard to make sure that we do the check correctly for the type of id in all places, but if we ensure valid id values are never falsy, it just doesn't matter how we check for it. It's more robust as a policy, IMO.

@tsmaeder tsmaeder merged commit 5058c24 into eclipse-theia:master Oct 10, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

First Menu Action not Working with Emtpy Main Menu
2 participants