Skip to content

Add async menu.popup option - #8702

Merged
kevinsawicki merged 16 commits into
masterfrom
async-menu-popup
Feb 22, 2017
Merged

kevinsawicki merged 16 commits into
masterfrom
async-menu-popup

Conversation

@kevinsawicki

@kevinsawicki kevinsawicki commented Feb 16, 2017 •

Copy link
Copy Markdown
Contributor

Adds an async option to menu.popup that returns immediately on each platform and does not block the render loop on macOS.

The menu.popup signature is also updated (but backwards-compatible) to take an options object instead of x, y, and positioningItem arguments.

win.webContents.on('context-menu', (event, params) => {
  menu.popup(win, {
    x: params.x,
    y: params.y,
    async: true
  })

  // Close it for some reason after 2 seconds
  setTimeout(function () {
    menu.closePopup(win)
  }, 2000)
})
Sync (current behavior) Async (new behavior)
sync-menu async-menu
  • Implement async option on macOS
  • Implement async option on Linux/Windows
  • Implement menu.closePopup on macOS
  • Implement menu.closePopup on Linux/Windows
  • Update menu.md API docs
  • Add new method signature to planned-breaking-changes.md
  • Add tests

This does not change the default behavior, this new option is opt-in but that default could be revisited in the 2.0 API.

This pull request also adds a new menu.closePopup([browserWindow]) API that can be used to explicitly close the context menu.

Closes #1854

@bsclifton

bsclifton commented Feb 19, 2017 •

Copy link
Copy Markdown
Contributor

@kevinsawicki any reason this is defaulted to async=false? Since Windows works great, I would think defaulting to true (and omitting the parameter altogether) would be the way to go

edit: I need to learn to read (derp on my part)- it's defaulted to false to keep the behavior the same, in case this would be a breaking change 😄

bsclifton added a commit to brave/muon that referenced this pull request Feb 19, 2017
@kevinsawicki
kevinsawicki merged commit 62f4a77 into master Feb 22, 2017
@kevinsawicki
kevinsawicki deleted the async-menu-popup branch February 22, 2017 20:51
@kevinsawicki

Copy link
Copy Markdown
Contributor Author

@bsclifton just a heads up, I pushed a few more tweaks to this if you end up pulling this into Brave in brave/muon#161

@bsclifton

Copy link
Copy Markdown
Contributor

@kevinsawicki great, thank you! 😄

bsclifton added a commit to brave/muon that referenced this pull request Feb 23, 2017
bsclifton added a commit to brave/muon that referenced this pull request Feb 23, 2017
bsclifton added a commit to brave/muon that referenced this pull request Feb 28, 2017
bsclifton added a commit to brave/muon that referenced this pull request Feb 28, 2017
CharlieHess added a commit to electron-userland/electron-spellchecker that referenced this pull request Mar 16, 2017
bsclifton added a commit to brave/muon that referenced this pull request May 9, 2017
bsclifton added a commit to brave/muon that referenced this pull request May 9, 2017
@bpasero

bpasero commented May 11, 2017 •

Copy link
Copy Markdown
Contributor

@kevinsawicki about this becoming the default or not in 2.0, isn't this quite a breaking change for people that have code like this (pseudo):

menu.popup(async: false);
onMenuClosedCallback.fire(true); // <-- if async is true, this would fire directly, even though the menu was not dismissed

We in VS Code for example need to know in certain cases when the menu was closed (which can happen not only when a menu item is picked but also when the user clicks somewhere else or hits escape) and as far as I know there is no event that we can use to find out. This is also the reason why at the moment we cannot really adopt the async: true option.

I think what is missing compared to the async: false solution is a way to find out that the menu was closed (e.g. by passing in a callback to the popup function that is called).

Wouldn't it make sense to align the API here with how dialogs work and just make the popup call async if a callback is passed in and otherwise make it sync?

@kevinsawicki

Copy link
Copy Markdown
Contributor Author

Wouldn't it make sense to align the API here with how dialogs work and just make the popup call async if a callback is passed in and otherwise make it sync?

Yeah, could add this for sure 👍

@kevinsawicki

Copy link
Copy Markdown
Contributor Author

@bpasero want to open a new issue to track the callback option to menu.popup?

@bpasero

bpasero commented May 12, 2017

Copy link
Copy Markdown
Contributor

@kevinsawicki done #9441

bsclifton added a commit to brave/muon that referenced this pull request May 24, 2017
bsclifton added a commit to brave/muon that referenced this pull request May 24, 2017
bsclifton added a commit to brave/muon that referenced this pull request May 24, 2017
Additional updates (per electron/electron#8702)

Fixes brave/browser-laptop#5470

- Default `async` to true for popup menus
- fix lint errors
- menus do not destroy themselves
hferreiro pushed a commit to brave/muon that referenced this pull request Jun 29, 2017
Additional updates (per electron/electron#8702)

Fixes brave/browser-laptop#5470

- Default `async` to true for popup menus
- fix lint errors
- menus do not destroy themselves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Menu.popup blocks the run/render loop

4 participants