From c3b1a973c0bcef1ac7130e1b0df89dd3b1003703 Mon Sep 17 00:00:00 2001 From: Hank Date: Sun, 12 Jun 2022 22:44:32 +0200 Subject: [PATCH] Add theme support --- apps/hworldclock/ChangeLog | 3 ++- apps/hworldclock/app.js | 45 ++++++++++------------------------ apps/hworldclock/metadata.json | 2 +- 3 files changed, 16 insertions(+), 34 deletions(-) diff --git a/apps/hworldclock/ChangeLog b/apps/hworldclock/ChangeLog index fdc717c92..c7b1731a2 100644 --- a/apps/hworldclock/ChangeLog +++ b/apps/hworldclock/ChangeLog @@ -2,4 +2,5 @@ 0.16: Fix timing 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 \ No newline at end of file +0.19: Fix PM Hours +0.20: Add theme support \ No newline at end of file diff --git a/apps/hworldclock/app.js b/apps/hworldclock/app.js index e907dd703..faf24e974 100644 --- a/apps/hworldclock/app.js +++ b/apps/hworldclock/app.js @@ -82,7 +82,7 @@ var drawTimeout; var drawTimeoutSeconds; var secondsTimeout; -g.setBgColor(0, 0, 0); +g.setBgColor(g.theme.bg); // schedule a draw for the next minute function queueDraw() { @@ -128,7 +128,7 @@ function drawSeconds() { // default draw styles g.reset(); - g.setBgColor(0, 0, 0); + g.setBgColor(g.theme.bg); // drawSting centered g.setFontAlign(0, 0); @@ -138,7 +138,11 @@ function drawSeconds() { var seconds = time[2]; g.setFont("5x9Numeric7Seg",primaryTimeFontSize - 3); - g.setColor("#22ff05"); + if (g.theme.dark) { + g.setColor("#22ff05"); + } 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 @@ -155,7 +159,7 @@ function draw() { // default draw styles g.reset(); - g.setBgColor(0, 0, 0); + g.setBgColor(g.theme.bg); // drawSting centered g.setFontAlign(0, 0); @@ -179,7 +183,11 @@ function draw() { //g.setFont(font, primaryTimeFontSize); g.setFont("5x9Numeric7Seg",primaryTimeFontSize); - g.setColor("#22ff05"); + if (g.theme.dark) { + g.setColor("#22ff05"); + } else { + g.setColor(g.theme.fg); + } g.drawString(`${hours}:${minutes}`, xyCenter-10, yposTime, true); // am / PM ? @@ -187,7 +195,6 @@ function draw() { //do 12 hour stuff //var ampm = require("locale").medidian(new Date()); Not working g.setFont("Vector", 17); - g.setColor("#22ff05"); g.drawString(ampm, xyCenterSeconds, yAmPm, true); } @@ -287,33 +294,7 @@ if (!Bangle.isLocked()) { // Initial state } -// Stop updates when LCD is off, restart when on -Bangle.on('lcdPower',on=>{ - if (on) { - if (PosInterval != 0) clearInterval(PosInterval); - - PosInterval = setInterval(updatePos, 60*10E3); // refesh every 10 mins - secondsTimeout = 1000; - if (drawTimeout) clearTimeout(drawTimeout); - if (drawTimeoutSeconds) clearTimeout(drawTimeoutSeconds); - drawTimeout = undefined; - drawTimeoutSeconds = undefined; - draw(); // draw immediately, queue redraw - updatePos(); - } else { // stop draw timer - secondsTimeout = 1000 * 60; - 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(); - } -}); Bangle.on('lock',on=>{ diff --git a/apps/hworldclock/metadata.json b/apps/hworldclock/metadata.json index 1ee04b333..5cc2a49a8 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.19", + "version": "0.20", "description": "Current time zone plus up to three others", "allow_emulator":true, "icon": "app.png",