added charging detection to battery icon (#53)

This commit is contained in:
matavach
2024-07-31 23:20:34 -05:00
committed by GitHub
parent c238a72963
commit 126f2b7535

View File

@@ -8,11 +8,14 @@ const { label: show_label } = options.bar.battery;
const BatteryLabel = () => { const BatteryLabel = () => {
const isVis = Variable(battery.available); const isVis = Variable(battery.available);
const icon = () => const batIcon = Utils.merge([battery.bind("percent"), battery.bind("charging"), battery.bind("charged")],
battery (batPercent: number, batCharging, batCharged) => {
.bind("percent") if(batCharged)
.as((p) => `battery-level-${Math.floor(p / 10) * 10}-symbolic`); return `battery-level-100-charged-symbolic`;
else
return `battery-level-${Math.floor(batPercent / 10) * 10}${batCharging ? '-charging' : ''}-symbolic`;
});
battery.connect("changed", ({ available }) => { battery.connect("changed", ({ available }) => {
isVis.value = available; isVis.value = available;
@@ -49,7 +52,7 @@ const BatteryLabel = () => {
return [ return [
Widget.Icon({ Widget.Icon({
class_name: "bar-button-icon battery", class_name: "bar-button-icon battery",
icon: icon() icon: batIcon
}), }),
Widget.Label({ Widget.Label({
class_name: "bar-button-label battery", class_name: "bar-button-label battery",
@@ -57,7 +60,7 @@ const BatteryLabel = () => {
}), }),
]; ];
} else if (batAvail && !showLabel) { } else if (batAvail && !showLabel) {
return [Widget.Icon({ icon: icon() })]; return [Widget.Icon({ icon: batIcon })];
} else { } else {
return []; return [];
} }