diff --git a/js/notify/electron-notify-preload.js b/js/notify/electron-notify-preload.js index 4bf76af3..1c7497e9 100644 --- a/js/notify/electron-notify-preload.js +++ b/js/notify/electron-notify-preload.js @@ -164,6 +164,18 @@ function setStyleOnDomElement(styleObj, domElement) { } } +window.addEventListener('keydown', handleKeyPress, true); +window.addEventListener('keyup', handleKeyPress, true); + +/** + * Method the prevent key stroke on notification window + * + * @param e keydown event + */ +function handleKeyPress(e) { + e.preventDefault(); +} + /** * Loads the config * @param event diff --git a/js/notify/electron-notify.js b/js/notify/electron-notify.js index 261a6c9f..5f25ea96 100644 --- a/js/notify/electron-notify.js +++ b/js/notify/electron-notify.js @@ -361,22 +361,24 @@ function showNotification(notificationObj) { // next check notfs being shown for(let i = 0; i < activeNotifications.length; i++) { - let existingNotfyObj = activeNotifications[ i ].notfyObj; - if (existingNotfyObj && tag === existingNotfyObj.tag) { - let notificationWindow = activeNotifications[ i ]; + if (activeNotifications[ i ] && !activeNotifications[ i ].isDestroyed()) { + let existingNotfyObj = activeNotifications[ i ].notfyObj; + if (existingNotfyObj && tag === existingNotfyObj.tag) { + let notificationWindow = activeNotifications[ i ]; - // be sure to call close event for existing, so it gets - // cleaned up. - if (notificationWindow.electronNotifyOnCloseFunc) { - notificationWindow.electronNotifyOnCloseFunc({ - event: 'close', - id: existingNotfyObj.id - }); - delete notificationWindow.electronNotifyOnCloseFunc; + // be sure to call close event for existing, so it gets + // cleaned up. + if (notificationWindow.electronNotifyOnCloseFunc) { + notificationWindow.electronNotifyOnCloseFunc({ + event: 'close', + id: existingNotfyObj.id + }); + delete notificationWindow.electronNotifyOnCloseFunc; + } + setNotificationContents(notificationWindow, notificationObj); + resolve(); + return; } - setNotificationContents(notificationWindow, notificationObj); - resolve(); - return; } } } @@ -698,7 +700,9 @@ function getWindow() { // Done notificationWindow.webContents.send('electron-notify-load-config', config); resolve(notificationWindow) - }) + }); + + notificationWindow.once('closed', cleanUpActiveNotification); } }) } @@ -708,12 +712,29 @@ function getWindow() { */ setInterval(cleanUpInactiveWindow, 60000); +function cleanUpActiveNotification(event) { + + if (!event || !event.sender) { + return null; + } + + let pos = activeNotifications.indexOf(event.sender); + if (pos !== -1) { + activeNotifications.splice(pos, 1); + return moveOneDown(pos); + } + + return null; +} + /** * Cleans up inactive windows */ function cleanUpInactiveWindow() { inactiveWindows.forEach(function(window) { - window.close(); + if (!window.isDestroyed()) { + window.close(); + } }); inactiveWindows = []; } @@ -725,11 +746,15 @@ function closeAll() { // Clear out animation Queue and close windows animationQueue.clear(); - activeNotifications.forEach(function(window) { + let notificationWindows = Array.from(activeNotifications); + + notificationWindows.forEach((window) => { if (window.displayTimer) { clearTimeout(window.displayTimer); } - window.close(); + if (!window.isDestroyed()) { + window.close(); + } }); cleanUpInactiveWindow(); diff --git a/js/notify/settings/configure-notification-position.js b/js/notify/settings/configure-notification-position.js index 396abab6..7cc94f04 100644 --- a/js/notify/settings/configure-notification-position.js +++ b/js/notify/settings/configure-notification-position.js @@ -155,6 +155,7 @@ function updateConfig() { */ function updateNotification(mPosition, mDisplay) { notify.updateConfig({position: mPosition, display: mDisplay}); + eventEmitter.emit('notificationSettings', {position: mPosition, display: mDisplay}); notify.reset(); }