mirror of https://github.com/espruino/BangleApps
Add Minimal Battery widget
parent
789e3a7ec5
commit
e097da43dd
|
@ -0,0 +1 @@
|
|||
0.01: Initial Version: Display at under 30% battery
|
|
@ -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"}
|
||||
]
|
||||
}
|
|
@ -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);
|
||||
})();
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 777 B |
Loading…
Reference in New Issue