Electron-414 (Add a logic not to close the notifications on mouse hover) (#338)

- Add logic to not close the notification on mouse hover
- Clear timer when the notification content is reset
- Move logic from preload to main process
- Remove unwanted code
- Remove event listener on reset
This commit is contained in:
Kiran Niranjan
2018-05-01 12:04:24 +05:30
committed by Vishwas Shashidhar
parent 3a9f156317
commit 4d15f03492
2 changed files with 65 additions and 2 deletions

View File

@@ -10,6 +10,9 @@ const electron = require('electron');
const ipc = electron.ipcRenderer;
const whiteColorRegExp = new RegExp(/^(?:white|#fff(?:fff)?|rgba?\(\s*255\s*,\s*255\s*,\s*255\s*(?:,\s*1\s*)?\))$/i);
// event functions ref
let onMouseLeaveFunc;
let onMouseOverFunc;
/**
* Sets style for a notification
@@ -134,6 +137,28 @@ function setContents(event, notificationObj) {
const winId = notificationObj.windowId;
if (!notificationObj.sticky) {
onMouseLeaveFunc = onMouseLeave.bind(this);
onMouseOverFunc = onMouseOver.bind(this);
container.addEventListener('mouseleave', onMouseLeaveFunc);
container.addEventListener('mouseover', onMouseOverFunc);
}
/**
* Start a new timer to close the notification
*/
function onMouseLeave() {
ipc.send('electron-notify-mouseleave', winId, notificationObj);
}
/**
* Clear all timeouts to prevent notification
* from closing
*/
function onMouseOver() {
ipc.send('electron-notify-mouseover', winId);
}
// note: use onclick because we only want one handler, for case
// when content gets overwritten by notf with same tag
closeButton.onclick = function(clickEvent) {
@@ -197,7 +222,10 @@ function reset() {
let newContainer = container.cloneNode(true);
container.parentNode.replaceChild(newContainer, container);
let newCloseButton = closeButton.cloneNode(true);
closeButton.parentNode.replaceChild(newCloseButton, closeButton)
closeButton.parentNode.replaceChild(newCloseButton, closeButton);
container.removeEventListener('mouseleave', onMouseLeaveFunc);
container.removeEventListener('mouseover', onMouseOverFunc);
}
ipc.on('electron-notify-set-contents', setContents);