ui: Handle new nextchangetime settings

This commit is contained in:
nemunaire 2024-03-17 17:06:58 +01:00
parent 0db9e9b539
commit 6e684436d1
1 changed files with 16 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import { stop_refresh } from './common';
import { my } from './my';
let refresh_interval_settings = null;
let refresh_timeout_settings = null;
function createSettingsStore() {
const { subscribe, set, update } = writable({});
@ -19,8 +20,8 @@ function createSettingsStore() {
settings.end = new Date(settings.end);
if (settings.generation)
settings.generation = new Date(settings.generation);
if (settings.activateTime)
settings.activateTime = new Date(settings.activateTime);
if (settings.nextchangetime)
settings.nextchangetime = new Date(settings.nextchangetime);
if (!settings.disablesubmitbutton)
settings.disablesubmitbutton = null;
@ -59,14 +60,24 @@ function createSettingsStore() {
if (stgs.start > srv_cur) {
const startIn = stgs.start - srv_cur;
if (refresh_timeout_settings)
clearTimeout(refresh_timeout_settings);
if (startIn > 15000) {
setTimeout(refreshFunc, Math.floor(Math.random() * 3500) + 10000);
refresh_timeout_settings = setTimeout(refreshFunc, Math.floor(Math.random() * 3500) + 10000);
} else if (startIn > 1500) {
setTimeout(refreshFunc, startIn - 1000 - Math.floor(Math.random() * 500))
refresh_timeout_settings = setTimeout(refreshFunc, startIn - 1000 - Math.floor(Math.random() * 500))
} else {
// On scheduled start time, refresh my.json file
setTimeout(my.refresh, startIn + Math.floor(Math.random() * 200))
refresh_timeout_settings = setTimeout(my.refresh, startIn + Math.floor(Math.random() * 200))
}
} else if (stgs.nextchangetime > srv_cur) {
if (refresh_timeout_settings)
clearTimeout(refresh_timeout_settings);
refresh_timeout_settings = setTimeout(() => {
refreshFunc();
setTimeout(my.refresh, 4500 + Math.floor(Math.random() * 2000));
}, stgs.nextchangetime - srv_cur + 500 + Math.floor(Math.random() * 500));
}
};
}