Add Minimal Battery widget

pull/2030/head
Leon Matthes 2022-07-07 11:54:41 +02:00
parent 789e3a7ec5
commit e097da43dd
4 changed files with 41 additions and 0 deletions

1
apps/widminbat/ChangeLog Normal file
View File

@ -0,0 +1 @@
0.01: Initial Version: Display at under 30% battery

View File

@ -0,0 +1,13 @@
{ "id": "widminbat",
"name": "Minimal Battery",
"shortName":"MinBat",
"version":"0.01",
"description": "A minimal version of the battery widget that only appears if the battery is running low (below 30%)",
"icon": "widget.png",
"type": "widget",
"tags": "widget,battery,minimal",
"supports" : ["BANGLEJS2", "BANGLEJS"],
"storage": [
{"name":"widminbat.wid.js","url":"widget.js"}
]
}

27
apps/widminbat/widget.js Normal file
View File

@ -0,0 +1,27 @@
(function(){
function getWidth() {
return E.getBattery() <= 30 ? 40 : 0;
}
WIDGETS.minbat={area:"tr",width:getWidth(),draw:function() {
if(this.width < 40) return;
var s = 39;
var bat = E.getBattery();
var x = this.x, y = this.y;
g.reset();
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() {
var newWidth = getWidth();
if(newWidth != this.width) {
this.width = newWidth;
Bangle.drawWidgets();
}
}};
setInterval(()=>{
var widget = WIDGETS.minbat;
if(widget) {widget.updateWidth();}
}, 10*60*1000);
})();

BIN
apps/widminbat/widget.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 777 B