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