Minimal battery: Optimizations

pull/2030/head
Leon Matthes 2022-07-07 13:08:39 +02:00
parent 2a1eb5ade2
commit f781f34200
1 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
(function(){
(()=>{
function getWidth() {
return E.getBattery() <= 30 ? 40 : 0;
}
@ -8,20 +8,22 @@
var bat = E.getBattery();
var x = this.x, y = this.y;
g.reset();
g.clearRect(x,y,x+s,y+24);
g.setColor(g.theme.fg).fillRect(x,y+2,x+s-4,y+21).clearRect(x+2,y+4,x+s-6,y+19).fillRect(x+s-3,y+10,x+s,y+14);
var barWidth = bat*(s-12)/100;
var color = bat < 15 ? "#f00" : "#f80";
g.setColor(color).fillRect(x+4,y+6,x+4+barWidth,y+17);
},updateWidth: function() {
},update: function() {
var newWidth = getWidth();
if(newWidth != this.width) {
this.width = newWidth;
Bangle.drawWidgets();
Bangle.drawWidgets();//relayout
}else{
this.draw();
}
}};
setInterval(()=>{
var widget = WIDGETS.minbat;
if(widget) {widget.updateWidth();}
if(widget) {widget.update();}
}, 10*60*1000);
})();