mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
add max queue length for notifications (#46)
This commit is contained in:
@@ -383,9 +383,10 @@ electron.ipcMain.on(apiProxyCmds.addEvent, function(event, args) {
|
||||
/* eslint-enable no-console */
|
||||
|
||||
let obj = liveObjs[args.objId];
|
||||
let callbackFunc = function() {
|
||||
let callbackFunc = function(result) {
|
||||
event.sender.send(apiProxyCmds.eventCallback, {
|
||||
callbackId: args.callbackId
|
||||
callbackId: args.callbackId,
|
||||
result: result
|
||||
});
|
||||
}
|
||||
obj._callbacks[args.callbackId] = callbackFunc;
|
||||
|
@@ -16,6 +16,10 @@ const app = electron.app;
|
||||
const BrowserWindow = electron.BrowserWindow;
|
||||
const ipc = electron.ipcMain;
|
||||
|
||||
// maximum number of notifications that can be queued, after limit is
|
||||
// reached then error func callback will be invoked.
|
||||
const MAX_QUEUE_SIZE = 30;
|
||||
|
||||
let AnimationQueue = require('./AnimationQueue.js');
|
||||
|
||||
// Array of windows with currently showing notifications
|
||||
@@ -225,12 +229,26 @@ function setupConfig() {
|
||||
|
||||
|
||||
function notify(notification) {
|
||||
if (notificationQueue.length >= MAX_QUEUE_SIZE) {
|
||||
var id = latestID;
|
||||
incrementId();
|
||||
if (typeof notification.onErrorFunc === 'function') {
|
||||
setTimeout(function() {
|
||||
notification.onErrorFunc({
|
||||
id: id,
|
||||
error: 'max notification queue size reached: ' + MAX_QUEUE_SIZE
|
||||
});
|
||||
}, 0);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
// Is it an object and only one argument?
|
||||
if (arguments.length === 1 && typeof notification === 'object') {
|
||||
let notf = Object.assign({}, notification);
|
||||
// Use object instead of supplied parameters
|
||||
notf.id = latestID
|
||||
latestID++
|
||||
notf.id = latestID;
|
||||
incrementId();
|
||||
animationQueue.push({
|
||||
func: showNotification,
|
||||
args: [ notf ]
|
||||
@@ -241,6 +259,10 @@ function notify(notification) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function incrementId() {
|
||||
latestID++;
|
||||
}
|
||||
|
||||
function showNotification(notificationObj) {
|
||||
return new Promise(function(resolve) {
|
||||
// Can we show it?
|
||||
|
@@ -19,7 +19,8 @@ class Notify {
|
||||
color: options.color,
|
||||
onShowFunc: onShow.bind(this),
|
||||
onClickFunc: onClick.bind(this),
|
||||
onCloseFunc: onClose.bind(this)
|
||||
onCloseFunc: onClose.bind(this),
|
||||
onErrorFunc: onError.bind(this)
|
||||
});
|
||||
|
||||
this._data = options.data || null;
|
||||
@@ -43,6 +44,17 @@ class Notify {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
function onError(arg) {
|
||||
if (arg.id === this._id) {
|
||||
// don't raise error event if handler doesn't exist, node
|
||||
// will throw an exception
|
||||
if (this.emitter.eventNames().includes('error')) {
|
||||
this.emitter.emit('error', arg.error || 'notification error');
|
||||
}
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
close() {
|
||||
|
@@ -46,7 +46,7 @@ class Notify {
|
||||
get data() {}
|
||||
|
||||
/**
|
||||
* add event listeners for 'click' and 'close' events
|
||||
* add event listeners for 'click', 'close', 'show', 'error' events
|
||||
*
|
||||
* @param {String} event event to listen for
|
||||
* @param {func} cb callback invoked when event occurs
|
||||
@@ -54,7 +54,7 @@ class Notify {
|
||||
addEventListener(event, cb) {}
|
||||
|
||||
/**
|
||||
* remove event listeners for 'click' and 'close' events
|
||||
* remove event listeners for 'click', 'close', 'show', 'error' events
|
||||
*
|
||||
* @param {String} event event to stop listening for.
|
||||
* @param {func} cb callback associated with original addEventListener
|
||||
|
@@ -112,7 +112,8 @@ function addEventHandler(target) {
|
||||
if (arg.callbackId === callbackId) {
|
||||
callback({
|
||||
target: this,
|
||||
type: eventName
|
||||
type: eventName,
|
||||
result: arg.result
|
||||
});
|
||||
}
|
||||
}.bind(this);
|
||||
|
Reference in New Issue
Block a user