Update to new electron single instance API

This commit is contained in:
David Baker 2018-12-18 18:10:09 +00:00
parent 17983c47d8
commit 60d3076038
1 changed files with 14 additions and 14 deletions

View File

@ -100,24 +100,12 @@ ipcMain.on('app_onAction', function(ev, payload) {
app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
const shouldQuit = app.makeSingleInstance((commandLine, workingDirectory) => { const gotLock = app.requestSingleInstanceLock();
// If other instance launched with --hidden then skip showing window if (!gotLock) {
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) {
console.log('Other instance detected: exiting'); console.log('Other instance detected: exiting');
app.exit(); app.exit();
} }
const launcher = new AutoLaunch({ const launcher = new AutoLaunch({
name: vectorConfig.brand || 'Riot', name: vectorConfig.brand || 'Riot',
isHidden: true, 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 // Set the App User Model ID to match what the squirrel
// installer uses for the shortcut icon. // installer uses for the shortcut icon.
// This makes notifications work on windows 8.1 (and is // This makes notifications work on windows 8.1 (and is