added charging detection to battery icon (#53)
This commit is contained in:
@@ -9,10 +9,13 @@ 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 [];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user