From bd85987e721e45487b8a74355db26b2fda6125fb Mon Sep 17 00:00:00 2001 From: hunlongyu Date: Thu, 7 May 2020 23:17:37 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=B4=20=E5=8F=AA=E8=83=BD=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E4=B8=80=E4=B8=AA=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/background.js | 26 ++++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 868430e..aa21917 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zy", - "version": "0.9.27", + "version": "0.9.28", "private": true, "author": { "name": "Hunlongyu", diff --git a/src/background.js b/src/background.js index 84e4071..a07b24f 100644 --- a/src/background.js +++ b/src/background.js @@ -114,12 +114,26 @@ ipcMain.on('miniOpacity', (e, arg) => { mini.setOpacity(arg) }) -app.on('ready', async () => { - if (!process.env.WEBPACK_DEV_SERVER_URL) { - createProtocol('app') - } - createWindow() -}) +const gotTheLock = app.requestSingleInstanceLock() +if (!gotTheLock) { + app.quit() +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // 当运行第二个实例时,将会聚焦到win这个窗口 + if (win) { + if (win.isMinimized()) win.restore() + win.focus() + } + }) + + // 创建 win, 加载应用的其余部分, etc... + app.on('ready', () => { + if (!process.env.WEBPACK_DEV_SERVER_URL) { + createProtocol('app') + } + createWindow() + }) +} // Exit cleanly on request from parent process in development mode. if (isDevelopment) {