in the electron Doc (https://electronjs.org/docs/api/screen(
他们为什么要添加
x: externalDisplay.bounds.x + 50,
y: externalDisplay.bounds.y + 50
窗口x
和y
的+50 ?
app.on('ready', () => {
let displays = electron.screen.getAllDisplays()
let externalDisplay = displays.find((display) => {
return display.bounds.x !== 0 || display.bounds.y !== 0
})
if (externalDisplay) {
win = new BrowserWindow({
x: externalDisplay.bounds.x + 50,
y: externalDisplay.bounds.y + 50
})
win.loadURL('https://github.com')
}
})
也许你可以测试这段代码来找到这个要求的解决方案:
var scr = screen.getDisplayMatching(trayBounds)
console.warn("getDisplayMatching-x-y",scr.bounds);