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