From da55ade2d38457b20c2643dfe0e809ed28b5b949 Mon Sep 17 00:00:00 2001 From: Tom Wallroth Date: Sat, 16 Nov 2024 18:43:35 +0100 Subject: [PATCH] tiny refactor on top --- apps/owmweather/boot.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/apps/owmweather/boot.js b/apps/owmweather/boot.js index 5b513f59a..f2a2116ed 100644 --- a/apps/owmweather/boot.js +++ b/apps/owmweather/boot.js @@ -7,11 +7,7 @@ ); let refreshMillis = function () { - return settings.refresh * 1000 * 60 - } - - let nextDueDate = function () { - return settings.updated + refreshMillis() + 1 + return settings.refresh * 1000 * 60 + 1 // +1 <- leave some slack } let onCompleted = function () { @@ -19,7 +15,7 @@ settings.updated = Date.now(); require('Storage').writeJSON("owmweather.json", settings); if (timeoutRef) clearTimeout(timeoutRef); - timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis() + 1); + timeoutRef = setTimeout(loadIfDueAndReschedule, refreshMillis()); } let loadIfDueAndReschedule = function () { @@ -30,7 +26,7 @@ settings.updated = lastWeatherUpdate; } - let MillisUntilDue = nextDueDate() - Date.now(); + let MillisUntilDue = settings.updated + refreshMillis() - Date.now(); if (MillisUntilDue <= 0) { if (!loading) { loading = true;