Skip to content

Commit

Permalink
Merge pull request #11127 from nextcloud/fix/11126/more-activity-events
Browse files Browse the repository at this point in the history
fix(session): track mouse movement activity
  • Loading branch information
Antreesy authored Dec 6, 2023
2 parents b2d5cca + 20dabaf commit 4edb17f
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/composables/useActiveSession.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4edb17f

Please sign in to comment.