Show window if hidden when second instance attempts to start (#1897)

This commit is contained in:
Scott Nonnenberg 2017-12-14 12:27:52 -08:00 committed by GitHub
parent 8a919efbe9
commit 5cf320e429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 16 deletions

39
main.js
View File

@ -40,13 +40,33 @@ const config = require("./app/config");
// userData directory.
const userConfig = require('./app/user_config');
function showWindow() {
// Using focus() instead of show() seems to be important on Windows when our window
// has been docked using Aero Snap/Snap Assist. A full .show() call here will cause
// the window to reposition:
// https://github.com/WhisperSystems/Signal-Desktop/issues/1429
if (mainWindow.isVisible()) {
mainWindow.focus();
} else {
mainWindow.show();
}
// toggle the visibility of the show/hide tray icon menu entries
if (tray) {
tray.updateContextMenu();
}
}
if (!process.mas) {
console.log('making app single instance');
var shouldQuit = app.makeSingleInstance(function(commandLine, workingDirectory) {
// Someone tried to run a second instance, we should focus our window
if (mainWindow) {
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.focus();
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
showWindow();
}
return true;
});
@ -280,20 +300,7 @@ function createWindow () {
});
ipc.on('show-window', function() {
// Using focus() instead of show() seems to be important on Windows when our window
// has been docked using Aero Snap/Snap Assist. A full .show() call here will cause
// the window to reposition:
// https://github.com/WhisperSystems/Signal-Desktop/issues/1429
if (mainWindow.isVisible()) {
mainWindow.focus();
} else {
mainWindow.show();
}
// toggle the visibility of the show/hide tray icon menu entries
if (tray) {
tray.updateContextMenu();
}
showWindow();
});
}