Fix notf close (#52)

* fix notf close

* send close event for queued items
This commit is contained in:
Lynn 2017-04-04 20:16:14 -07:00 committed by GitHub
parent 662fa1d864
commit 8d94893ea8
2 changed files with 16 additions and 18 deletions

View File

@ -10,20 +10,7 @@ const cmds = keyMirror({
badgeDataUrl: null badgeDataUrl: null
}); });
const proxyCmds = keyMirror({
createObject: null,
addEvent: null,
removeEvent: null,
eventCallback: null,
invokeMethod: null,
invokeResult: null,
get: null,
getResult: null,
set: null
});
module.exports = { module.exports = {
cmds: cmds, cmds: cmds,
proxyCmds: proxyCmds,
apiName: 'symphony-api' apiName: 'symphony-api'
} }

View File

@ -274,18 +274,29 @@ function showNotification(notificationObj) {
// if has same grouping id. // if has same grouping id.
let tag = notificationObj.tag; let tag = notificationObj.tag;
if (tag) { if (tag) {
// first check waiting items // first check queued notifications
for(let i = 0; i < notificationQueue.length; i++) { for(let i = 0; i < notificationQueue.length; i++) {
if (tag === notificationQueue[ i ].tag) { if (tag === notificationQueue[ i ].tag) {
let existingNotfObj = notificationQueue[ i ];
// be sure to call close event for existing, so it gets
// cleaned up.
if (typeof existingNotfObj.onCloseFunc === 'function') {
existingNotfObj.onCloseFunc({
event: 'close',
id: notificationObj.id
});
}
// update with new notf
notificationQueue[ i ] = notificationObj; notificationQueue[ i ] = notificationObj;
resolve(); resolve();
return; return;
} }
} }
// next check items being shown // next check notfs being shown
for(let i = 0; i < activeNotifications.length; i++) { for(let i = 0; i < activeNotifications.length; i++) {
if (tag === activeNotifications[ i ].tag) { let existingNotfyObj = activeNotifications[ i ].notfyObj;
if (existingNotfyObj && tag === existingNotfyObj.tag) {
let notificationWindow = activeNotifications[ i ]; let notificationWindow = activeNotifications[ i ];
// be sure to call close event for existing, so it gets // be sure to call close event for existing, so it gets
@ -293,7 +304,7 @@ function showNotification(notificationObj) {
if (notificationWindow.electronNotifyOnCloseFunc) { if (notificationWindow.electronNotifyOnCloseFunc) {
notificationWindow.electronNotifyOnCloseFunc({ notificationWindow.electronNotifyOnCloseFunc({
event: 'close', event: 'close',
id: notificationObj.id id: existingNotfyObj.id
}); });
delete notificationWindow.electronNotifyOnCloseFunc; delete notificationWindow.electronNotifyOnCloseFunc;
} }
@ -337,7 +348,7 @@ function setNotificationContents(notfWindow, notfObj) {
var updatedNotificationWindow = notfWindow; var updatedNotificationWindow = notfWindow;
updatedNotificationWindow.tag = notfObj.tag; updatedNotificationWindow.notfyObj = notfObj;
let timeoutId; let timeoutId;
let closeFunc = buildCloseNotification(notfWindow, notfObj, function() { let closeFunc = buildCloseNotification(notfWindow, notfObj, function() {