From 73d78d345a02bffaaa88801d225e4cb5d50e18e1 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 1 Jan 2018 17:17:01 +0900 Subject: [PATCH] Make callback work for old-style Menu.popup call While the old-style Menu.popup has been deprecated, it is still being used widely in apps and even in Electron itself. --- lib/browser/api/menu.js | 5 +++++ spec/api-menu-spec.js | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/browser/api/menu.js b/lib/browser/api/menu.js index 6fb5489f42bd..c0e9c202ef54 100644 --- a/lib/browser/api/menu.js +++ b/lib/browser/api/menu.js @@ -56,6 +56,11 @@ Menu.prototype.popup = function (window, x, y, positioningItem) { [newPosition, newY, newX, newWindow] = [y, x, window, null] } + // menu.popup([w], x, y, callback) + if (typeof newPosition === 'function') { + callback = newPosition + } + // menu.popup({}) if (window != null && window.constructor === Object) { opts = window diff --git a/spec/api-menu-spec.js b/spec/api-menu-spec.js index 32ee985de322..a15fd5f83cda 100644 --- a/spec/api-menu-spec.js +++ b/spec/api-menu-spec.js @@ -328,6 +328,11 @@ describe('Menu module', () => { menu.popup({}, () => done()) menu.closePopup() }) + + it('works with old style', (done) => { + menu.popup(w, 100, 101, () => done()) + menu.closePopup() + }) }) describe('Menu.closePopup()', () => {