From 136120b8310c8cb0fc1f202f5172740619a78095 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B3bert=20Kiss?= Date: Mon, 9 Apr 2018 21:09:09 +0200 Subject: [PATCH] feat: not allow run multiple Agent (#603) --- packages/uhk-agent/src/electron-main.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/uhk-agent/src/electron-main.ts b/packages/uhk-agent/src/electron-main.ts index 5b425823..a628f526 100644 --- a/packages/uhk-agent/src/electron-main.ts +++ b/packages/uhk-agent/src/electron-main.ts @@ -60,7 +60,25 @@ if (console.debug) { }; } +const isSecondInstance = app.makeSingleInstance(function (commandLine, workingDirectory) { + // Someone tried to run a second instance, we should focus our window. + if (win) { + if (win.isMinimized()) { + win.restore(); + } + win.focus(); + } +}); + +if (isSecondInstance) { + app.quit(); +} + function createWindow() { + if (isSecondInstance) { + return; + } + logger.info('[Electron Main] Create new window.'); let packagesDir; if (isDev) {