From 60d307603873b4a6e9630fafea986e3d1589d5f8 Mon Sep 17 00:00:00 2001 From: David Baker Date: Tue, 18 Dec 2018 18:10:09 +0000 Subject: [PATCH] Update to new electron single instance API --- electron_app/src/electron-main.js | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index 85955392a..986cc7070 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -100,24 +100,12 @@ ipcMain.on('app_onAction', function(ev, payload) { app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); -const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { - // If other instance launched with --hidden then skip showing window - if (commandLine.includes('--hidden')) return; - - // Someone tried to run a second instance, we should focus our window. - if (mainWindow) { - if (!mainWindow.isVisible()) mainWindow.show(); - if (mainWindow.isMinimized()) mainWindow.restore(); - mainWindow.focus(); - } -}); - -if (shouldQuit) { +const gotLock = app.requestSingleInstanceLock(); +if (!gotLock) { console.log('Other instance detected: exiting'); app.exit(); } - const launcher = new AutoLaunch({ name: vectorConfig.brand || 'Riot', isHidden: true, @@ -268,6 +256,18 @@ app.on('before-quit', () => { } }); +app.on('second-instance', (ev, commandLine, workingDirectory) => { + // If other instance launched with --hidden then skip showing window + if (commandLine.includes('--hidden')) return; + + // Someone tried to run a second instance, we should focus our window. + if (mainWindow) { + if (!mainWindow.isVisible()) mainWindow.show(); + if (mainWindow.isMinimized()) mainWindow.restore(); + mainWindow.focus(); + } +}); + // Set the App User Model ID to match what the squirrel // installer uses for the shortcut icon. // This makes notifications work on windows 8.1 (and is