Merge pull request #3030 from r-j-taylor/mtnclock-add-widgets

[mtnclock] Add settings and the ability to show widgets
pull/3035/head^2
Gordon Williams 2023-09-29 09:46:23 +01:00 committed by GitHub
commit 095b0c80ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 2 deletions

View File

@ -1,3 +1,4 @@
0.01: New App!
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

View File

@ -196,6 +196,10 @@ g.clear();
(color.clock == undefined) ? g.setColor(0xFFFF) : g.setColor(color.clock);
g.setFont("Vector", py(20)).setFontAlign(-1, -1).drawString((require("locale").time(new Date(), 1).replace(" ", "")), px(2), py(67));
g.setFont("Vector", py(10)).drawString(require('locale').dow(new Date(), 1)+" "+new Date().getDate()+" "+require('locale').month(new Date(), 1)+((data.temp == undefined) ? "" : " | "+require('locale').temp(Math.round(data.temp-273.15)).replace(".0", "")), px(2), py(87));
if (data.showWidgets) {
Bangle.drawWidgets();
}
}
var i = 0;
@ -367,3 +371,8 @@ queueDraw();
readWeather();
setWeather();
Bangle.setUI("clock");
if (data.showWidgets) {
Bangle.loadWidgets();
Bangle.drawWidgets();
}

View File

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

28
apps/mtnclock/settings.js Normal file
View File

@ -0,0 +1,28 @@
(function(back) {
var STORAGE = require('Storage')
var FILE = "mtnclock.json";
// Load settings
var SETTINGS = Object.assign({
// default values
showWidgets: false,
}, STORAGE.readJSON(FILE, true) || {});
function writeSettings() {
STORAGE.writeJSON(FILE, SETTINGS);
}
// Show the menu
E.showMenu({
"" : { "title" : "Mountain Clock" },
"< Back" : () => back(),
'Show widgets': {
value: !!SETTINGS.showWidgets, // !! converts undefined to false
onchange: value => {
SETTINGS.showWidgets = value;
writeSettings();
}
},
});
})