From 1c76b5886f7983bc406d67c5f728436b79815b8d Mon Sep 17 00:00:00 2001 From: yzrsng <43310551+yzrsng@users.noreply.github.com> Date: Mon, 26 Aug 2019 12:58:04 +0900 Subject: [PATCH] Enforce single instance for linux and windows --- app/main.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/main.js b/app/main.js index 4ee004bf..4b7404ac 100644 --- a/app/main.js +++ b/app/main.js @@ -18,6 +18,23 @@ const app = electron.app; const BrowserWindow = electron.BrowserWindow; // メインウィンドウはGCされないようにグローバル宣言 let mainWindow; + +// アプリが多重起動しないようにする +const gotTheLock = app.requestSingleInstanceLock() + +if (!gotTheLock) { + app.quit() +} else { + app.on('second-instance', () => { + // 多重起動を試みた場合、既に存在するウィンドウにフォーカスを移す + // Someone tried to run a second instance, we should focus our window. + if (mainWindow) { + if (mainWindow.isMinimized()) mainWindow.restore() + mainWindow.focus() + } + }) +} + if (process.argv.indexOf("--dev") === -1) { var packaged = true; } else {