add: battery notify script

This commit is contained in:
ooks-io 2023-09-04 12:15:15 +12:00
parent cc0bbbe9f5
commit 659b7407d5
4 changed files with 56 additions and 87 deletions

View file

@ -0,0 +1,51 @@
{ config, lib, pkgs, ... }:
let
conf = config.modules.battery-notify;
in {
options.modules.battery-notify = with lib; {
enable = mkEnableOption "battery-notify";
};
config = lib.mkIf conf.enable {
systemd.user.services.battery-notify = {
wantedBy = [ "graphical-session.target" ];
script = ''
batval=$(cat /sys/class/power_supply/BAT0/capacity)
tempbatval="/tmp/bat_val_$batval"
if [ ! -f "$tempbatval" ]; then
case "$batval" in
75|50|25|10|5)
${pkgs.libnotify}/bin/notify-send -a bat-notify "battery:" "$batval"
touch "tempbatval"
;;
esac
fi
for level in 75 50 25 10 5; do
if [ "$batval" -gt "$level" ]; then
rm -f "/tmp/bat_val_$level"
fi
done
'';
};
systemd.user.timers.battery-notify = {
wantedBy = [ "timers.target" ];
after = [ "basic.target" ];
requires = [ "battery-notify.service" ];
partOf = [ "battery-notify.service" ];
timerConfig = {
OnBootSec = "1m";
OnUnitActiveSec = "1m";
};
};
};
}