Skip to content

Commit

Permalink
tiny refactor on top
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnd committed Nov 16, 2024
1 parent e1f16ea commit da55ade
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions apps/owmweather/boot.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@
);

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 () {
loading = false;
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 () {
Expand All @@ -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;
Expand Down

0 comments on commit da55ade

Please sign in to comment.