From 8a4a6b2023d86f86427ee7984d0a51e9302deefb Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 26 May 2018 14:21:38 +0100 Subject: [PATCH] refactor hidden logic to be more resilient against electron weirdness Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- electron_app/src/electron-main.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/electron_app/src/electron-main.js b/electron_app/src/electron-main.js index c84fcb7344..d9473dcf89 100644 --- a/electron_app/src/electron-main.js +++ b/electron_app/src/electron-main.js @@ -101,6 +101,9 @@ electron.ipcMain.on('app_onAction', function(ev, payload) { electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing'); const shouldQuit = electron.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(); @@ -211,11 +214,17 @@ electron.app.on('ready', () => { brand: vectorConfig.brand || 'Riot', }); - if (!argv.hidden) { - mainWindow.once('ready-to-show', () => { + mainWindow.once('ready-to-show', () => { + mainWindowState.manage(mainWindow); + + if (!argv.hidden) { + console.log("Showing window"); mainWindow.show(); - }); - } + } else { + // hide here explicitly because window manage above sometimes shows it + mainWindow.hide(); + } + }); mainWindow.on('closed', () => { mainWindow = global.mainWindow = null; @@ -243,7 +252,6 @@ electron.app.on('ready', () => { } webContentsHandler(mainWindow.webContents); - mainWindowState.manage(mainWindow); }); electron.app.on('window-all-closed', () => {