Skip to content

Commit 8a4a6b2

Browse files
committed
refactor hidden logic to be more resilient against electron weirdness
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
1 parent ca2533c commit 8a4a6b2

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎electron_app/src/electron-main.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ electron.ipcMain.on('app_onAction', function(ev, payload) {
101101
electron.app.commandLine.appendSwitch('--enable-usermedia-screen-capturing');
102102

103103
const shouldQuit = electron.app.makeSingleInstance((commandLine, workingDirectory) => {
104+
// If other instance launched with --hidden then skip showing window
105+
if (commandLine.includes('--hidden')) return;
106+
104107
// Someone tried to run a second instance, we should focus our window.
105108
if (mainWindow) {
106109
if (!mainWindow.isVisible()) mainWindow.show();
@@ -211,11 +214,17 @@ electron.app.on('ready', () => {
211214
brand: vectorConfig.brand || 'Riot',
212215
});
213216

214-
if (!argv.hidden) {
215-
mainWindow.once('ready-to-show', () => {
217+
mainWindow.once('ready-to-show', () => {
218+
mainWindowState.manage(mainWindow);
219+
220+
if (!argv.hidden) {
221+
console.log("Showing window");
216222
mainWindow.show();
217-
});
218-
}
223+
} else {
224+
// hide here explicitly because window manage above sometimes shows it
225+
mainWindow.hide();
226+
}
227+
});
219228

220229
mainWindow.on('closed', () => {
221230
mainWindow = global.mainWindow = null;
@@ -243,7 +252,6 @@ electron.app.on('ready', () => {
243252
}
244253

245254
webContentsHandler(mainWindow.webContents);
246-
mainWindowState.manage(mainWindow);
247255
});
248256

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

0 commit comments

Comments
 (0)