From ceeac6cbb314f5463f45ebe23a757c8b70201050 Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 30 Jul 2025 20:39:56 -0500 Subject: [PATCH 1/3] [widalarmeta] Add option to only show when on clock --- apps/widalarmeta/ChangeLog | 1 + apps/widalarmeta/metadata.json | 2 +- apps/widalarmeta/settings.js | 10 +++++ apps/widalarmeta/widget.js | 81 ++++++++++++++++++---------------- 4 files changed, 55 insertions(+), 39 deletions(-) diff --git a/apps/widalarmeta/ChangeLog b/apps/widalarmeta/ChangeLog index cf82dfe437..2cac2f8875 100644 --- a/apps/widalarmeta/ChangeLog +++ b/apps/widalarmeta/ChangeLog @@ -14,3 +14,4 @@ 0.10: Change 4x5 font to 6x8, teletext is now default font 0.11: Bugfix: handle changes in alarms (e.g. done without a load, such as via fastload) 0.12: Redraw when screen turns on or watch is unlocked +0.13: Add option to only show when on clock diff --git a/apps/widalarmeta/metadata.json b/apps/widalarmeta/metadata.json index 8ffe4ea623..f9e58acdf1 100644 --- a/apps/widalarmeta/metadata.json +++ b/apps/widalarmeta/metadata.json @@ -2,7 +2,7 @@ "id": "widalarmeta", "name": "Alarm & Timer ETA", "shortName": "Alarm ETA", - "version": "0.12", + "version": "0.13", "description": "A widget that displays the time to the next Alarm or Timer in hours and minutes, maximum 24h (configurable).", "icon": "widget.png", "type": "widget", diff --git a/apps/widalarmeta/settings.js b/apps/widalarmeta/settings.js index 5e83c6f3ab..93b92a0d2c 100644 --- a/apps/widalarmeta/settings.js +++ b/apps/widalarmeta/settings.js @@ -7,6 +7,7 @@ padHours: true, showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2 + whenToShow: 0, // 0=always, 1=on clock only }, require("Storage").readJSON(CONFIGFILE,1) || {}); function writeSettings() { @@ -59,5 +60,14 @@ writeSettings(); } }, + /*LANG*/'When To Show': { + value: settings.whenToShow, + min: 0, max: 1, + format: v => [/*LANG*/"Always", /*LANG*/"On Clock Only"][v === undefined ? 0 : v], + onchange: v => { + settings.whenToShow = v; + writeSettings(); + } + }, }); }) diff --git a/apps/widalarmeta/widget.js b/apps/widalarmeta/widget.js index ffe95db1ba..4f80d09cbd 100644 --- a/apps/widalarmeta/widget.js +++ b/apps/widalarmeta/widget.js @@ -8,6 +8,7 @@ padHours: true, showSeconds: 0, // 0=never, 1=only when display is unlocked, 2=for less than a minute font: 1, // 0=segment style font, 1=teletext font, 2=6x8:1x2 + whenToShow: 0, // 0=always, 1=on clock only }, require("Storage").readJSON("widalarmeta.json",1) || {}); if (config.font == 0) { @@ -55,44 +56,48 @@ let calcWidth = 0; let drawSeconds = false; - if (next > 0 && next <= config.maxhours*60*60*1000) { - const hours = Math.floor((next-1) / 3600000).toString(); - const minutes = Math.floor(((next-1) % 3600000) / 60000).toString(); - const seconds = Math.floor(((next-1) % 60000) / 1000).toString(); - drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60); - - g.reset(); // reset the graphics context to defaults (color/font/etc) - g.setFontAlign(-1,0); // center font in y direction - g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); - - var text = ""; - if (config.padHours) { - text += hours.padStart(2, '0'); - } else { - text += hours; - } - text += ":" + minutes.padStart(2, '0'); - if (drawSeconds) { - text += ":" + seconds.padStart(2, '0'); - } - if (config.font == 0) { - g.setFont("5x9Numeric7Seg:1x2"); - } else if (config.font == 1) { - g.setFont("Teletext5x9Ascii:1x2"); - } else { - // Default to this if no other font is set. - g.setFont("6x8:1x2"); - } - g.drawString(text, this.x+1, this.y+12); - - calcWidth = g.stringWidth(text) + 2; // One pixel on each side - this.bellVisible = false; - } else if (config.drawBell && this.numActiveAlarms > 0) { - calcWidth = 24; - // next alarm too far in future, draw only widalarm bell - if (this.bellVisible !== true || fromInterval !== true) { - g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); - this.bellVisible = true; + // If always showing, or the clock is visible + if (config.whenToShow === 0 || Bangle.CLOCK) { + // Determine text and width + if (next > 0 && next <= config.maxhours*60*60*1000) { + const hours = Math.floor((next-1) / 3600000).toString(); + const minutes = Math.floor(((next-1) % 3600000) / 60000).toString(); + const seconds = Math.floor(((next-1) % 60000) / 1000).toString(); + drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60); + + g.reset(); // reset the graphics context to defaults (color/font/etc) + g.setFontAlign(-1,0); // center font in y direction + g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); + + var text = ""; + if (config.padHours) { + text += hours.padStart(2, '0'); + } else { + text += hours; + } + text += ":" + minutes.padStart(2, '0'); + if (drawSeconds) { + text += ":" + seconds.padStart(2, '0'); + } + if (config.font == 0) { + g.setFont("5x9Numeric7Seg:1x2"); + } else if (config.font == 1) { + g.setFont("Teletext5x9Ascii:1x2"); + } else { + // Default to this if no other font is set. + g.setFont("6x8:1x2"); + } + g.drawString(text, this.x+1, this.y+12); + + calcWidth = g.stringWidth(text) + 2; // One pixel on each side + this.bellVisible = false; + } else if (config.drawBell && this.numActiveAlarms > 0) { + calcWidth = 24; + // next alarm too far in future, draw only widalarm bell + if (this.bellVisible !== true || fromInterval !== true) { + g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); + this.bellVisible = true; + } } } From d31c6ca12a5af4e7907762617e53e4d3e6a66dcf Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 6 Aug 2025 10:18:38 -0500 Subject: [PATCH 2/3] [widalarmeta] tweak to if statement Co-authored-by: Rob Pilling --- apps/widalarmeta/widget.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/widalarmeta/widget.js b/apps/widalarmeta/widget.js index 4f80d09cbd..fc8da6d6a5 100644 --- a/apps/widalarmeta/widget.js +++ b/apps/widalarmeta/widget.js @@ -57,7 +57,8 @@ let drawSeconds = false; // If always showing, or the clock is visible - if (config.whenToShow === 0 || Bangle.CLOCK) { + if (config.whenToShow === 1 && !Bangle.CLOCK) + return; // Determine text and width if (next > 0 && next <= config.maxhours*60*60*1000) { const hours = Math.floor((next-1) / 3600000).toString(); From 7fc876237d30ee78c3fdd414ca6a7f59e25ebea3 Mon Sep 17 00:00:00 2001 From: Logan B <3870583+thinkpoop@users.noreply.github.com> Date: Wed, 30 Jul 2025 20:39:56 -0500 Subject: [PATCH 3/3] [widalarmeta] move "Only on clock" check to top of draw --- apps/widalarmeta/widget.js | 89 ++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 43 deletions(-) diff --git a/apps/widalarmeta/widget.js b/apps/widalarmeta/widget.js index fc8da6d6a5..21097add85 100644 --- a/apps/widalarmeta/widget.js +++ b/apps/widalarmeta/widget.js @@ -39,6 +39,13 @@ } // getNextAlarm function draw(_w, fromInterval) { + + // If only show on clock and not on clock + if (config.whenToShow === 1 && !Bangle.CLOCK) { + this.nextAlarm = undefined; // make sure to reload later + return; + } + if (this.nextAlarm === undefined) { let alarm = getNextAlarm(); if (alarm === undefined) { @@ -56,49 +63,45 @@ let calcWidth = 0; let drawSeconds = false; - // If always showing, or the clock is visible - if (config.whenToShow === 1 && !Bangle.CLOCK) - return; - // Determine text and width - if (next > 0 && next <= config.maxhours*60*60*1000) { - const hours = Math.floor((next-1) / 3600000).toString(); - const minutes = Math.floor(((next-1) % 3600000) / 60000).toString(); - const seconds = Math.floor(((next-1) % 60000) / 1000).toString(); - drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60); - - g.reset(); // reset the graphics context to defaults (color/font/etc) - g.setFontAlign(-1,0); // center font in y direction - g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); - - var text = ""; - if (config.padHours) { - text += hours.padStart(2, '0'); - } else { - text += hours; - } - text += ":" + minutes.padStart(2, '0'); - if (drawSeconds) { - text += ":" + seconds.padStart(2, '0'); - } - if (config.font == 0) { - g.setFont("5x9Numeric7Seg:1x2"); - } else if (config.font == 1) { - g.setFont("Teletext5x9Ascii:1x2"); - } else { - // Default to this if no other font is set. - g.setFont("6x8:1x2"); - } - g.drawString(text, this.x+1, this.y+12); - - calcWidth = g.stringWidth(text) + 2; // One pixel on each side - this.bellVisible = false; - } else if (config.drawBell && this.numActiveAlarms > 0) { - calcWidth = 24; - // next alarm too far in future, draw only widalarm bell - if (this.bellVisible !== true || fromInterval !== true) { - g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); - this.bellVisible = true; - } + // Determine text and width + if (next > 0 && next <= config.maxhours*60*60*1000) { + const hours = Math.floor((next-1) / 3600000).toString(); + const minutes = Math.floor(((next-1) % 3600000) / 60000).toString(); + const seconds = Math.floor(((next-1) % 60000) / 1000).toString(); + drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60); + + g.reset(); // reset the graphics context to defaults (color/font/etc) + g.setFontAlign(-1,0); // center font in y direction + g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23); + + var text = ""; + if (config.padHours) { + text += hours.padStart(2, '0'); + } else { + text += hours; + } + text += ":" + minutes.padStart(2, '0'); + if (drawSeconds) { + text += ":" + seconds.padStart(2, '0'); + } + if (config.font == 0) { + g.setFont("5x9Numeric7Seg:1x2"); + } else if (config.font == 1) { + g.setFont("Teletext5x9Ascii:1x2"); + } else { + // Default to this if no other font is set. + g.setFont("6x8:1x2"); + } + g.drawString(text, this.x+1, this.y+12); + + calcWidth = g.stringWidth(text) + 2; // One pixel on each side + this.bellVisible = false; + } else if (config.drawBell && this.numActiveAlarms > 0) { + calcWidth = 24; + // next alarm too far in future, draw only widalarm bell + if (this.bellVisible !== true || fromInterval !== true) { + g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y); + this.bellVisible = true; } }