From cccce9318e1191b880ffb0b04332159d0b48819f Mon Sep 17 00:00:00 2001 From: Gordon Williams Date: Wed, 10 May 2023 10:29:00 +0100 Subject: [PATCH] Show the current date as a widget in tha Patriot clock --- apps/patriotclk/ChangeLog | 1 + apps/patriotclk/app.js | 30 ++++++++++++++++++++++++------ apps/patriotclk/metadata.json | 4 ++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/patriotclk/ChangeLog b/apps/patriotclk/ChangeLog index 5560f00bc..c9f08fcc2 100644 --- a/apps/patriotclk/ChangeLog +++ b/apps/patriotclk/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: Show the date inside the widget bar \ No newline at end of file diff --git a/apps/patriotclk/app.js b/apps/patriotclk/app.js index 4c3ed2d0f..e618b0106 100644 --- a/apps/patriotclk/app.js +++ b/apps/patriotclk/app.js @@ -14,7 +14,7 @@ Graphics.prototype.setFontAudiowide = function() { let options = require("Storage").readJSON("patriotclk.opts",1)||{}; // timeout used to update every minute - let drawTimeout; + let drawTimeout, widgetTimeout; // draw everything let draw = function() { @@ -55,17 +55,35 @@ Graphics.prototype.setFontAudiowide = function() { }, 60000 - (Date.now() % 60000)); }; - // Clear the screen once, at startup - g.clear(); - // draw immediately at first, queue update - draw(); // Show launcher when middle button pressed Bangle.setUI({mode:"clock", remove:function() { //f ree memory if (drawTimeout) clearTimeout(drawTimeout); + if (widgetTimeout) clearTimeout(widgetTimeout); + require("widget_utils").show(); + var e = WIDGETS["patriot"]; + g.reset().clearRect(e.x,e.y,e.x+63,e.y+23); + delete WIDGETS["patriot"]; delete Graphics.prototype.setFontAudiowide; - require("widget_utils").cleanup(); }}); // Load widgets (make them swipeable) Bangle.loadWidgets(); + WIDGETS["patriot"] = { + area:"tl", + width: 64, // how wide is the widget? You can change this and call Bangle.drawWidgets() to re-layout + draw : function(e) { + g.reset().clearRect(e.x,e.y,e.x+63,e.y+23); + var d = new Date(); + g.setFont("6x8").setFontAlign(-1,0).drawString(require("locale").dow(d,0), e.x+2, e.y+8); + g.setFont("6x8").setFontAlign(-1,0).drawString(require("locale").date(d).trim(), e.x+2, e.y+16); + widgetTimeout = setTimeout(function() { // redraw every hour (it's just easier that working out timezones) + widgetTimeout = undefined; + WIDGETS["patriot"].draw(WIDGETS["patriot"]); + }, 3600000 - (Date.now() % 3600000)); + } + }; require("widget_utils").swipeOn(); + // Clear the screen once, at startup + g.clear(); + // draw immediately at first, queue update + draw(); } \ No newline at end of file diff --git a/apps/patriotclk/metadata.json b/apps/patriotclk/metadata.json index 7c8752000..689f1422d 100644 --- a/apps/patriotclk/metadata.json +++ b/apps/patriotclk/metadata.json @@ -1,8 +1,8 @@ { "id": "patriotclk", "name": "Patriotic Clock", "shortName":"Patriot", - "version":"0.01", - "description": "Show your Patriotism with your Country's flag as a clock face (configurable)", + "version":"0.02", + "description": "Show your Patriotism with your Country's flag as a clock face (configurable). Swipe down to show widgets and date.", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], "type": "clock",