Skip to content

Commit

Permalink
fix: close context menu before popup (#17509)
Browse files Browse the repository at this point in the history
  • Loading branch information
trop[bot] authored and John Kleinschmidt committed Mar 22, 2019
1 parent e280ae1 commit ef38019
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions atom/browser/ui/win/notify_icon.cc
Expand Up @@ -142,6 +142,10 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
if (!SetForegroundWindow(window_))
return;

// Cancel current menu if there is one.
if (menu_runner_ && menu_runner_->IsRunning())
menu_runner_->Cancel();

// Show menu at mouse's position by default.
gfx::Rect rect(pos, gfx::Size());
if (pos.IsOrigin())
Expand Down
17 changes: 17 additions & 0 deletions spec/api-tray-spec.js
Expand Up @@ -23,6 +23,23 @@ describe('tray module', () => {
})
})

describe('tray.popUpContextMenu', () => {
before(function () {
if (process.platform !== 'win32') {
this.skip()
}
})

it('can be called when menu is showing', (done) => {
tray.setContextMenu(Menu.buildFromTemplate([{ label: 'Test' }]))
setTimeout(() => {
tray.popUpContextMenu()
done()
})
tray.popUpContextMenu()
})
})

describe('tray.setImage', () => {
it('accepts empty image', () => {
tray.setImage(nativeImage.createEmpty())
Expand Down

0 comments on commit ef38019

Please sign in to comment.