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

33 lines
867 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';
2023-11-16 00:48:50 -05:00
import Separator from '../../misc/separator.js';
2023-09-11 19:57:21 -04:00
const LOW_BATT = 20;
2023-12-18 18:00:30 -05:00
const SPACING = 5;
2023-12-18 18:00:30 -05:00
export default () => Box({
class_name: 'toggle-off battery',
2023-12-18 18:00:30 -05:00
children: [
Icon({
class_name: 'battery-indicator',
// @ts-expect-error
icon: Battery.bind('icon_name'),
}).hook(Battery, (self) => {
self.toggleClassName('charging', Battery.charging);
self.toggleClassName('charged', Battery.charged);
self.toggleClassName('low', Battery.percent < LOW_BATT);
2023-12-18 18:00:30 -05:00
}),
Separator(SPACING),
2023-12-18 18:00:30 -05:00
Label({
label: Battery.bind('percent')
.transform((v) => `${v}%`),
}),
],
});