diff --git a/apps/mtnclock/app.js b/apps/mtnclock/app.js index 82d06e03b..996fe2cee 100644 --- a/apps/mtnclock/app.js +++ b/apps/mtnclock/app.js @@ -324,19 +324,26 @@ function setWeather() { } function readWeather() { - var weatherData = require("Storage").readJSON('weather.json', true); - if (weatherData !== undefined) { - if (weatherData.weather.time > data.time) { - data = weatherData.weather; - require("Storage").write('mtnclock.json', data); - } + var weatherJson = require("Storage").readJSON('weather.json', 1); + // save updated weather data if available and it has been an hour since last updated + if (weatherJson !== undefined && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) { + data = { + time: weatherJson.weather.time, + temp: weatherJson.weather.temp, + code: weatherJson.weather.code + }; + require("Storage").writeJSON('mtnclock.json', data); } } const _GB = global.GB; global.GB = (event) => { if (event.t==="weather") { - data = event; + data = { + temp: event.temp, + code: event.code, + time: Date.now() + }; require("Storage").write('mtnclock.json', event); setWeather(); } @@ -357,5 +364,6 @@ function queueDraw() { } queueDraw(); +readWeather(); setWeather(); Bangle.setUI("clock");