diff --git a/js/bringToFront.js b/js/bringToFront.js new file mode 100644 index 00000000..6d6274c5 --- /dev/null +++ b/js/bringToFront.js @@ -0,0 +1,30 @@ +'use strict'; + +const windowMgr = require('./windowMgr.js'); +const { getConfigField } = require('./config.js'); +const log = require('./log.js'); +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 + */ +function bringToFront(windowName) { + + getConfigField('bringToFront') + .then((bringToFrontSetting) => { + if (typeof bringToFrontSetting === 'boolean' && bringToFrontSetting) { + log.send(logLevels.INFO, 'Window has been activated for: bringToFront'); + windowMgr.activate(windowName || 'main'); + } + }) + .catch((error) => { + log.send(logLevels.ERROR, 'Could not read bringToFront field from config error= ' + error); + }); +} + + +module.exports = { + bringToFront: bringToFront +}; \ No newline at end of file diff --git a/js/mainApiMgr.js b/js/mainApiMgr.js index 92706004..3c8211d9 100644 --- a/js/mainApiMgr.js +++ b/js/mainApiMgr.js @@ -13,6 +13,7 @@ const activityDetection = require('./activityDetection'); const badgeCount = require('./badgeCount.js'); const protocolHandler = require('./protocolHandler'); const configureNotification = require('./notify/settings/configure-notification-position'); +const { bringToFront } = require('./bringToFront.js'); const apiEnums = require('./enums/api.js'); const apiCmds = apiEnums.cmds; @@ -82,6 +83,11 @@ electron.ipcMain.on(apiName, (event, arg) => { } if (arg.cmd === apiCmds.activate && 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); + return; + } windowMgr.activate(arg.windowName); return; } diff --git a/js/notify/bringToFront.js b/js/notify/bringToFront.js deleted file mode 100644 index 984b45b9..00000000 --- a/js/notify/bringToFront.js +++ /dev/null @@ -1,28 +0,0 @@ -'use strict'; - -const windowMgr = require('../windowMgr.js'); -const { getConfigField } = require('../config.js'); -const log = require('../log.js'); -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 - */ -function bringToFront() { - - getConfigField('bringToFront') - .then((bool) => { - if (bool) { - windowMgr.activate('main'); - } - }) - .catch((error) => { - log.send(logLevels.ERROR, 'Could not read bringToFront field from config error= ' + error); - }); -} - - -module.exports = { - bringToFront: bringToFront -}; \ No newline at end of file diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 439ba575..6bfb7cfb 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -294,10 +294,6 @@ function setupConfig() { function notify(notification) { // Is it an object and only one argument? if (arguments.length === 1 && typeof notification === 'object') { - - if (typeof notification.onBringToFrontFunc === 'function') { - notification.onBringToFrontFunc({id: notification.id }); - } let notf = Object.assign({}, notification); // Use object instead of supplied parameters notf.id = latestID; diff --git a/js/notify/notifyImpl.js b/js/notify/notifyImpl.js index 32218df3..363123aa 100644 --- a/js/notify/notifyImpl.js +++ b/js/notify/notifyImpl.js @@ -2,7 +2,6 @@ const EventEmitter = require('events'); const { notify } = require('./electron-notify.js'); -const { bringToFront } = require('./bringToFront.js'); const log = require('../log.js'); const logLevels = require('../enums/logLevels.js'); /** @@ -46,8 +45,7 @@ class Notify { onShowFunc: onShow.bind(this), onClickFunc: onClick.bind(this), onCloseFunc: onClose.bind(this), - onErrorFunc: onError.bind(this), - onBringToFrontFunc: onBringToFront.bind(this) + onErrorFunc: onError.bind(this) }); log.send(logLevels.INFO, 'created notification, id=' + this._id + ', text=' + options.body); @@ -112,14 +110,6 @@ class Notify { } } - /** - * activates/focuses the main window - */ - function onBringToFront(arg) { - if (arg.id === this._id) { - bringToFront(); - } - } } /** diff --git a/js/preload/preloadMain.js b/js/preload/preloadMain.js index 165dd10b..1c7f5b0d 100644 --- a/js/preload/preloadMain.js +++ b/js/preload/preloadMain.js @@ -151,11 +151,13 @@ 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) { + activate: function(windowName, reason) { local.ipcRenderer.send(apiName, { cmd: apiCmds.activate, - windowName: windowName + windowName: windowName, + reason: reason }); },