From dc3ba06e9e1d8545b36c3cb78a18115b5f676544 Mon Sep 17 00:00:00 2001 From: Hugh Barney Date: Sat, 11 Nov 2023 18:21:45 +0000 Subject: [PATCH 1/3] clkinfocal added settings menu for different date formats --- apps/clkinfocal/ChangeLog | 1 + apps/clkinfocal/clkinfo.js | 18 ++++++++++++++++- apps/clkinfocal/metadata.json | 9 ++++++--- apps/clkinfocal/settings.js | 37 +++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 apps/clkinfocal/settings.js diff --git a/apps/clkinfocal/ChangeLog b/apps/clkinfocal/ChangeLog index 5560f00bc..815c197c4 100644 --- a/apps/clkinfocal/ChangeLog +++ b/apps/clkinfocal/ChangeLog @@ -1 +1,2 @@ 0.01: New App! +0.02: added settings options to change date format diff --git a/apps/clkinfocal/clkinfo.js b/apps/clkinfocal/clkinfo.js index a7949cda4..d40e7360d 100644 --- a/apps/clkinfocal/clkinfo.js +++ b/apps/clkinfocal/clkinfo.js @@ -1,5 +1,21 @@ (function() { require("Font4x8Numeric").add(Graphics); + + var settings = require("Storage").readJSON("clkinfocal.json",1)||{}; + settings.fmt = settings.fmt||0; + + var getDateString = function(dt) { + var fmt = 1; // get from settings + switch(settings.fmt) { + case 2: // dd MMM + return '' + dt.getDate() + ' ' + require("locale").month(dt,1).toUpperCase(); + case 1: // DDD dd + return require("locale").dow(dt,1).toUpperCase() + ' ' + dt.getDate(); + default: // DDD + return require("locale").dow(dt,1).toUpperCase(); + } + }; + return { name: "Bangle", items: [ @@ -10,7 +26,7 @@ g.drawImage(atob("FhgBDADAMAMP/////////////////////8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAPAAA8AADwAAP///////"),1,0); g.setFont("6x15").setFontAlign(0,0).drawString(d.getDate(),11,17); return { - text : require("locale").dow(d,1).toUpperCase(), + text : getDateString(d), img : g.asImage("string") }; }, diff --git a/apps/clkinfocal/metadata.json b/apps/clkinfocal/metadata.json index 1d14c3b59..cfa0f8b65 100644 --- a/apps/clkinfocal/metadata.json +++ b/apps/clkinfocal/metadata.json @@ -1,6 +1,6 @@ { "id": "clkinfocal", "name": "Calendar Clockinfo", - "version":"0.01", + "version":"0.02", "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], @@ -8,6 +8,9 @@ "tags": "clkinfo,calendar", "supports" : ["BANGLEJS2"], "storage": [ - {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"} - ] + {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"}, + {"name":"clkinfocal.settings.js","url":"settings.js"} + + ], + "data": [{"name":"clkinfocal.json"}] } diff --git a/apps/clkinfocal/settings.js b/apps/clkinfocal/settings.js new file mode 100644 index 000000000..6fe8f2817 --- /dev/null +++ b/apps/clkinfocal/settings.js @@ -0,0 +1,37 @@ +(function(back) { + const SETTINGS_FILE = "clkinfocal.json"; + + // initialize with default settings... + let s = {'fmt': 0}; + + // and overwrite them with any saved values + // this way saved values are preserved if a new version adds more settings + const storage = require('Storage'); + let settings = storage.readJSON(SETTINGS_FILE, 1) || {}; + const saved = settings || {}; + for (const key in saved) { + s[key] = saved[key]; + } + + function save() { + settings = s; + storage.write(SETTINGS_FILE, settings); + } + + var date_options = ["DDD","DDD dd","dd MMM"]; + + E.showMenu({ + '': { 'title': 'Cal Clkinfo' }, + '< Back': back, + 'Format': { + value: 0 | date_options.indexOf(s.fmt), + min: 0, max: 2, + format: v => date_options[v], + onchange: v => { + s.fmt = date_options[v]; + save(); + }, + } + }); + +}); From 1f7f4fdbf140a4a0c33a95e500a822e034f7fb6f Mon Sep 17 00:00:00 2001 From: Hugh Barney Date: Sat, 11 Nov 2023 18:42:08 +0000 Subject: [PATCH 2/3] clkinfocal switch on the string of the date format --- apps/clkinfocal/clkinfo.js | 7 +++---- apps/clkinfocal/metadata.json | 1 - 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/apps/clkinfocal/clkinfo.js b/apps/clkinfocal/clkinfo.js index d40e7360d..d4e7b0efc 100644 --- a/apps/clkinfocal/clkinfo.js +++ b/apps/clkinfocal/clkinfo.js @@ -2,14 +2,13 @@ require("Font4x8Numeric").add(Graphics); var settings = require("Storage").readJSON("clkinfocal.json",1)||{}; - settings.fmt = settings.fmt||0; + settings.fmt = settings.fmt||"DDD"; var getDateString = function(dt) { - var fmt = 1; // get from settings switch(settings.fmt) { - case 2: // dd MMM + case "dd MMM": return '' + dt.getDate() + ' ' + require("locale").month(dt,1).toUpperCase(); - case 1: // DDD dd + case "DDD dd": return require("locale").dow(dt,1).toUpperCase() + ' ' + dt.getDate(); default: // DDD return require("locale").dow(dt,1).toUpperCase(); diff --git a/apps/clkinfocal/metadata.json b/apps/clkinfocal/metadata.json index cfa0f8b65..c8091db8c 100644 --- a/apps/clkinfocal/metadata.json +++ b/apps/clkinfocal/metadata.json @@ -10,7 +10,6 @@ "storage": [ {"name":"clkinfocal.clkinfo.js","url":"clkinfo.js"}, {"name":"clkinfocal.settings.js","url":"settings.js"} - ], "data": [{"name":"clkinfocal.json"}] } From cd1b1c643fceb2c335f9ad9d96c80d2824f45327 Mon Sep 17 00:00:00 2001 From: Hugh Barney Date: Sun, 12 Nov 2023 12:15:22 +0000 Subject: [PATCH 3/3] clkinfocal, updated description --- apps/clkinfocal/metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/clkinfocal/metadata.json b/apps/clkinfocal/metadata.json index c8091db8c..a4fcc85ee 100644 --- a/apps/clkinfocal/metadata.json +++ b/apps/clkinfocal/metadata.json @@ -1,7 +1,7 @@ { "id": "clkinfocal", "name": "Calendar Clockinfo", "version":"0.02", - "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday", + "description": "For clocks that display 'clockinfo' (messages that can be cycled through using the clock_info module) this displays the day of the month in the icon, and the weekday. There is also a settings menu to select the format of the text", "icon": "app.png", "screenshots": [{"url":"screenshot.png"}], "type": "clkinfo",