多个显示器【外接的例如有些商店业务员一个有一个对客户的收银的那种机器】的功能用的比较少,再一次亲身经历说下,远离百度
有问题多看文档。找找中文的,再找找英文的;
electron多显示器文档:https://www.electronjs.org/docs/api/screen
代码:
const { app, BrowserWindow, screen } = require('electron')
let win
app.whenReady().then(() => {
const { width, height } = screen.getPrimaryDisplay().workAreaSize
win = new BrowserWindow({ width, height })
win.loadURL('https://github.com')
})
另外一个例子:
let win
app.whenReady().then(() => {
const displays = screen.getAllDisplays()
const 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')
}
})