From 3c0f20f364a41e651fce168224fb77820fa6d7be Mon Sep 17 00:00:00 2001 From: jhdcruz Date: Thu, 5 Sep 2019 22:15:41 +0800 Subject: [PATCH] Single Instance fix #3241 Fixes single instance depreciation --- lib/main-app.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/main-app.js b/lib/main-app.js index 6151c1f0..9a2c4e59 100644 --- a/lib/main-app.js +++ b/lib/main-app.js @@ -5,24 +5,23 @@ const ipc = electron.ipcMain const GhReleases = require('electron-gh-releases') const { isPackaged } = app // electron.crashReporter.start() +const singleInstance = app.requestSingleInstanceLock() var ipcServer = null var mainWindow = null -var shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) { - if (mainWindow) { - if (process.platform === 'win32') { - mainWindow.minimize() - mainWindow.restore() - } - mainWindow.focus() - } - return true -}) - -if (shouldQuit) { +// Single Instance Lock +if (!singleInstance) { app.quit() +} else { + app.on('second-instance', () => { + // Someone tried to run a second instance, it should focus the existing instance. + if (mainWindow) { + if (!mainWindow.isVisible()) mainWindow.show() + mainWindow.focus() + } + }) } var isUpdateReady = false