Skip to content

Commit 7fc8762

Browse files
committed
[widalarmeta] move "Only on clock" check to top of draw
1 parent d31c6ca commit 7fc8762

File tree

1 file changed

+46
-43
lines changed

1 file changed

+46
-43
lines changed

apps/widalarmeta/widget.js

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
} // getNextAlarm
4040

4141
function draw(_w, fromInterval) {
42+
43+
// If only show on clock and not on clock
44+
if (config.whenToShow === 1 && !Bangle.CLOCK) {
45+
this.nextAlarm = undefined; // make sure to reload later
46+
return;
47+
}
48+
4249
if (this.nextAlarm === undefined) {
4350
let alarm = getNextAlarm();
4451
if (alarm === undefined) {
@@ -56,49 +63,45 @@
5663
let calcWidth = 0;
5764
let drawSeconds = false;
5865

59-
// If always showing, or the clock is visible
60-
if (config.whenToShow === 1 && !Bangle.CLOCK)
61-
return;
62-
// Determine text and width
63-
if (next > 0 && next <= config.maxhours*60*60*1000) {
64-
const hours = Math.floor((next-1) / 3600000).toString();
65-
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
66-
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
67-
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
68-
69-
g.reset(); // reset the graphics context to defaults (color/font/etc)
70-
g.setFontAlign(-1,0); // center font in y direction
71-
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
72-
73-
var text = "";
74-
if (config.padHours) {
75-
text += hours.padStart(2, '0');
76-
} else {
77-
text += hours;
78-
}
79-
text += ":" + minutes.padStart(2, '0');
80-
if (drawSeconds) {
81-
text += ":" + seconds.padStart(2, '0');
82-
}
83-
if (config.font == 0) {
84-
g.setFont("5x9Numeric7Seg:1x2");
85-
} else if (config.font == 1) {
86-
g.setFont("Teletext5x9Ascii:1x2");
87-
} else {
88-
// Default to this if no other font is set.
89-
g.setFont("6x8:1x2");
90-
}
91-
g.drawString(text, this.x+1, this.y+12);
92-
93-
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
94-
this.bellVisible = false;
95-
} else if (config.drawBell && this.numActiveAlarms > 0) {
96-
calcWidth = 24;
97-
// next alarm too far in future, draw only widalarm bell
98-
if (this.bellVisible !== true || fromInterval !== true) {
99-
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
100-
this.bellVisible = true;
101-
}
66+
// Determine text and width
67+
if (next > 0 && next <= config.maxhours*60*60*1000) {
68+
const hours = Math.floor((next-1) / 3600000).toString();
69+
const minutes = Math.floor(((next-1) % 3600000) / 60000).toString();
70+
const seconds = Math.floor(((next-1) % 60000) / 1000).toString();
71+
drawSeconds = (config.showSeconds & 0b01 && !Bangle.isLocked()) || (config.showSeconds & 0b10 && next <= 1000*60);
72+
73+
g.reset(); // reset the graphics context to defaults (color/font/etc)
74+
g.setFontAlign(-1,0); // center font in y direction
75+
g.clearRect(this.x, this.y, this.x+this.width-1, this.y+23);
76+
77+
var text = "";
78+
if (config.padHours) {
79+
text += hours.padStart(2, '0');
80+
} else {
81+
text += hours;
82+
}
83+
text += ":" + minutes.padStart(2, '0');
84+
if (drawSeconds) {
85+
text += ":" + seconds.padStart(2, '0');
86+
}
87+
if (config.font == 0) {
88+
g.setFont("5x9Numeric7Seg:1x2");
89+
} else if (config.font == 1) {
90+
g.setFont("Teletext5x9Ascii:1x2");
91+
} else {
92+
// Default to this if no other font is set.
93+
g.setFont("6x8:1x2");
94+
}
95+
g.drawString(text, this.x+1, this.y+12);
96+
97+
calcWidth = g.stringWidth(text) + 2; // One pixel on each side
98+
this.bellVisible = false;
99+
} else if (config.drawBell && this.numActiveAlarms > 0) {
100+
calcWidth = 24;
101+
// next alarm too far in future, draw only widalarm bell
102+
if (this.bellVisible !== true || fromInterval !== true) {
103+
g.reset().drawImage(atob("GBgBAAAAAAAAABgADhhwDDwwGP8YGf+YMf+MM//MM//MA//AA//AA//AA//AA//AA//AB//gD//wD//wAAAAADwAABgAAAAAAAAA"),this.x,this.y);
104+
this.bellVisible = true;
102105
}
103106
}
104107

0 commit comments

Comments
 (0)