BangleApps/apps/widChargingStatus/widget.ts

40 lines
948 B
TypeScript
Raw Normal View History

(() => {
const icon = require('heatshrink').decompress(
atob(
'ikggMAiEAgYIBmEAg4EB+EAh0AgPggEeCAIEBnwQBAgP+gEP//x///j//8f//k///H//4BYOP/4lBv4bDvwEB4EAvAEBwEAuA7DCAI7BgAQBhEAA'
)
);
const iconWidth = 18;
2021-12-04 21:22:22 +00:00
2023-02-25 21:58:53 +00:00
function draw(this: { x?: number; y?: number }) {
g.reset();
if (Bangle.isCharging()) {
g.setColor('#FD0');
2023-02-25 21:58:53 +00:00
g.drawImage(icon, this.x! + 1, this.y! + 1, {
scale: 0.6875,
});
}
}
2024-05-04 21:21:43 +00:00
WIDGETS["chargingStatus"] = {
area: 'tr',
width: Bangle.isCharging() ? iconWidth : 0,
2021-12-10 21:32:36 +00:00
draw: draw,
};
Bangle.on('charging', (charging) => {
2024-05-04 21:21:43 +00:00
const widget = WIDGETS["chargingStatus"];
2021-12-10 20:36:42 +00:00
if (widget) {
if (charging) {
Bangle.buzz();
widget.width = iconWidth;
} else {
Promise.resolve().then(() => require("buzz").pattern("..;"));
2021-12-10 20:36:42 +00:00
widget.width = 0;
}
Bangle.drawWidgets(); // re-layout widgets
g.flip();
}
});
})();