ui: Handle new nextchangetime settings

This commit is contained in:
nemunaire 2024-03-17 17:06:58 +01:00
parent 0db9e9b539
commit 6e684436d1

View File

@ -4,6 +4,7 @@ import { stop_refresh } from './common';
import { my } from './my'; import { my } from './my';
let refresh_interval_settings = null; let refresh_interval_settings = null;
let refresh_timeout_settings = null;
function createSettingsStore() { function createSettingsStore() {
const { subscribe, set, update } = writable({}); const { subscribe, set, update } = writable({});
@ -19,8 +20,8 @@ function createSettingsStore() {
settings.end = new Date(settings.end); settings.end = new Date(settings.end);
if (settings.generation) if (settings.generation)
settings.generation = new Date(settings.generation); settings.generation = new Date(settings.generation);
if (settings.activateTime) if (settings.nextchangetime)
settings.activateTime = new Date(settings.activateTime); settings.nextchangetime = new Date(settings.nextchangetime);
if (!settings.disablesubmitbutton) if (!settings.disablesubmitbutton)
settings.disablesubmitbutton = null; settings.disablesubmitbutton = null;
@ -59,14 +60,24 @@ function createSettingsStore() {
if (stgs.start > srv_cur) { if (stgs.start > srv_cur) {
const startIn = stgs.start - srv_cur; const startIn = stgs.start - srv_cur;
if (refresh_timeout_settings)
clearTimeout(refresh_timeout_settings);
if (startIn > 15000) { 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) { } 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 { } else {
// On scheduled start time, refresh my.json file // 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));
} }
}; };
} }