(config) ags: fix battery icon
This commit is contained in:
parent
26054842a5
commit
a6defdb54e
1 changed files with 22 additions and 6 deletions
|
@ -161,22 +161,38 @@ function Volume() {
|
||||||
|
|
||||||
|
|
||||||
function BatteryLabel() {
|
function BatteryLabel() {
|
||||||
const value = battery.bind("percent").as(p => p > 0 ? p / 100 : 0)
|
const icons = {
|
||||||
const icon = battery.bind("percent").as(p =>
|
100: "full",
|
||||||
`battery-level-${Math.floor(p / 10) * 10}-symbolic`)
|
50: "good",
|
||||||
|
25: "low",
|
||||||
|
0: "empty",
|
||||||
|
};
|
||||||
|
const value = battery.bind("percent").as(p => p > 0 ? p / 100 : 0);
|
||||||
|
// const icon = battery.bind("percent").as(p =>
|
||||||
|
// `battery-level-${Math.floor(p / 10) * 10}-symbolic`)
|
||||||
|
|
||||||
const percent = battery.bind("percent").as(x => x.toString()) + "%"
|
const percent = battery.bind("percent").as(x => x.toString()) + "%";
|
||||||
|
|
||||||
|
function getIcon() {
|
||||||
|
const icon = [100, 50, 25, 0].find(threshold => threshold <= battery.percent);
|
||||||
|
|
||||||
|
return `battery-${icons[icon]}-symbolic`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const icon = Widget.Icon({
|
||||||
|
icon: Utils.watch(getIcon(), battery, getIcon),
|
||||||
|
});
|
||||||
|
|
||||||
return Widget.Box({
|
return Widget.Box({
|
||||||
class_name: "battery",
|
class_name: "battery",
|
||||||
visible: battery.bind("available"),
|
visible: battery.bind("available"),
|
||||||
children: [
|
children: [
|
||||||
Widget.Icon({ icon }),
|
icon,
|
||||||
Widget.Label({
|
Widget.Label({
|
||||||
label: battery.bind('percent').as(x => x.toString()),
|
label: battery.bind('percent').as(x => x.toString()),
|
||||||
})
|
})
|
||||||
],
|
],
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue