Electron-470 (Add a new boolean check whether to activate main window) (#361)

- Add a new boolean check whether to activate main window
- update params to object
This commit is contained in:
Kiran Niranjan 2018-05-09 14:49:18 +05:30 committed by Vishwas Shashidhar
parent 6a782efa25
commit 0a66fc90f2
3 changed files with 23 additions and 10 deletions

View File

@ -287,7 +287,10 @@ function getTemplate(app) {
checked: isAlwaysOnTop,
click: (item) => {
isAlwaysOnTop = item.checked;
eventEmitter.emit('isAlwaysOnTop', isAlwaysOnTop);
eventEmitter.emit('isAlwaysOnTop', {
isAlwaysOnTop,
shouldActivateMainWindow: true
});
updateConfigField('alwaysOnTop', isAlwaysOnTop);
}
});
@ -374,7 +377,10 @@ function setCheckboxValues() {
break;
case 'alwaysOnTop':
isAlwaysOnTop = configData[key];
eventEmitter.emit('isAlwaysOnTop', configData[key]);
eventEmitter.emit('isAlwaysOnTop', {
isAlwaysOnTop: configData[key],
shouldActivateMainWindow: true
});
break;
case 'notificationSettings':
eventEmitter.emit('notificationSettings', configData[key]);

View File

@ -70,7 +70,10 @@ class ScreenSnippet {
if (windows && windows.length > 0) {
isAlwaysOnTop = windows[ 0 ].isAlwaysOnTop();
if (isAlwaysOnTop) {
eventEmitter.emit('isAlwaysOnTop', false);
eventEmitter.emit('isAlwaysOnTop', {
isAlwaysOnTop: false,
shouldActivateMainWindow: false
});
}
}
@ -87,7 +90,10 @@ class ScreenSnippet {
child = childProcess.execFile(captureUtil, captureUtilArgs, (error) => {
// Method to reset always on top feature
if (isAlwaysOnTop) {
eventEmitter.emit('isAlwaysOnTop', true);
eventEmitter.emit('isAlwaysOnTop', {
isAlwaysOnTop: true,
shouldActivateMainWindow: false
});
}
// will be called when child process exits.
if (error && error.killed) {

View File

@ -747,9 +747,10 @@ function openUrlInDefaultBrowser(urlToOpen) {
/**
* Called when an event is received from menu
* @param boolean weather to enable or disable alwaysOnTop.
* @param {boolean} boolean whether to enable or disable alwaysOnTop.
* @param {boolean} shouldActivateMainWindow whether to activate main window
*/
function isAlwaysOnTop(boolean) {
function isAlwaysOnTop(boolean, shouldActivateMainWindow = true) {
alwaysOnTop = boolean;
let browserWins = BrowserWindow.getAllWindows();
if (browserWins.length > 0) {
@ -761,16 +762,16 @@ function isAlwaysOnTop(boolean) {
// An issue where changing the alwaysOnTop property
// focus the pop-out window
// Issue - Electron-209
if (mainWindow && mainWindow.winName) {
// Issue - Electron-209/470
if (mainWindow && mainWindow.winName && shouldActivateMainWindow) {
activate(mainWindow.winName);
}
}
}
// node event emitter to update always on top
eventEmitter.on('isAlwaysOnTop', (boolean) => {
isAlwaysOnTop(boolean);
eventEmitter.on('isAlwaysOnTop', (params) => {
isAlwaysOnTop(params.isAlwaysOnTop, params.shouldActivateMainWindow);
});
// node event emitter for notification settings