diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 769b30e7..5ebc8c6a 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -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;