Electron-235 (Fix javascript error in notification) (#326)

- Fix javascript error "object has been destroyed"
- Fix notification javascript error and position issue
- Remove unused export
This commit is contained in:
Kiran Niranjan 2018-03-18 14:35:02 +05:30 committed by Vishwas Shashidhar
parent ecb0f88660
commit 6914f30151
3 changed files with 56 additions and 18 deletions

View File

@ -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

View File

@ -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();

View File

@ -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();
}