Web: reload window 60 minutes after user activity
Reload the webapp 60 minutes after keyboard/mouse activity. Previously this was a hard 60 minutes after the webapp was loaded, which means that it could happen while someone was actively working in the web interface. This should now be prevented.
This commit is contained in:
parent
f8c49981f6
commit
7bceaf5b10
36
web/app/src/autoreloader.js
Normal file
36
web/app/src/autoreloader.js
Normal file
@ -0,0 +1,36 @@
|
||||
import { DateTime } from "luxon";
|
||||
|
||||
// Do a full refresh once per hour. This is just to make sure that long-lived
|
||||
// displays (like the TV in the hallway at Blender HQ) pick up on HTML/JS/CSS
|
||||
// changes eventually.
|
||||
const reloadAfter = {minute: 60};
|
||||
|
||||
function getReloadDeadline() {
|
||||
return DateTime.now().plus(reloadAfter);
|
||||
}
|
||||
|
||||
let reloadAt = getReloadDeadline();
|
||||
|
||||
// Every activity (mouse move, keyboard, etc.) defers the reload.
|
||||
function deferReload() {
|
||||
reloadAt = getReloadDeadline();
|
||||
}
|
||||
|
||||
function maybeReload() {
|
||||
const now = DateTime.now();
|
||||
if (now < reloadAt) return;
|
||||
|
||||
window.location.reload();
|
||||
}
|
||||
|
||||
export default function autoreload() {
|
||||
// Check whether reloading is needed every minute.
|
||||
window.setInterval(maybeReload, 60 * 1000);
|
||||
|
||||
window.addEventListener("resize", deferReload);
|
||||
window.addEventListener("mousedown", deferReload);
|
||||
window.addEventListener("mouseup", deferReload);
|
||||
window.addEventListener("mousemove", deferReload);
|
||||
window.addEventListener("keydown", deferReload);
|
||||
window.addEventListener("keyup", deferReload);
|
||||
}
|
@ -14,11 +14,6 @@ window.plain = (x) => JSON.parse(JSON.stringify(x));
|
||||
// objectEmpty returns whether the object is empty or not.
|
||||
window.objectEmpty = (o) => !o || Object.entries(o).length == 0;
|
||||
|
||||
// Do a full refresh once per hour. This is just to make sure that long-lived
|
||||
// displays (like the TV in the hallway at Blender HQ) pick up on HTML/JS/CSS
|
||||
// changes eventually.
|
||||
window.setTimeout(() => {window.location.reload(); }, 3600 * 1000);
|
||||
|
||||
const app = createApp(App)
|
||||
const pinia = createPinia()
|
||||
|
||||
@ -35,3 +30,7 @@ window.jobs = useJobs();
|
||||
window.notifs = useNotifs();
|
||||
window.taskLog = useTaskLog();
|
||||
window.API = API;
|
||||
|
||||
// Automatically reload the window after a period of inactivity from the user.
|
||||
import autoreload from '@/autoreloader'
|
||||
autoreload();
|
||||
|
Loading…
x
Reference in New Issue
Block a user