feat: app.on('activate') handle

This commit is contained in:
草鞋没号 2021-12-30 10:04:57 +08:00
parent 3e6596b51c
commit f00c53c0e9
1 changed files with 11 additions and 3 deletions

View File

@ -13,7 +13,7 @@ if (!app.requestSingleInstanceLock()) {
let win: BrowserWindow | null = null
async function mainWin() {
async function createWindow() {
win = new BrowserWindow({
title: 'Main window',
webPreferences: {
@ -28,7 +28,6 @@ async function mainWin() {
const url = `http://${pkg.env.HOST || '127.0.0.1'}:${pkg.env.PORT}`
win.loadURL(url)
win.maximize()
win.webContents.openDevTools()
}
@ -38,7 +37,7 @@ async function mainWin() {
})
}
app.whenReady().then(mainWin)
app.whenReady().then(createWindow)
app.on('window-all-closed', () => {
win = null
@ -54,3 +53,12 @@ app.on('second-instance', () => {
win.focus()
}
})
app.on('activate', () => {
const allWindows = BrowserWindow.getAllWindows()
if (allWindows.length) {
allWindows[0].focus()
} else {
createWindow()
}
})