-
-
Save yayitswei/c1efdce6bfa2fc16b548 to your computer and use it in GitHub Desktop.
This file contains 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
(defn start-autologout-monitoring [] | |
(let [activity-ch (async/chan)] | |
(.ready | |
($ js/document) | |
(fn [] | |
(this-as | |
this | |
(.mousemove ($ this) (fn [_] (go (>! activity-ch true)))) | |
(.keypress ($ this) (fn [_] (go (>! activity-ch true)))) | |
(go | |
(loop [] | |
(let [[v p] (async/alts! [(async/timeout 5000) activity-ch])] | |
(if v (recur)))) | |
(.open js/window "/logout"))))))) |
This file contains 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
// source: http://stackoverflow.com/questions/667555/detecting-idle-time-in-javascript-elegantly | |
var idleTime = 0; | |
$(document).ready(function () { | |
//Increment the idle time counter every minute. | |
var idleInterval = setInterval(timerIncrement, 60000); // 1 minute | |
//Zero the idle timer on mouse movement. | |
$(this).mousemove(function (e) { | |
idleTime = 0; | |
}); | |
$(this).keypress(function (e) { | |
idleTime = 0; | |
}); | |
}); | |
function timerIncrement() { | |
idleTime = idleTime + 1; | |
if (idleTime > 19) { // 20 minutes | |
window.location.reload(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment