Electron-249 - Updated API work flow

This commit is contained in:
Kiran Niranjan 2018-01-08 16:43:10 +05:30 committed by kiranniranjan
parent 92076ce9c7
commit ab6a4fdc6a
6 changed files with 41 additions and 45 deletions

30
js/bringToFront.js Normal file
View File

@ -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
};

View File

@ -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;
}

View File

@ -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
};

View File

@ -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;

View File

@ -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();
}
}
}
/**

View File

@ -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
});
},