nixos-configs/devices/wim/config/ags/js/bar/battery.js

31 lines
853 B
JavaScript
Raw Normal View History

import Battery from 'resource:///com/github/Aylur/ags/service/battery.js';
import { Label, Icon, Box } from 'resource:///com/github/Aylur/ags/widget.js';
import Separator from '../misc/separator.js';
2023-09-11 19:57:21 -04:00
const Indicator = () => Icon({
className: 'battery-indicator',
binds: [['icon', Battery, 'icon-name']],
connections: [[Battery, self => {
self.toggleClassName('charging', Battery.charging);
self.toggleClassName('charged', Battery.charged);
self.toggleClassName('low', Battery.percent < 20);
}]],
});
const LevelLabel = props => Label({
...props,
className: 'label',
connections: [[Battery, self => self.label = `${Battery.percent}%`]],
});
export default () => Box({
className: 'toggle-off battery',
children: [
Indicator(),
Separator(5),
LevelLabel(),
],
});