electron限制只能打开一个应用窗口,在有窗口的情况下唤起窗口。
const { app, BrowserWindow } = require('electron')
let mainWindow
let windowConfig = { // 窗口配置程序运行窗口的大小
width: 1280,
height: 800
}
function createWindow () {
mainWindow = new BrowserWindow(windowConfig)
mainWindow.show()
mainWindow.loadFile('www/index.html')
mainWindow.webContents.openDevTools({mode: 'detach'})
}
const gotTheLock = app.requestSingleInstanceLock()
if (!gotTheLock) {
app.quit()
} else {
app.on('second-instance', (event) => {
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore()
mainWindow.focus()
}
})
app.on('ready', () => {
createWindow()
const { Menu } = require('electron')
Menu.setApplicationMenu(null) // 隐藏菜单栏
})
}