diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index c7b1731a2..72b25a7c6 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -3,4 +3,5 @@ 0.17: Fix hours 0.18: Code cleanup and major changes with seconds timing. New feature: if watch is locked, seconds get refreshed every 10 seconds. 0.19: Fix PM Hours -0.20: Add theme support \ No newline at end of file +0.20: Add theme support +0.21: Add Settings \ No newline at end of file diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index faf24e974..d4c677d26 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -1,3 +1,10 @@ +// ------- Settings file +const SETTINGSFILE = "hworldclock.json"; +var secondsMode; +var showSunInfo; +var colorWhenDark; +// ------- Settings file + const big = g.getWidth()>200; // Font for primary time and date const primaryTimeFontSize = big?6:5; @@ -66,6 +73,11 @@ const mockOffsets = { ], };*/ + +// Example hworldclock.settings.json +// [["London","0"],["NY","-5"],["Denver","-6"]] + + // Uncomment one at a time to test various offsets array scenarios //offsets = mockOffsets.zeroOffsets; // should render nothing below primary time //offsets = mockOffsets.oneOffset; // should render larger in two rows @@ -73,6 +85,19 @@ const mockOffsets = { //offsets = mockOffsets.fourOffsets; // should render in columns // END TESTING CODE + + +// Load settings +function loadMySettings() { + // Helper function default setting + function def (value, def) {return value !== undefined ? value : def;} + + var settings = require('Storage').readJSON(SETTINGSFILE, true) || {}; + secondsMode = def(settings.secondsMode, "when unlocked"); + showSunInfo = def(settings.showSunInfo, true); + colorWhenDark = def(settings.colorWhenDark, "green"); +} + // Check settings for what type our clock should be var _12hour = (require("Storage").readJSON("setting.json",1)||{})["12hour"]||false; @@ -139,13 +164,17 @@ function drawSeconds() { g.setFont("5x9Numeric7Seg",primaryTimeFontSize - 3); if (g.theme.dark) { - g.setColor("#22ff05"); + if (colorWhenDark == "green") { + g.setColor("#22ff05"); + } else { + g.setColor(g.theme.fg); + } } else { g.setColor(g.theme.fg); } //console.log("---"); //console.log(seconds); - if (Bangle.isLocked()) seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x + if (Bangle.isLocked() && secondsMode != "always") seconds = seconds.slice(0, -1) + ':::'; // we use :: as the font does not have an x //console.log(seconds); g.drawString(`${seconds}`, xyCenterSeconds, yposTime+14, true); queueDrawSeconds(); @@ -184,7 +213,11 @@ function draw() { //g.setFont(font, primaryTimeFontSize); g.setFont("5x9Numeric7Seg",primaryTimeFontSize); if (g.theme.dark) { - g.setColor("#22ff05"); + if (colorWhenDark == "green") { + g.setColor("#22ff05"); + } else { + g.setColor(g.theme.fg); + } } else { g.setColor(g.theme.fg); } @@ -198,7 +231,7 @@ function draw() { g.drawString(ampm, xyCenterSeconds, yAmPm, true); } - drawSeconds(); // To make sure... + if (secondsMode != "none") drawSeconds(); // To make sure... // draw Day, name of month, Date //DATE @@ -245,19 +278,31 @@ function draw() { } }); - g.setFontAlign(-1, 0); - g.setFont("Vector",12); - g.drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset - g.setFontAlign(1, 0); - g.drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + if (showSunInfo) { + g.setFontAlign(-1, 0); + g.setFont("Vector",12); + g.drawString(`^${rise}`, 10, 3 + yposWorld + 3 * 15, true); // draw riseset + g.setFontAlign(1, 0); + g.drawString(`v${set}`, xcol2, 3 + yposWorld + 3 * 15, true); // draw riseset + } + //debug settings + //g.setFontAlign(1, 0); + //g.drawString(secondsMode, xcol2, 3 + yposWorld + 3 * 15, true); + //g.drawString(showSunInfo, xcol2, 3 + yposWorld + 3 * 15, true); + //g.drawString(colorWhenDark, xcol2, 3 + yposWorld + 3 * 15, true); + queueDraw(); - queueDrawSeconds(); + + if (secondsMode != "none") queueDrawSeconds(); } // clean app screen g.clear(); +// Init the settings of the app +loadMySettings(); + // Show launcher when button pressed Bangle.setUI("clock"); Bangle.loadWidgets(); @@ -269,28 +314,38 @@ draw(); if (!Bangle.isLocked()) { // Initial state - if (PosInterval != 0) clearInterval(PosInterval); - PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + if (showSunInfo) { + if (PosInterval != 0) clearInterval(PosInterval); + PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + } - secondsTimeout = 1000; + secondsTimeout = 1000; + if (secondsMode != "none") { + if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); + drawTimeoutSeconds = undefined; + } if (drawTimeout) clearTimeout(drawTimeout); - if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); drawTimeout = undefined; - drawTimeoutSeconds = undefined; draw(); // draw immediately, queue redraw - updatePos(); + if (showSunInfo) updatePos(); }else{ - secondsTimeout = 10 * 1000; + if (secondsMode == "always") secondsTimeout = 1000; + if (secondsMode == "when unlocked") secondsTimeout = 10 * 1000; + + if (secondsMode != "none") { + if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); + drawTimeoutSeconds = undefined; + } if (drawTimeout) clearTimeout(drawTimeout); - if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); drawTimeout = undefined; - drawTimeoutSeconds = undefined; - if (PosInterval != 0) clearInterval(PosInterval); - PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + if (showSunInfo) { + if (PosInterval != 0) clearInterval(PosInterval); + PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins + } draw(); // draw immediately, queue redraw - updatePos(); + if (showSunInfo) updatePos(); } @@ -299,29 +354,36 @@ if (!Bangle.isLocked()) { // Initial state Bangle.on('lock',on=>{ if (!on) { // UNlocked - - if (PosInterval != 0) clearInterval(PosInterval); - PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + if (showSunInfo) { + if (PosInterval != 0) clearInterval(PosInterval); + PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins + } secondsTimeout = 1000; + if (secondsMode != "none") { + if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); + drawTimeoutSeconds = undefined; + } if (drawTimeout) clearTimeout(drawTimeout); - if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); drawTimeout = undefined; - drawTimeoutSeconds = undefined; draw(); // draw immediately, queue redraw - updatePos(); + if (showSunInfo) updatePos(); }else{ // locked - secondsTimeout = 10 * 1000; + if (secondsMode == "always") secondsTimeout = 1000; + if (secondsMode == "when unlocked") secondsTimeout = 10 * 1000; + + if (secondsMode != "none") { + if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); + drawTimeoutSeconds = undefined; + } if (drawTimeout) clearTimeout(drawTimeout); - if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); drawTimeout = undefined; - drawTimeoutSeconds = undefined; if (PosInterval != 0) clearInterval(PosInterval); PosInterval = setInterval(updatePos, 60*60E3); // refesh every 60 mins draw(); // draw immediately, queue redraw - updatePos(); + if (showSunInfo) updatePos(); } }); \ No newline at end of file diff --git a/apps/hworldclock/metadata.json b/apps/hworldclock/metadata.json index 5cc2a49a8..f41d56932 100644 --- a/apps/hworldclock/metadata.json +++ b/apps/hworldclock/metadata.json @@ -2,7 +2,7 @@ "id": "hworldclock", "name": "Hanks World Clock", "shortName": "Hanks World Clock", - "version": "0.20", + "version": "0.21", "description": "Current time zone plus up to three others", "allow_emulator":true, "icon": "app.png", @@ -15,7 +15,11 @@ "storage": [ {"name":"hworldclock.app.js","url":"app.js"}, {"name":"hworldclock.img","url":"hworldclock-icon.js","evaluate":true}, + {"name":"hworldclock.settings.js","url":"settings.js"}, {"name":"hsuncalc.js","url":"hsuncalc.js"} ], - "data": [{"name":"hworldclock.settings.json"}] + "data": [ + {"name":"hworldclock.settings.json"}, + {"name":"hworldclock.json"}, + ] } diff --git a/apps/hworldclock/settings.js b/apps/hworldclock/settings.js new file mode 100644 index 000000000..60092d21e --- /dev/null +++ b/apps/hworldclock/settings.js @@ -0,0 +1,59 @@ +// Settings menu for the enhanced Anton clock + +(function(back) { + var FILE = "hworldclock.json"; + // Load settings + var settings = Object.assign({ + secondsOnUnlock: false, + }, require('Storage').readJSON(FILE, true) || {}); + + function writeSettings() { + require('Storage').writeJSON(FILE, settings); + } + + // Helper method which uses int-based menu item for set of string values + function stringItems(startvalue, writer, values) { + return { + value: (startvalue === undefined ? 0 : values.indexOf(startvalue)), + format: v => values[v], + min: 0, + max: values.length - 1, + wrap: true, + step: 1, + onchange: v => { + writer(values[v]); + writeSettings(); + } + }; + } + + // Helper method which breaks string set settings down to local settings object + function stringInSettings(name, values) { + return stringItems(settings[name], v => settings[name] = v, values); + } + + var mainmenu = { + "": { + "title": "Hanks World Clock" + }, + "< Back": () => back(), + "Seconds": stringInSettings("secondsMode", ["always", "when unlocked", "none"]), + "Color w. dark": stringInSettings("colorWhenDark", ["green", "default"]), + "Show SunInfo": { + value: (settings.showSunInfo !== undefined ? settings.showSunInfo : true), + format: v => v ? "On" : "Off", + onchange: v => { + settings.showSunInfo = v; + writeSettings(); + } + } + }; + + + + // Actually display the menu + E.showMenu(mainmenu); + +}); + +// end of file