From da764721d90ca3b057217b70213a0f02f39235f5 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Wed, 4 Sep 2019 13:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8D=95=E4=BE=8B=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++++ src/main/index.js | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/publish/changeLog.md b/publish/changeLog.md index 9c067645..9343f067 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,7 @@ +### 新增 + +- 新增单例应用功能 + ### 优化 - 优化歌单列表动画 diff --git a/src/main/index.js b/src/main/index.js index f223b5bb..eb6ead83 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -1,6 +1,20 @@ const { app, BrowserWindow, Menu } = require('electron') const path = require('path') +// 单例应用程序 +if (!app.requestSingleInstanceLock()) { + app.quit() + return +} +app.on('second-instance', (event, argv, cwd) => { + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + } else { + app.quit() + } +}) + require('./events') const progressBar = require('./events/progressBar') const trafficLight = require('./events/trafficLight') @@ -90,4 +104,3 @@ app.on('activate', () => { createWindow() } }) -