diff --git a/apps/widminbate/ChangeLog b/apps/widminbate/ChangeLog new file mode 100644 index 000000000..d4143d802 --- /dev/null +++ b/apps/widminbate/ChangeLog @@ -0,0 +1,3 @@ +0.01: Initial Version: Display at under 30% battery +0.02: Display while charging +0.03: Do not clear outside of widget bar diff --git a/apps/widminbate/metadata.json b/apps/widminbate/metadata.json new file mode 100644 index 000000000..7aa200282 --- /dev/null +++ b/apps/widminbate/metadata.json @@ -0,0 +1,13 @@ +{ "id": "widminbat", + "name": "Minimal Battery", + "shortName":"MinBat", + "version":"0.03", + "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"} + ] +} diff --git a/apps/widminbate/widget.js b/apps/widminbate/widget.js new file mode 100644 index 000000000..27453f7cd --- /dev/null +++ b/apps/widminbate/widget.js @@ -0,0 +1,30 @@ +(()=>{ + function getWidth() { + return E.getBattery() <= 30 || Bangle.isCharging() ? 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.clearRect(x,y,x+s,y+23); + 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" : (bat <= 30 ? "#f80" : "#0f0"); + g.setColor(color).fillRect(x+4,y+6,x+4+barWidth,y+17); + },update: function() { + var newWidth = getWidth(); + if(newWidth != this.width) { + this.width = newWidth; + Bangle.drawWidgets();//relayout + }else{ + this.draw(); + } + }}; + setInterval(()=>{ + var widget = WIDGETS.minbat; + if(widget) {widget.update();} + }, 10*60*1000); + Bangle.on('charging', () => WIDGETS.minbat.update()); +})(); diff --git a/apps/widminbate/widget.png b/apps/widminbate/widget.png new file mode 100644 index 000000000..b04bc4ef9 Binary files /dev/null and b/apps/widminbate/widget.png differ