mirror of
https://github.com/finos/SymphonyElectron.git
synced 2025-02-25 18:55:29 -06:00
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:
committed by
Vishwas Shashidhar
parent
3a9f156317
commit
4d15f03492
@@ -10,6 +10,9 @@ const electron = require('electron');
|
|||||||
const ipc = electron.ipcRenderer;
|
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);
|
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
|
* Sets style for a notification
|
||||||
@@ -134,6 +137,28 @@ function setContents(event, notificationObj) {
|
|||||||
|
|
||||||
const winId = notificationObj.windowId;
|
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
|
// note: use onclick because we only want one handler, for case
|
||||||
// when content gets overwritten by notf with same tag
|
// when content gets overwritten by notf with same tag
|
||||||
closeButton.onclick = function(clickEvent) {
|
closeButton.onclick = function(clickEvent) {
|
||||||
@@ -197,7 +222,10 @@ function reset() {
|
|||||||
let newContainer = container.cloneNode(true);
|
let newContainer = container.cloneNode(true);
|
||||||
container.parentNode.replaceChild(newContainer, container);
|
container.parentNode.replaceChild(newContainer, container);
|
||||||
let newCloseButton = closeButton.cloneNode(true);
|
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);
|
ipc.on('electron-notify-set-contents', setContents);
|
||||||
|
|||||||
@@ -435,7 +435,6 @@ function setNotificationContents(notfWindow, notfObj) {
|
|||||||
});
|
});
|
||||||
let closeNotificationSafely = buildCloseNotificationSafely(closeFunc);
|
let closeNotificationSafely = buildCloseNotificationSafely(closeFunc);
|
||||||
|
|
||||||
// don't start timer to close if we aren't sticky
|
|
||||||
if (!notfObj.sticky) {
|
if (!notfObj.sticky) {
|
||||||
timeoutId = setTimeout(function() {
|
timeoutId = setTimeout(function() {
|
||||||
closeNotificationSafely('timeout');
|
closeNotificationSafely('timeout');
|
||||||
@@ -744,6 +743,42 @@ function cleanUpInactiveWindow() {
|
|||||||
inactiveWindows = [];
|
inactiveWindows = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Start a new timer to close the notification
|
||||||
|
* @param event
|
||||||
|
* @param winId
|
||||||
|
* @param notificationObj
|
||||||
|
*/
|
||||||
|
function onMouseLeave(event, winId, notificationObj) {
|
||||||
|
if (winId) {
|
||||||
|
const notificationWindow = BrowserWindow.fromId(winId);
|
||||||
|
if (notificationWindow && !notificationWindow.isDestroyed()) {
|
||||||
|
notificationWindow.displayTimer = setTimeout(function () {
|
||||||
|
let closeFunc = buildCloseNotification(BrowserWindow.fromId(winId), notificationObj);
|
||||||
|
buildCloseNotificationSafely(closeFunc)('close');
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clears the timer for a specific notification window
|
||||||
|
* @param event
|
||||||
|
* @param winId
|
||||||
|
*/
|
||||||
|
function onMouseOver(event, winId) {
|
||||||
|
if (winId) {
|
||||||
|
const notificationWindow = BrowserWindow.fromId(winId);
|
||||||
|
if (notificationWindow) {
|
||||||
|
clearTimeout(notificationWindow.displayTimer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// capturing mouse events
|
||||||
|
ipc.on('electron-notify-mouseleave', onMouseLeave);
|
||||||
|
ipc.on('electron-notify-mouseover', onMouseOver);
|
||||||
|
|
||||||
|
|
||||||
module.exports.notify = notify;
|
module.exports.notify = notify;
|
||||||
module.exports.updateConfig = updateConfig;
|
module.exports.updateConfig = updateConfig;
|
||||||
|
|||||||
Reference in New Issue
Block a user