Electron-222

Added a safety check to prevent from using an already destroyed notification window
Added method to close all notification when notification config is changed
This commit is contained in:
Kiran Niranjan 2017-12-29 15:59:19 +05:30 committed by Kiran Niranjan
parent 5ed8e8f026
commit c8101a9b1e

View File

@ -165,6 +165,7 @@ function updateConfig(customConfig) {
if (customConfig.display) {
displayId = customConfig.display;
}
closeAll();
}
/**
@ -477,6 +478,13 @@ function setNotificationContents(notfWindow, notfObj) {
*/
function buildCloseNotification(notificationWindow, notificationObj, getTimeoutId) {
return function(event) {
// safety check to prevent from using an
// already destroyed notification window
if (notificationWindow.isDestroyed()) {
return new Promise(function(exitEarly) { exitEarly() })
}
if (closedNotifications[notificationObj.id]) {
delete closedNotifications[notificationObj.id];
return new Promise(function(exitEarly) { exitEarly() });
@ -711,6 +719,34 @@ function cleanUpInactiveWindow() {
inactiveWindows = [];
}
/**
* Closes all the notifications and windows
*/
function closeAll() {
// Clear out animation Queue and close windows
animationQueue.clear();
activeNotifications.forEach(function(window) {
if (window.displayTimer) {
clearTimeout(window.displayTimer);
}
if (window.electronNotifyOnCloseFunc) {
// ToDo: fix this: shouldn't delete method on arg
/* eslint-disable */
delete window.electronNotifyOnCloseFunc;
/* eslint-enable */
}
window.close();
});
cleanUpInactiveWindow();
// Reset certain vars
nextInsertPos = {};
activeNotifications = [];
}
module.exports.notify = notify;
module.exports.updateConfig = updateConfig;
module.exports.reset = setupConfig;