From b5796746f202efffef479afff4ddc30ecc3f3860 Mon Sep 17 00:00:00 2001 From: Luc Bijl Date: Thu, 14 Aug 2025 20:34:04 +0000 Subject: [PATCH] src/battery: add --- src/battery | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100755 src/battery diff --git a/src/battery b/src/battery new file mode 100755 index 0000000..5e6c0d8 --- /dev/null +++ b/src/battery @@ -0,0 +1,52 @@ +#!/bin/sh + +# Define icon theme and path +icon_theme="Tela-circle-black-dark" +icon_path="/usr/share/icons/${icon_theme}/24/panel" + +# Define icon files for different discharging battery states +discharging_empty="${icon_path}/battery-000.svg" +discharging_low="${icon_path}/battery-020.svg" +discharging_medium="${icon_path}/battery-050.svg" +discharging_good="${icon_path}/battery-080.svg" +discharging_full="${icon_path}/battery-100.svg" + +# Define icon files for different charging battery states +charging_empty="${icon_path}/battery-020" +charging_low="${icon_path}/battery-020-charging.svg" +charging_medium="${icon_path}/battery-050-charging.svg" +charging_good="${icon_path}/battery-080-charging.svg" +charging_full="${icon_path}/battery-100-charged.svg" + +# Get the capacity and charging state of the battery +capacity="$(cat "/sys/class/power_supply/BAT0/capacity")" +charging="$(cat "/sys/class/power_supply/AC/online")" + +# Send a different notification based on the charging state +if [ $charging -eq 0 ]; then + # send a different notification based on the capacity + if [ $capacity -gt 90 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_full -t 4000 + elif [ $capacity -gt 70 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_good -t 4000 + elif [ $capacity -gt 40 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_medium -t 4000 + elif [ $capacity -gt 10 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_low -t 4000 + else + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $discharging_empty -t 4000 + fi +else + # Send a different notification based on the capacity + if [ $capacity -gt 90 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_full -t 4000 + elif [ $capacity -gt 70 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_good -t 4000 + elif [ $capacity -gt 40 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_medium -t 4000 + elif [ $capacity -gt 10 ]; then + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_low -t 4000 + else + notify-send "Capacity: ${capacity}%" -h int:value:$capacity -h string:synchronous: -i $charging_empty -t 4000 + fi +fi