From f00c53c0e92388d5098126aad9c612ca35222a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8D=89=E9=9E=8B=E6=B2=A1=E5=8F=B7?= <308487730@qq.com> Date: Thu, 30 Dec 2021 10:04:57 +0800 Subject: [PATCH] feat: app.on('activate') handle --- src/main/index.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/index.ts b/src/main/index.ts index d3eccdb..798554e 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -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() + } +})