From 4bab1bde1c3ebe8fb8825b0fe72119754c6447b5 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 20 Mar 2019 18:56:13 +0900 Subject: [PATCH] fix: close context menu before popup --- atom/browser/ui/win/notify_icon.cc | 4 ++++ spec/api-tray-spec.js | 17 +++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/atom/browser/ui/win/notify_icon.cc b/atom/browser/ui/win/notify_icon.cc index 52081edd8a0ab..66d82dad78bda 100644 --- a/atom/browser/ui/win/notify_icon.cc +++ b/atom/browser/ui/win/notify_icon.cc @@ -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()) diff --git a/spec/api-tray-spec.js b/spec/api-tray-spec.js index 7c42fb563ef7d..c44bb516994a3 100644 --- a/spec/api-tray-spec.js +++ b/spec/api-tray-spec.js @@ -24,6 +24,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())