From f95a172c30d7fecae26235260bfd06b35a4b0851 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Tue, 13 Feb 2024 15:26:05 +0545 Subject: [PATCH] feat(battery_notifier): Improved versio XD:( --- config/hypr/scripts/System_cmd.sh | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/config/hypr/scripts/System_cmd.sh b/config/hypr/scripts/System_cmd.sh index 120299be..3a041fa7 100755 --- a/config/hypr/scripts/System_cmd.sh +++ b/config/hypr/scripts/System_cmd.sh @@ -366,11 +366,16 @@ esac battery_notify() { PREV_STATUS="Unknown" # Initialize previous status +FULL_CHARGE_NOTIFIED=0 +LOW_BATTERY_NOTIFIED=0 while true; do STATUS=$(cat /sys/class/power_supply/AC/online 2>/dev/null) # Get charger status using power supply directory if [ "$STATUS" != "$PREV_STATUS" ]; then # Check if the charger status has changed + FULL_CHARGE_NOTIFIED=0 # Reset full charge notification state when charger status changes + LOW_BATTERY_NOTIFIED=0 # Reset low battery notification state when charger status changes + if [ "$STATUS" == "1" ]; then # Send a notification when charger is plugged in or unplugged notify-send -u low "🔌 Charger Plugged In" "Battery charging" else @@ -383,11 +388,14 @@ while true; do BATTERY_INFO=$(acpi) PERCENT=$(echo "$BATTERY_INFO" | awk -F ',|%' '{print $2}') - if [ "$STATUS" == "1" ] && [ "$PERCENT" -eq 100 ]; then # Check if the battery is charging and the percentage is 100% + if [ "$STATUS" == "1" ] && [ "$PERCENT" -eq 100 ] && [ "$FULL_CHARGE_NOTIFIED" -eq 0 ]; then # Check if the battery is charging and the percentage is 100% notify-send -u low "🔌 Battery Fully Charged" "You can unplug the charger" # Send a notification when the battery is fully charged + FULL_CHARGE_NOTIFIED=1 # Set the state to indicate that the full charge notification has been sent fi - if [ "$PERCENT" -le 15 ]; then # Check if the battery percentage is less than or equal to 20% - notify-send -u critical "🪫 Low Battery" "Plug in the charger" #Send low battery notification + + if [ "$PERCENT" -le 20 ] && [ "$LOW_BATTERY_NOTIFIED" -eq 0 ]; then # Check if the battery percentage is less than or equal to 20% and low battery notification has not been sent + notify-send -u critical "🪫 Low Battery" "Plug in the charger" # Send low battery notification + LOW_BATTERY_NOTIFIED=1 # Set the state to indicate that the low battery notification has been sent fi sleep 0.1 # Sleep for some time before checking again done