From e25c3c6c012f8f6717a411473c728a0a51a19b18 Mon Sep 17 00:00:00 2001 From: Kiran Niranjan Date: Tue, 23 Jan 2018 13:47:17 +0530 Subject: [PATCH] Electron-284 Added an new api for bring to front feature --- js/bringToFront.js | 7 ++++--- js/enums/api.js | 3 ++- js/mainApiMgr.js | 11 ++++++----- js/preload/preloadMain.js | 15 +++++++++++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/js/bringToFront.js b/js/bringToFront.js index 6d6274c5..74abcbc4 100644 --- a/js/bringToFront.js +++ b/js/bringToFront.js @@ -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'); } }) diff --git a/js/enums/api.js b/js/enums/api.js index 7d139129..c6941e43 100644 --- a/js/enums/api.js +++ b/js/enums/api.js @@ -16,7 +16,8 @@ const cmds = keyMirror({ registerProtocolHandler: null, registerActivityDetection: null, showNotificationSettings: null, - sanitize: null + sanitize: null, + bringToFront: null }); module.exports = { diff --git a/js/mainApiMgr.js b/js/mainApiMgr.js index bd7c85d1..98bfbf32 100644 --- a/js/mainApiMgr.js +++ b/js/mainApiMgr.js @@ -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: } diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index 846133d8..84700a9d 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -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 });