mirror of https://github.com/espruino/BangleApps
[Nifty-A Clock] Improve settings page
parent
89edc64922
commit
b6e9474bf4
|
@ -1,6 +1,6 @@
|
||||||
const locale = require("locale");
|
const locale = require("locale");
|
||||||
const is12Hour = (require("Storage").readJSON("setting.json", 1) || {})["12hour"];
|
const is12Hour = Object.assign({ "12hour": false }, require("Storage").readJSON("setting.json", true))["12hour"];
|
||||||
const CFG = require('Storage').readJSON("ffcniftya.json", 1) || {showWeekNum: true};
|
const showWeekNum = Object.assign({ showWeekNum: true }, require('Storage').readJSON("ffcniftya.json", true))["showWeekNum"];
|
||||||
|
|
||||||
/* Clock *********************************************/
|
/* Clock *********************************************/
|
||||||
const scale = g.getWidth() / 176;
|
const scale = g.getWidth() / 176;
|
||||||
|
@ -17,16 +17,17 @@ const center = {
|
||||||
y: Math.round(((viewport.height - widget) / 2) + widget),
|
y: Math.round(((viewport.height - widget) / 2) + widget),
|
||||||
}
|
}
|
||||||
|
|
||||||
function ISO8601_week_no(date) { //copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
// copied from: https://gist.github.com/IamSilviu/5899269#gistcomment-3035480
|
||||||
var tdt = new Date(date.valueOf());
|
function ISO8601_week_no(date) {
|
||||||
var dayn = (date.getDay() + 6) % 7;
|
var tdt = new Date(date.valueOf());
|
||||||
tdt.setDate(tdt.getDate() - dayn + 3);
|
var dayn = (date.getDay() + 6) % 7;
|
||||||
var firstThursday = tdt.valueOf();
|
tdt.setDate(tdt.getDate() - dayn + 3);
|
||||||
tdt.setMonth(0, 1);
|
var firstThursday = tdt.valueOf();
|
||||||
if (tdt.getDay() !== 4) {
|
tdt.setMonth(0, 1);
|
||||||
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
|
if (tdt.getDay() !== 4) {
|
||||||
}
|
tdt.setMonth(0, 1 + ((4 - tdt.getDay()) + 7) % 7);
|
||||||
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
|
}
|
||||||
|
return 1 + Math.ceil((firstThursday - tdt) / 604800000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function d02(value) {
|
function d02(value) {
|
||||||
|
@ -59,7 +60,7 @@ function draw() {
|
||||||
g.drawString(year, centerDatesScaleX, center.y - 62 * scale);
|
g.drawString(year, centerDatesScaleX, center.y - 62 * scale);
|
||||||
g.drawString(month, centerDatesScaleX, center.y - 44 * scale);
|
g.drawString(month, centerDatesScaleX, center.y - 44 * scale);
|
||||||
g.drawString(day, centerDatesScaleX, center.y - 26 * scale);
|
g.drawString(day, centerDatesScaleX, center.y - 26 * scale);
|
||||||
if (CFG.showWeekNum) g.drawString(d02(ISO8601_week_no(now)), centerDatesScaleX, center.y + 15 * scale);
|
if (showWeekNum) g.drawString(d02(ISO8601_week_no(now)), centerDatesScaleX, center.y + 15 * scale);
|
||||||
g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale);
|
g.drawString(monthName, centerDatesScaleX, center.y + 48 * scale);
|
||||||
g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale);
|
g.drawString(dayName, centerDatesScaleX, center.y + 66 * scale);
|
||||||
}
|
}
|
||||||
|
@ -79,7 +80,6 @@ function clearTickTimer() {
|
||||||
function queueNextTick() {
|
function queueNextTick() {
|
||||||
clearTickTimer();
|
clearTickTimer();
|
||||||
tickTimer = setTimeout(tick, 60000 - (Date.now() % 60000));
|
tickTimer = setTimeout(tick, 60000 - (Date.now() % 60000));
|
||||||
// tickTimer = setTimeout(tick, 3000);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tick() {
|
function tick() {
|
||||||
|
@ -91,15 +91,13 @@ function tick() {
|
||||||
|
|
||||||
// Clear the screen once, at startup
|
// Clear the screen once, at startup
|
||||||
g.clear();
|
g.clear();
|
||||||
// Start ticking
|
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
// Stop updates when LCD is off, restart when on
|
|
||||||
Bangle.on('lcdPower', (on) => {
|
Bangle.on('lcdPower', (on) => {
|
||||||
if (on) {
|
if (on) {
|
||||||
tick(); // Start ticking
|
tick();
|
||||||
} else {
|
} else {
|
||||||
clearTickTimer(); // stop ticking
|
clearTickTimer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,15 @@
|
||||||
(function(back) {
|
(function (back) {
|
||||||
var FILE = "ffcniftya.json";
|
const settings = Object.assign({ showWeekNum: true }, require("Storage").readJSON("ffcniftya.json", true));
|
||||||
// Load settings
|
|
||||||
var cfg = require('Storage').readJSON(FILE, 1) || { showWeekNum: true };
|
|
||||||
|
|
||||||
function writeSettings() {
|
|
||||||
require('Storage').writeJSON(FILE, cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show the menu
|
|
||||||
E.showMenu({
|
E.showMenu({
|
||||||
"" : { "title" : "Nifty-A Clock" },
|
"": { "title": "Nifty-A Clock" },
|
||||||
"< Back" : () => back(),
|
"< Back": () => back(),
|
||||||
'week number?': {
|
/*LANG*/"Show Week Number": {
|
||||||
value: cfg.showWeekNum,
|
value: settings.showWeekNum,
|
||||||
format: v => v?"On":"Off",
|
|
||||||
onchange: v => {
|
onchange: v => {
|
||||||
cfg.showWeekNum = v;
|
settings.showWeekNum = v;
|
||||||
writeSettings();
|
require("Storage").writeJSON("ffcniftya.json", settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue