1
0
Fork 0

Merge pull request #2610 from nxdefiant/widbatpc

widbatpc: Only redraw when values change
master
Gordon Williams 2023-02-27 11:07:14 +00:00 committed by GitHub
commit 44af5523e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View File

@ -15,3 +15,4 @@
0.16: Increase screen update rate when charging
0.17: Add option 'Remove Jitter'='Drop only' to prevent percentage from getting up again when not charging
Add option to disable vibration when charger connects
0.18: Only redraw when values change

View File

@ -2,7 +2,7 @@
"id": "widbatpc",
"name": "Battery Level Widget (with percentage)",
"shortName": "Battery Widget",
"version": "0.17",
"version": "0.18",
"description": "Show the current battery level and charging status in the top right of the clock, with charge percentage",
"icon": "widget.png",
"type": "widget",

View File

@ -86,7 +86,7 @@
return changed;
}
function draw() {
function draw(fromInterval) {
// if hidden, don't draw
if (!WIDGETS["batpc"].width) return;
// else...
@ -103,6 +103,14 @@
l = prevMin;
}
}
if (fromInterval === true && this.prevLevel === l && this.prevCharging === Bangle.isCharging()) {
return; // unchanged, do nothing
}
this.prevLevel = l;
this.prevCharging = Bangle.isCharging();
const c = levelColor(l);
if (Bangle.isCharging() && setting('charger')) {
@ -173,7 +181,7 @@
if (on) update();
});
var id = setInterval(()=>WIDGETS["batpc"].draw(), intervalLow);
var id = setInterval(()=>WIDGETS["batpc"].draw(true), intervalLow);
WIDGETS["batpc"]={area:"tr",width:40,draw:draw,reload:reload};
setWidth();