options all the things
This commit is contained in:
parent
56f06187d5
commit
fb7fb4972d
2 changed files with 22 additions and 36 deletions
|
@ -43,50 +43,32 @@ Menu.prototype._init = function () {
|
|||
}
|
||||
}
|
||||
|
||||
Menu.prototype.popup = function (window, options, callback) {
|
||||
let x, y, pos
|
||||
let [win, opts, cb] = [window, options, callback]
|
||||
|
||||
if (!opts && !callback) {
|
||||
// win.popup({opts})
|
||||
if (typeof window !== 'function') {
|
||||
opts = window
|
||||
// win.popup(callback)
|
||||
} else {
|
||||
callback = window
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof opts === 'object') {
|
||||
[x, y, pos] = [opts.x, opts.y, opts.newPosition]
|
||||
}
|
||||
|
||||
// win.popup(win, callback)
|
||||
if (typeof opts === 'function') cb = opts
|
||||
Menu.prototype.popup = function (options) {
|
||||
let {window, x, y, positionItem, callback} = options
|
||||
|
||||
// no callback passed
|
||||
if (!cb || typeof cb !== 'function') cb = () => {}
|
||||
if (!callback || typeof callback !== 'function') callback = () => {}
|
||||
|
||||
// set defaults
|
||||
if (typeof x !== 'number') x = -1
|
||||
if (typeof y !== 'number') y = -1
|
||||
if (typeof pos !== 'number') pos = -1
|
||||
if (!win || (win && win.constructor !== BrowserWindow)) {
|
||||
win = BrowserWindow.getFocusedWindow()
|
||||
if (typeof positionItem !== 'number') positionItem = -1
|
||||
if (!window || (window && window.constructor !== BrowserWindow)) {
|
||||
window = BrowserWindow.getFocusedWindow()
|
||||
|
||||
// No window focused?
|
||||
if (!win) {
|
||||
if (!window) {
|
||||
const wins = BrowserWindow.getAllWindows()
|
||||
if (wins && wins.length > 0) {
|
||||
win = wins[0]
|
||||
window = wins[0]
|
||||
} else {
|
||||
throw new Error(`Cannot open Menu without a BrowserWindow present`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.popupAt(win, x, y, pos, cb)
|
||||
return { browserWindow: win, x, y, position: pos }
|
||||
this.popupAt(window, x, y, positionItem, callback)
|
||||
return { browserWindow: window, x, y, position: positionItem }
|
||||
}
|
||||
|
||||
Menu.prototype.closePopup = function (window) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue