Improve timer interval refresh behavior
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s

This commit is contained in:
Shinuwa 2026-08-03 15:57:25 +02:00
parent fdc81373c6
commit a6b2388763
9 changed files with 305 additions and 39 deletions

View file

@ -16,6 +16,8 @@ const NOTEPAD_RGB_COLOR_MAP = {
const TIMER_TABS = new Set(["stopwatch", "countdown"]);
const COUNTDOWN_TYPES = new Set(["duration", "daily_time", "time_pattern", "interval"]);
const TIMER_ALERT_MODES = new Set(["off", "visible", "site"]);
const TIMER_INTERVAL_START_MODES = new Set(["now", "time"]);
const TIMER_MIN_AUTO_REFRESH_MS = 5 * 60 * 1000;
const TASK_TYPES = new Set(["unique", "daily", "weekly"]);
const COMBO_DEVICES = new Set(["playstation", "xbox", "switch", "n64", "keyboardMouse"]);
const COMBO_INPUT_KINDS = new Set(["button", "direction", "key", "mouse"]);
@ -553,7 +555,7 @@ export function normalizeTimerData(data) {
if (type === "daily_time") {
const time = String(countdown?.time || "").trim();
const targetAt = Math.max(0, Number(countdown?.targetAt) || 0);
return isTimeString(time) && targetAt > 0 ? { ...normalized, time, targetAt } : null;
return isTimeString(time) && targetAt > 0 ? { ...normalized, time, targetAt, autoRefresh: countdown?.autoRefresh === true } : null;
}
if (type === "time_pattern") {
const pattern = String(countdown?.pattern || "").trim().toUpperCase();
@ -562,7 +564,21 @@ export function normalizeTimerData(data) {
if (type === "interval") {
const intervalMs = Math.max(0, Number(countdown?.intervalMs) || 0);
const anchorAt = Math.max(0, Number(countdown?.anchorAt) || 0);
return intervalMs > 0 ? { ...normalized, intervalMs, anchorAt } : null;
const targetAt = Math.max(0, Number(countdown?.targetAt) || 0);
const startMode = TIMER_INTERVAL_START_MODES.has(countdown?.startMode) ? countdown.startMode : "now";
const startTime = String(countdown?.startTime || "").trim();
const autoRefresh = countdown?.autoRefresh === true || (countdown?.autoRefresh !== false && !targetAt && intervalMs >= TIMER_MIN_AUTO_REFRESH_MS);
return intervalMs > 0
? {
...normalized,
intervalMs,
anchorAt,
targetAt: targetAt || anchorAt + intervalMs,
startMode: startMode === "time" && isTimeString(startTime) ? "time" : "now",
...(startMode === "time" && isTimeString(startTime) ? { startTime } : {}),
autoRefresh: autoRefresh && intervalMs >= TIMER_MIN_AUTO_REFRESH_MS
}
: null;
}
return null;
})
@ -822,11 +838,14 @@ export function compactModuleDataForStorage(type, value) {
}
if (normalized.countdowns.length) {
compact.countdowns = normalized.countdowns.map((countdown) => {
if (countdown.alertMode === "off") {
const { alertMode, ...compactCountdown } = countdown;
return compactCountdown;
const { alertMode, autoRefresh, startMode, startTime, ...compactCountdown } = countdown;
if (alertMode !== "off") compactCountdown.alertMode = alertMode;
if (autoRefresh) compactCountdown.autoRefresh = true;
if (startMode === "time" && startTime) {
compactCountdown.startMode = startMode;
compactCountdown.startTime = startTime;
}
return countdown;
return compactCountdown;
});
}
return Object.keys(compact).length ? compact : null;