add refresh flag to getdata funcions

This commit is contained in:
Matt Walsh
2025-04-02 11:10:58 -05:00
parent b272aa298a
commit 23cc1a1f7a
14 changed files with 34 additions and 18 deletions

View File

@@ -21,7 +21,7 @@ class Almanac extends WeatherDisplay {
this.timing.totalScreens = 1; this.timing.totalScreens = 1;
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
const superResponse = super.getData(_weatherParameters); const superResponse = super.getData(_weatherParameters);
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -21,7 +21,7 @@ class CurrentWeather extends WeatherDisplay {
this.backgroundImage = loadImg('images/BackGround1_1.png'); this.backgroundImage = loadImg('images/BackGround1_1.png');
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
// always load the data for use in the lower scroll // always load the data for use in the lower scroll
const superResult = super.getData(_weatherParameters); const superResult = super.getData(_weatherParameters);
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -18,7 +18,7 @@ class ExtendedForecast extends WeatherDisplay {
this.timing.totalScreens = 2; this.timing.totalScreens = 2;
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters)) return; if (!super.getData(_weatherParameters)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -26,7 +26,7 @@ class Hazards extends WeatherDisplay {
this.timing.totalScreens = 0; this.timing.totalScreens = 0;
} }
async getData(weatherParameters) { async getData(weatherParameters, refresh) {
// super checks for enabled // super checks for enabled
const superResult = super.getData(weatherParameters); const superResult = super.getData(weatherParameters);

View File

@@ -23,7 +23,7 @@ class HourlyGraph extends WeatherDisplay {
this.elem.querySelector('.header .right').append(header); this.elem.querySelector('.header .right').append(header);
} }
async getData() { async getData(_weatherParameters, refresh) {
if (!super.getData()) return; if (!super.getData()) return;
const data = await getHourlyData(() => this.stillWaiting()); const data = await getHourlyData(() => this.stillWaiting());

View File

@@ -27,7 +27,7 @@ class Hourly extends WeatherDisplay {
this.timing.delay.push(150); this.timing.delay.push(150);
} }
async getData(weatherParameters) { async getData(weatherParameters, refresh) {
// super checks for enabled // super checks for enabled
const superResponse = super.getData(weatherParameters); const superResponse = super.getData(weatherParameters);
let forecast; let forecast;

View File

@@ -16,7 +16,7 @@ class LatestObservations extends WeatherDisplay {
this.MaximumRegionalStations = 7; this.MaximumRegionalStations = 7;
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters)) return; if (!super.getData(_weatherParameters)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -14,7 +14,7 @@ class LocalForecast extends WeatherDisplay {
this.timing.baseDelay = 5000; this.timing.baseDelay = 5000;
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters)) return; if (!super.getData(_weatherParameters)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -42,7 +42,7 @@ class Radar extends WeatherDisplay {
]; ];
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters)) return; if (!super.getData(_weatherParameters)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;
@@ -70,7 +70,7 @@ class Radar extends WeatherDisplay {
const lists = (await Promise.all(baseUrls.map(async (url) => { const lists = (await Promise.all(baseUrls.map(async (url) => {
try { try {
// get a list of available radars // get a list of available radars
return text(url, { cors: true }); return text(url, { cors: true });
} catch (error) { } catch (error) {
console.log('Unable to get list of radars'); console.log('Unable to get list of radars');
@@ -91,7 +91,7 @@ class Radar extends WeatherDisplay {
const anchors = xmlDoc.querySelectorAll('a'); const anchors = xmlDoc.querySelectorAll('a');
const urls = []; const urls = [];
Array.from(anchors).forEach((elem) => { Array.from(anchors).forEach((elem) => {
if (elem.innerHTML?.match(/n0r_\d{12}\.png/)) { if (elem.innerHTML?.match(/n0r_\d{12}\.png/)) {
urls.push(elem.href); urls.push(elem.href);
} }
}); });

View File

@@ -21,7 +21,7 @@ class RegionalForecast extends WeatherDisplay {
this.timing.totalScreens = 3; this.timing.totalScreens = 3;
} }
async getData(_weatherParameters) { async getData(_weatherParameters, refresh) {
if (!super.getData(_weatherParameters)) return; if (!super.getData(_weatherParameters)) return;
const weatherParameters = _weatherParameters ?? this.weatherParameters; const weatherParameters = _weatherParameters ?? this.weatherParameters;

View File

@@ -22,6 +22,13 @@ const init = () => {
['us', 'US'], ['us', 'US'],
['si', 'Metric'], ['si', 'Metric'],
]); ]);
settings.refreshTime = new Setting('refreshTime', 'Refresh Time', 'select', 30_000, null, false, [
[30_000, 'TESTING'],
[300_000, '5 minutes'],
[600_000, '10 minutes'],
[900_000, '15 minutes'],
[1_800_000, '30 minutes'],
]);
// generate html objects // generate html objects
const settingHtml = Object.values(settings).map((d) => d.generate()); const settingHtml = Object.values(settings).map((d) => d.generate());

View File

@@ -28,9 +28,9 @@ class TravelForecast extends WeatherDisplay {
this.timing.delay.push(150); this.timing.delay.push(150);
} }
async getData() { async getData(weatherParameters, refresh) {
// super checks for enabled // super checks for enabled
if (!super.getData()) return; if (!super.getData(this.weatherParameters)) return;
const forecastPromises = TravelCities.map(async (city) => { const forecastPromises = TravelCities.map(async (city) => {
try { try {
// get point then forecast // get point then forecast

View File

@@ -22,6 +22,7 @@ class WeatherDisplay {
this.okToDrawCurrentConditions = true; this.okToDrawCurrentConditions = true;
this.okToDrawCurrentDateTime = true; this.okToDrawCurrentDateTime = true;
this.showOnProgress = true; this.showOnProgress = true;
this.autoRefreshHandle = null;
// default navigation timing // default navigation timing
this.timing = { this.timing = {
@@ -129,9 +130,14 @@ class WeatherDisplay {
} }
// get necessary data for this display // get necessary data for this display
getData(weatherParameters) { getData(weatherParameters, refresh) {
// clear current data // refresh doesn't delete existing data, and is resued if the silent refresh fails
this.data = undefined; if (!refresh) {
this.data = undefined;
}
// clear any refresh timers
clearTimeout(this.autoRefreshHandle);
this.autoRefreshHandle = null;
// store weatherParameters locally in case we need them later // store weatherParameters locally in case we need them later
if (weatherParameters) this.weatherParameters = weatherParameters; if (weatherParameters) this.weatherParameters = weatherParameters;
@@ -144,6 +150,9 @@ class WeatherDisplay {
return false; return false;
} }
// set up auto reload
this.autoRefreshHandle = setTimeout(() => this.getData(false, true), settings.refreshTime.value);
// recalculate navigation timing (in case it was modified in the constructor) // recalculate navigation timing (in case it was modified in the constructor)
this.calcNavTiming(); this.calcNavTiming();
return true; return true;

View File

@@ -14,7 +14,7 @@
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" /> <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<link rel="manifest" href="manifest.json" /> <link rel="manifest" href="manifest.json" />
<link rel="icon" href="images/Logo192.png" /> <link rel="icon" href="images/Logo192.png" />
<link rel="preload" href="playlist.json" as="fetch"/> <link rel="preload" href="playlist.json" as="fetch" crossorigin="anonymous"/>
<meta property="og:image" content="https://weatherstar.netbymatt.com/images/social/1200x600.png"> <meta property="og:image" content="https://weatherstar.netbymatt.com/images/social/1200x600.png">
<meta property="og:image:width" content="1200"> <meta property="og:image:width" content="1200">
<meta property="og:image:height" content="627"> <meta property="og:image:height" content="627">