Fix battery icon

This commit is contained in:
Thomas Avé 2024-11-29 00:29:14 +01:00
parent 1db94740ed
commit 8b02610d97
1 changed files with 15 additions and 12 deletions

View File

@ -151,18 +151,21 @@ function Right() : JSX.Element {
}
function BatteryIcon(): JSX.Element {
if (!battery.online) return <box />;
return <box> {
bind(battery, "percentage").as((percentage) => {
const thresholds = [...Array(11).keys()].map( i => i * 10);
const icon = thresholds.find(threshold => threshold >= percentage * 100)
const charging_name = battery.percentage >= 0.99 ? "charged" : "charging"
return <box className="battery-item" tooltip_text={`Battery ${battery.percentage * 100}%`}>
<icon icon={battery.charging? `battery-level-${icon}-${charging_name}-symbolic` : `battery-level-${icon}-symbolic`} />
</box>
})
}
</box>
if (!battery) return <box />;
return <button className="battery-item" onClicked={() => execAsync(['gnome-power-manager'])}>
<box>
{
bind(battery, "percentage").as((percentage) => {
const thresholds = [...Array(11).keys()].map( i => i * 10);
const icon = thresholds.find(threshold => threshold >= percentage * 100)
const charging_name = battery.percentage >= 0.99 ? "charged" : "charging"
return <icon
icon={battery.charging? `battery-level-${icon}-${charging_name}-symbolic` : `battery-level-${icon}-symbolic`}
/>
})
}
</box>
</button>
}
function Icons() {