Electron-284 Added an new api for bring to front feature

This commit is contained in:
Kiran Niranjan 2018-01-23 13:47:17 +05:30 committed by kiranniranjan
parent c90fd8d886
commit e25c3c6c01
4 changed files with 25 additions and 11 deletions

View File

@ -8,14 +8,15 @@ const logLevels = require('./enums/logLevels.js');
/**
* Method that checks if user has enabled the bring to front feature
* if so then activates the main window
* @param windowName - Name of the window to activate
* @param {String} windowName - Name of the window to activate
* @param {String} reason - The reason for which the window is to be activated
*/
function bringToFront(windowName) {
function bringToFront(windowName, reason) {
getConfigField('bringToFront')
.then((bringToFrontSetting) => {
if (typeof bringToFrontSetting === 'boolean' && bringToFrontSetting) {
log.send(logLevels.INFO, 'Window has been activated for: bringToFront');
log.send(logLevels.INFO, 'Window has been activated for: ' + reason);
windowMgr.activate(windowName || 'main');
}
})

View File

@ -16,7 +16,8 @@ const cmds = keyMirror({
registerProtocolHandler: null,
registerActivityDetection: null,
showNotificationSettings: null,
sanitize: null
sanitize: null,
bringToFront: null
});
module.exports = {

View File

@ -103,11 +103,6 @@ electron.ipcMain.on(apiName, (event, arg) => {
break;
case apiCmds.activate:
if (typeof arg.windowName === 'string') {
// validates the user bring to front config and activates the wrapper
if (typeof arg.reason === 'string' && arg.reason === 'bringToFront') {
bringToFront(arg.windowName);
break;
}
windowMgr.activate(arg.windowName);
}
break;
@ -134,6 +129,12 @@ electron.ipcMain.on(apiName, (event, arg) => {
sanitize(arg.windowName);
}
break;
case apiCmds.bringToFront:
// validates the user bring to front config and activates the wrapper
if (typeof arg.reason === 'string' && arg.reason === 'notification') {
bringToFront(arg.windowName, arg.reason);
}
break;
default:
}

View File

@ -151,11 +151,22 @@ function createAPI() {
/**
* Brings window forward and gives focus.
* @param {String} windowName Name of window. Note: main window name is 'main'
* @param {String} reason, The reason for which the window is to be activated
*/
activate: function(windowName, reason) {
activate: function(windowName) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.activate,
windowName: windowName
});
},
/**
* Brings window forward and gives focus.
* @param {String} windowName Name of window. Note: main window name is 'main'
* @param {String} reason, The reason for which the window is to be activated
*/
bringToFront: function(windowName, reason) {
local.ipcRenderer.send(apiName, {
cmd: apiCmds.bringToFront,
windowName: windowName,
reason: reason
});