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

Support dynamic menu contributions #13720

Merged
merged 2 commits into from
Jun 25, 2024
Merged

Conversation

msujew
Copy link
Member

@msujew msujew commented May 17, 2024

What it does

Closes #13719

Adds a new onDidChange event to the MenuModelRegistry. Any changes to the menus (i.e. registering, unregistering, disposal) fire this event now. Adds a listener to this event in the menu factories to ensure that the menus are correctly recreated.

How to test

  1. Adjust some of the sample-menu-contribution.ts file:
setTimeout(() => {
  const disposable = menus.registerMenuAction(subSubMenuPath, {
    commandId: SampleCommand2.id,
    order: '3'
  });
  setTimeout(() => disposable.dispose(), 8000);
}, 8000);
  1. After starting the app, open the Sample Menu > Sample sub menu
  2. It should only show 2 entries
  3. After a few seconds the menu should refresh showing an additional entry
  4. A few seconds later the entry should disappear again.

Follow-ups

I've noticed that the menu flashes when the model is changed (i.e. any open main sub menus are closed). That's something that could maybe be addressed in a separate PR. A smart diffing of the menu bar HTML element would probably be appropriate here.

Review checklist

Reminder for reviewers

@msujew msujew added the menus issues related to the menu label May 17, 2024
@msujew
Copy link
Member Author

msujew commented May 17, 2024

cc @kittaakos this is maybe interesting for you.

@rschnekenbu
Copy link
Contributor

@msujew, on my machine (Linux), I tried both electron and browser version (also both on original branch and branch rebased on latest master).
On browser version, the menu disappears when it is refreshing. If I open it again, I have the right number of commands depending on the timeout. I understand the menu should refresh and content is added/remove, but it should stay visible?
On electron version, the menu stays (there is a kind of small flash on the top menu, as it was deselected), but the content is not updated. If I close it and reopen it, then the content is correct.
I can of course run some screen recording to show you what is happening on my machine for both version if you want.

@msujew
Copy link
Member Author

msujew commented Jun 24, 2024

@rschnekenbu I've mentioned this in the follow-ups of the PR:

I've noticed that the menu flashes when the model is changed (i.e. any open main sub menus are closed). That's something that could maybe be addressed in a separate PR. A smart diffing of the menu bar HTML element would probably be appropriate here.

The main issue is that on the browser, the whole HTML element is replaced, which in turn leads to losing some state information. I would try looking into this in a separate PR as indicated above.

In Electron, we're bound by the limits of the underlying OS. I'm not even sure you can add/remove native window menu entries while they're open on Windows (my OS) or other OS'. I'll take a look at this as well, but I can't promise anything here.

@rschnekenbu
Copy link
Contributor

@rschnekenbu I've mentioned this in the follow-ups of the PR:

I've noticed that the menu flashes when the model is changed (i.e. any open main sub menus are closed). That's something that could maybe be addressed in a separate PR. A smart diffing of the menu bar HTML element would probably be appropriate here.
Indeed, that makes sense. This could be indeed part of a second PR.

Other than these rendering issues, I am OK with this PR. I will approve it.

Copy link
Contributor

@rschnekenbu rschnekenbu 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 with of course the current known limitations :) Thanks @msujew!

@msujew msujew merged commit adf13a0 into master Jun 25, 2024
14 checks passed
@msujew msujew deleted the msujew/dynamic-menu-contributions branch June 25, 2024 09:36
@github-actions github-actions bot added this to the 1.51.0 milestone Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
menus issues related to the menu
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Dynamically registered menus are ignored by the menu renderer
2 participants