feat(ags): use upower for battery service

This commit is contained in:
matt1432 2023-09-26 13:32:24 -04:00
parent 5b29c3b199
commit f14f45ca72
2 changed files with 37 additions and 33 deletions

View file

@ -1,5 +1,5 @@
const { Label, Icon, Stack, ProgressBar, Overlay, Box } = ags.Widget;
const { exec } = ags.Utils;
const { Battery } = ags.Service;
const { Label, Icon, Stack, Box } = ags.Widget;
import { Separator } from '../misc/separator.js';
@ -18,8 +18,8 @@ const icons = charging => ([
const Indicators = charging => Stack({
items: icons(charging),
connections: [[1000, stack => {
stack.shown = `${Math.floor(exec('cat /sys/class/power_supply/BAT0/capacity') / 10) * 10}`;
connections: [[Battery, stack => {
stack.shown = `${Math.floor(Battery.percent / 10) * 10}`;
}]],
});
@ -34,20 +34,18 @@ const Indicator = ({
['true', charging],
['false', discharging],
],
connections: [[1000, stack => {
const charging = exec('cat /sys/class/power_supply/BAT0/status') == 'Charging';
const charged = exec('cat /sys/class/power_supply/BAT0/capacity') == 100;
stack.shown = `${charging || charged}`;
stack.toggleClassName('charging', charging);
stack.toggleClassName('charged', charged);
stack.toggleClassName('low', exec('cat /sys/class/power_supply/BAT0/capacity') < 30);
connections: [[Battery, stack => {
stack.shown = `${Battery.charging || Battery.charged}`;
stack.toggleClassName('charging', Battery.charging);
stack.toggleClassName('charged', Battery.charged);
stack.toggleClassName('low', Battery.percent < 20);
}]],
});
const LevelLabel = params => Label({
...params,
className: 'label',
connections: [[1000, label => label.label = `${exec('cat /sys/class/power_supply/BAT0/capacity')}%`]],
connections: [[Battery, label => label.label = `${Battery.percent}%`]],
});
export const BatteryIndicator = Box({

View file

@ -6,35 +6,41 @@
powerOnBoot = true;
};
services.udev.extraRules = ''
# enable brightness control for swayosd
programs.light.enable = true;
services = {
udev.extraRules = ''
# give permanent path to keyboard XF86* binds
SUBSYSTEMS=="input", ATTRS{id/product}=="0006", ATTRS{id/vendor}=="0000", SYMLINK += "video-bus"
'';
# enable brightness control for swayosd
programs.light.enable = true;
services.fwupd.enable = true;
fwupd.enable = true;
# Enable CUPS to print documents.
services.printing.enable = true;
services.printing.drivers = with pkgs; [
printing.enable = true;
printing.drivers = with pkgs; [
hplip
];
# Enable sound.
# sound.enable = true;
hardware.pulseaudio.enable = false;
services.pipewire = {
pipewire = {
enable = true;
alsa.enable = true;
jack.enable = true;
pulse.enable = true;
};
hardware.sensor.iio.enable = true;
hardware.opengl.enable = true;
hardware.opengl.driSupport32Bit = true;
hardware.uinput.enable = true;
upower.enable = true;
};
hardware = {
pulseaudio.enable = false;
sensor.iio.enable = true;
opengl.enable = true;
opengl.driSupport32Bit = true;
uinput.enable = true;
};
virtualisation = {
libvirtd.enable = true;