From b62d5fae8768ff7dca1cf81506a1a5b4883b6397 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:30:50 +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 656b7c0..beb45e5 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 bootstrap() { +async function createWindow() { win = new BrowserWindow({ webPreferences: { preload: path.join(__dirname, '../preload/index.cjs'), @@ -27,12 +27,11 @@ async function bootstrap() { const url = `http://${pkg.env.HOST || '127.0.0.1'}:${pkg.env.PORT}` win.loadURL(url) - win.maximize() win.webContents.openDevTools() } } -app.whenReady().then(bootstrap) +app.whenReady().then(createWindow) app.on('window-all-closed', () => { win = null @@ -49,6 +48,15 @@ app.on('second-instance', () => { } }) +app.on('activate', () => { + const allWindows = BrowserWindow.getAllWindows() + if (allWindows.length) { + allWindows[0].focus() + } else { + createWindow() + } +}) + // @TODO // auto update /* if (app.isPackaged) {