nixos-configs/nixosModules/ags/v2/widgets/bar/items/battery.tsx

33 lines
942 B
TypeScript
Raw Normal View History

2024-09-26 23:55:06 -04:00
import { bind, Widget } from 'astal';
import AstalBattery from 'gi://AstalBattery';
const Battery = AstalBattery.get_default();
import Separator from '../../misc/separator';
const LOW_BATT = 20;
const SPACING = 5;
export default () => (
2024-09-27 12:37:14 -04:00
<box className="bar-item battery">
2024-09-26 23:55:06 -04:00
<icon
icon={bind(Battery, 'batteryIconName')}
setup={(self: Widget.Icon) => {
Battery.connect('notify::percentage', () => {
2024-09-27 12:37:14 -04:00
const percent = Math.round(Battery.get_percentage() * 100);
2024-09-26 23:55:06 -04:00
self.toggleClassName('charging', Battery.get_charging());
2024-09-27 12:37:14 -04:00
self.toggleClassName('charged', percent === 100);
self.toggleClassName('low', percent < LOW_BATT);
2024-09-26 23:55:06 -04:00
});
}}
/>
<Separator size={SPACING} />
2024-09-27 12:37:14 -04:00
<label label={bind(Battery, 'percentage').as((v) => `${Math.round(v * 100)}%`)} />
2024-09-26 23:55:06 -04:00
</box>
);