Adding settings and the ability to show widgets

pull/3030/head
Ryan Taylor 2023-09-24 19:07:35 +00:00
parent e43abd2055
commit 1fb7c5c368
4 changed files with 38 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.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,11 @@ 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.loadWidgets();
Bangle.drawWidgets();
}
}
var i = 0;

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"}]

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

@ -0,0 +1,29 @@
(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
format: value => value ? "On" : "Off",
onchange: value => {
SETTINGS.showWidgets = value;
writeSettings();
}
},
});
})