Skip to content

Commit

Permalink
refactor hidden logic to be more resilient against electron weirdness
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy committed May 26, 2018
1 parent ca2533c commit 8a4a6b2
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions electron_app/src/electron-main.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -243,7 +252,6 @@ electron.app.on('ready', () => {
}

webContentsHandler(mainWindow.webContents);
mainWindowState.manage(mainWindow);
});

electron.app.on('window-all-closed', () => {
Expand Down

0 comments on commit 8a4a6b2

Please sign in to comment.