2023-10-31 08:32:40 -04:00
|
|
|
import Battery from 'resource:///com/github/Aylur/ags/service/battery.js';
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 16:19:09 -05:00
|
|
|
import { Label, Icon, Box } from 'resource:///com/github/Aylur/ags/widget.js';
|
2023-09-06 17:33:47 -04:00
|
|
|
|
2023-11-16 00:48:50 -05:00
|
|
|
import Separator from '../../misc/separator.js';
|
2023-09-11 19:57:21 -04:00
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const LOW_BATT = 20;
|
|
|
|
|
2023-09-06 17:33:47 -04:00
|
|
|
|
2023-11-13 16:19:09 -05:00
|
|
|
const Indicator = () => Icon({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'battery-indicator',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-11-13 16:19:09 -05:00
|
|
|
binds: [['icon', Battery, 'icon-name']],
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
connections: [[Battery, (self) => {
|
2023-11-13 16:19:09 -05:00
|
|
|
self.toggleClassName('charging', Battery.charging);
|
|
|
|
self.toggleClassName('charged', Battery.charged);
|
2023-11-21 01:29:46 -05:00
|
|
|
self.toggleClassName('low', Battery.percent < LOW_BATT);
|
2023-10-20 23:11:21 -04:00
|
|
|
}]],
|
2023-09-06 17:33:47 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const LevelLabel = (props) => Label({
|
2023-10-20 23:11:21 -04:00
|
|
|
...props,
|
|
|
|
className: 'label',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
|
|
|
connections: [[Battery, (self) => {
|
|
|
|
self.label = `${Battery.percent}%`;
|
|
|
|
}]],
|
2023-09-06 17:33:47 -04:00
|
|
|
});
|
|
|
|
|
2023-11-21 01:29:46 -05:00
|
|
|
const SPACING = 5;
|
|
|
|
|
2023-10-17 13:47:02 -04:00
|
|
|
export default () => Box({
|
2023-10-20 23:11:21 -04:00
|
|
|
className: 'toggle-off battery',
|
2023-11-21 01:29:46 -05:00
|
|
|
|
2023-10-20 23:11:21 -04:00
|
|
|
children: [
|
|
|
|
Indicator(),
|
2023-11-21 01:29:46 -05:00
|
|
|
Separator(SPACING),
|
2023-10-20 23:11:21 -04:00
|
|
|
LevelLabel(),
|
|
|
|
],
|
2023-09-06 17:33:47 -04:00
|
|
|
});
|