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

View file

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