feat: app.on('activate') handle
This commit is contained in:
1 parent
3e6596b51c
commit
f00c53c0e9
1 file changed
+11
-3
+11
-3
@@ -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()
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user