Skip to content

Commit

Permalink
Merge pull request #1 from gloriousDan/fix-mtnclock-widgets
Browse files Browse the repository at this point in the history
Fix mtnclock widgets
  • Loading branch information
gloriousDan authored Sep 25, 2024
2 parents 4689f45 + 3d519f8 commit d9ba7ea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/mtnclock/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
0.02: Get weather from weather.json
0.03: Address unexpected undefined when reading weather.json
0.04: Adding settings and the ability to show the widgets bar
0.05: Fix the widgets disappearing on weather update
24 changes: 17 additions & 7 deletions apps/mtnclock/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ g.clear();
}
}

var i = 0;

function setWeather() {
var a = {};
//clear day/night is default weather
Expand Down Expand Up @@ -270,7 +268,7 @@ function setWeather() {
//night-drizzle
if ((data.code >= 300 && data.code < 600) || (data.code >= 200 && data.code <= 202) || (data.code >= 230 && data.code <= 232)) a.rain1 = 0xC618;
//night-rain
if ((data.code >= 500 && data.code < 600) || (data.code >= 200 && data.code <= 202)) rain2 = 1;
if ((data.code >= 500 && data.code < 600) || (data.code >= 200 && data.code <= 202)) a.rain2 = 1;
}
}
else if ((data.code >= 700) && (data.code < 800)) {
Expand Down Expand Up @@ -331,24 +329,36 @@ function readWeather() {
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 && weatherJson.weather && weatherJson.weather.time && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) {
data = {
newSettings = {
time: weatherJson.weather.time,
temp: weatherJson.weather.temp,
code: weatherJson.weather.code
};
require("Storage").writeJSON('mtnclock.json', data);
require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
readJson('mtnclock.json'),
newSettings,
);
)
}
}

const _GB = global.GB;
global.GB = (event) => {
if (event.t==="weather") {
data = {
newSettings = {
temp: event.temp,
code: event.code,
time: Date.now()
};
require("Storage").writeJSON('mtnclock.json', data);
require("Storage").writeJSON(
'mtnclock.json',
Object.assign(
readJson('mtnclock.json'),
newSettings,
);
)
setWeather();
}
if (_GB) setTimeout(_GB, 0, event);
Expand Down
4 changes: 2 additions & 2 deletions apps/mtnclock/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "mtnclock",
"name": "Mountain Pass Clock",
"shortName": "Mtn Clock",
"version": "0.04",
"version": "0.05",
"description": "A clock that changes scenery based on time and weather.",
"readme":"README.md",
"icon": "app.png",
Expand All @@ -23,4 +23,4 @@
{"name":"mtnclock.img","url":"app-icon.js","evaluate":true}
],
"data": [{"name":"mtnclock.json"}]
}
}

0 comments on commit d9ba7ea

Please sign in to comment.