diff options
| author | Pliable Pixels <pliablepixels@gmail.com> | 2018-12-30 18:24:01 -0500 |
|---|---|---|
| committer | Pliable Pixels <pliablepixels@gmail.com> | 2018-12-30 18:24:01 -0500 |
| commit | 81b6111e441f9e8d7ba5bfa32ba43be8699e2e19 (patch) | |
| tree | e3975ce2676d2252e7a3037a3c582fd9b9c99b8e /electron_js | |
| parent | c07d973c02d9fba7f7ee744a96f4a684426243b0 (diff) | |
single instance changes for v4 of electron
Diffstat (limited to 'electron_js')
| -rw-r--r-- | electron_js/main.js | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/electron_js/main.js b/electron_js/main.js index 1236ae11..95e1521b 100644 --- a/electron_js/main.js +++ b/electron_js/main.js @@ -29,19 +29,21 @@ if (argv.path) { let win; app.commandLine.appendSwitch ('ignore-certificate-errors', 'true'); -const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { - // Someone tried to run a second instance, we should focus our window. - if (win) { - if (win.isMinimized()) win.restore(); - win.focus(); - } -}); - -if (shouldQuit) { - app.quit(); - return; +const gotTheLock = app.requestSingleInstanceLock() + +if (!gotTheLock) { + app.quit() +} else { + app.on('second-instance', (event, commandLine, workingDirectory) => { + // Someone tried to run a second instance, we should focus our window. + if (myWindow) { + if (myWindow.isMinimized()) myWindow.restore() + myWindow.focus() + } + }) } + function newWindow() { createAlternateWindow(); } |
