From 20dabaff278b32cef7d746a8072315700f2c7ce6 Mon Sep 17 00:00:00 2001 From: Maksim Sukharev Date: Tue, 5 Dec 2023 13:59:37 +0100 Subject: [PATCH] fix(session): fix mouse events for Firefox, change behavior Signed-off-by: Maksim Sukharev --- src/composables/useActiveSession.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/composables/useActiveSession.js b/src/composables/useActiveSession.js index 0a4bdf81c62..ef94ea6c665 100644 --- a/src/composables/useActiveSession.js +++ b/src/composables/useActiveSession.js @@ -120,23 +120,27 @@ export function useActiveSession() { if (type === 'focus') { setSessionAsActive() - document.removeEventListener('mouseenter', handleMouseMove) - document.removeEventListener('mouseleave', handleMouseMove) + document.body.removeEventListener('mouseenter', handleMouseEnter) + document.body.removeEventListener('mouseleave', handleMouseLeave) } else if (type === 'blur') { inactiveTimer.value = setTimeout(() => { setSessionAsInactive() }, INACTIVE_TIME_MS) // Listen for mouse events to track activity on tab - document.addEventListener('mouseenter', handleMouseMove) - document.addEventListener('mouseleave', handleMouseMove) + document.body.addEventListener('mouseenter', handleMouseEnter) + document.body.addEventListener('mouseleave', handleMouseLeave) } } - const handleMouseMove = (event) => { + const handleMouseEnter = (event) => { setSessionAsActive() - // Restart timer, if mouse moves around the tab clearTimeout(inactiveTimer.value) + inactiveTimer.value = null + } + + const handleMouseLeave = (event) => { + // Restart timer, if mouse leaves the tab inactiveTimer.value = setTimeout(() => { setSessionAsInactive() }, INACTIVE_TIME_MS)