[mtnclock] Fix widgets disappearing on weather update

pull/3586/head
Daniel Schulz 2024-09-23 19:24:33 +02:00
parent 4689f45da5
commit a2e054e958
3 changed files with 19 additions and 6 deletions

View File

@ -2,3 +2,4 @@
0.02: Get weather from weather.json 0.02: Get weather from weather.json
0.03: Address unexpected undefined when reading weather.json 0.03: Address unexpected undefined when reading weather.json
0.04: Adding settings and the ability to show the widgets bar 0.04: Adding settings and the ability to show the widgets bar
0.05: Fix the widgets disappearing on weather update

View File

@ -331,24 +331,36 @@ function readWeather() {
var weatherJson = require("Storage").readJSON('weather.json', 1); var weatherJson = require("Storage").readJSON('weather.json', 1);
// save updated weather data if available and it has been an hour since last updated // save updated weather data if available and it has been an hour since last updated
if (weatherJson && weatherJson.weather && weatherJson.weather.time && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) { if (weatherJson && weatherJson.weather && weatherJson.weather.time && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) {
data = { const newSettings = {
time: weatherJson.weather.time, time: weatherJson.weather.time,
temp: weatherJson.weather.temp, temp: weatherJson.weather.temp,
code: weatherJson.weather.code code: weatherJson.weather.code
}; };
require("Storage").writeJSON('mtnclock.json', data); require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
require("Storage").readJSON('mtnclock.json', 1),
newSettings
)
);
} }
} }
const _GB = global.GB; const _GB = global.GB;
global.GB = (event) => { global.GB = (event) => {
if (event.t==="weather") { if (event.t==="weather") {
data = { const newSettings = {
temp: event.temp, temp: event.temp,
code: event.code, code: event.code,
time: Date.now() time: Date.now()
}; };
require("Storage").writeJSON('mtnclock.json', data); require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
require("Storage").readJSON('mtnclock.json', 1),
newSettings
)
);
setWeather(); setWeather();
} }
if (_GB) setTimeout(_GB, 0, event); if (_GB) setTimeout(_GB, 0, event);

View File

@ -2,7 +2,7 @@
"id": "mtnclock", "id": "mtnclock",
"name": "Mountain Pass Clock", "name": "Mountain Pass Clock",
"shortName": "Mtn Clock", "shortName": "Mtn Clock",
"version": "0.04", "version": "0.05",
"description": "A clock that changes scenery based on time and weather.", "description": "A clock that changes scenery based on time and weather.",
"readme":"README.md", "readme":"README.md",
"icon": "app.png", "icon": "app.png",
@ -23,4 +23,4 @@
{"name":"mtnclock.img","url":"app-icon.js","evaluate":true} {"name":"mtnclock.img","url":"app-icon.js","evaluate":true}
], ],
"data": [{"name":"mtnclock.json"}] "data": [{"name":"mtnclock.json"}]
} }