From 537194608e34676450fa916a98d8a099a89af161 Mon Sep 17 00:00:00 2001 From: David Baker Date: Thu, 19 Jan 2017 16:01:37 +0000 Subject: [PATCH] Make riot desktop single instance So launching a new instance will focus the old one, meaning that if you have Riot minimised to the tray and launch it via the desktop shortcut / start menu, you don't end up with more & more copies of the app. This doesn't really prevent you from running multiple copies of the app to fake multi account support since they share a data directory anyway. --- electron/src/electron-main.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/electron/src/electron-main.js b/electron/src/electron-main.js index 929b78923f..1a6ea692d0 100644 --- a/electron/src/electron-main.js +++ b/electron/src/electron-main.js @@ -159,6 +159,19 @@ electron.ipcMain.on('install_update', installUpdate); electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); +const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => { + // 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) { + electron.app.quit() +} + electron.app.on('ready', () => { if (vectorConfig.update_base_url) { console.log("Starting auto update with base URL: " + vectorConfig.update_base_url);