We’ve been using nativefier with CircleCI for a while, and it’s great. Luckily, nativefier also makes it easy to fix this issue locally.
You make a local JS script called reloadPageInactivity.js
with the following (based on StackOverflow):
var refresh_rate = 30; //<-- In seconds, change to your needs
var last_user_action = 0;
var has_focus = false;
var lost_focus_count = 0;
var focus_margin = 10; // If we lose focus more then the margin we want to refresh
function reset() {
last_user_action = 0;
console.log("Reset");
}
function windowHasFocus() {
has_focus = true;
}
function windowLostFocus() {
has_focus = false;
lost_focus_count++;
console.log(lost_focus_count + " <~ Lost Focus");
}
setInterval(function () {
last_user_action++;
refreshCheck();
}, 1000);
function refreshCheck() {
var focus = window.onfocus;
if ((last_user_action >= refresh_rate && !has_focus && document.readyState == "complete") || lost_focus_count > focus_margin) {
window.location.reload(); // If this is called no reset is needed
reset(); // We want to reset just to make sure the location reload is not called.
}
}
window.addEventListener("focus", windowHasFocus, false);
window.addEventListener("blur", windowLostFocus, false);
window.addEventListener("click", reset, false);
window.addEventListener("mousemove", reset, false);
window.addEventListener("keypress", reset, false);
window.addEventListener("scroll", reset, false);
document.addEventListener("touchMove", reset, false);
document.addEventListener("touchEnd", reset, false);
Then you run nativefier:
nativefier https://circleci.com/gh/RuneAI --internal-urls "(.*?)(github\.com|circleci\.com)(.*?)" --name "CircleCI" --inject reloadPageInactivity.js
Voila! You now have a local CircleCI app that refreshes after 30 sec of inactivity. Hope that’s useful to anyone.