Created
February 11, 2019 21:50
-
-
Save cpave3/7bc4f9a99397b8c7db764d0d9596b787 to your computer and use it in GitHub Desktop.
Determine when a user should be considered inactive or away
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ioHook = require('iohook'); // For checking system input activity | |
const logUpdate = require('log-update'); // For writing out to the terminal | |
const moment = require('moment'); // Time related stuff | |
let idleTime = moment(); | |
// Listen for all the events we consider activity | |
ioHook.on("keyup", event => { | |
resetIdle(); | |
}); | |
ioHook.on("mousemove", event => { | |
resetIdle(); | |
}); | |
ioHook.start(); | |
// Every second, check if they should be considered inactive yet | |
setInterval(() => { | |
logUpdate(`Time since activity: ${moment().diff(idleTime, 'seconds')} \nInactive: ${moment().diff(idleTime, 'seconds') >= 15}`) | |
}, 1000) | |
// Set the latest activity time to now | |
function resetIdle() { | |
idleTime = moment() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment