gh0stzk / dotfiles

BSPWM environment with 18 themes. With a theme selector to change on the fly.
GNU General Public License v3.0
3.03k stars 228 forks source link

Battery low notification showing endlessly in z0mbi3 theme #351

Closed Momen-MKadry closed 3 weeks ago

Momen-MKadry commented 3 weeks ago

Hey, I added the battery script in the z0mbi3 theme as in #197 and now when the battery hits 20% it keeps spamming the battery low notification

image

I clear the notifications and they keep showing, I looked at the script but there seems to be nothing causing the issue there.

gh0stzk commented 3 weeks ago

I'm sure it's because of the interval of seconds in which the script is executed, every second it is executed. You should change the defpoll interval from 1s to 5m for example.

Momen-MKadry commented 3 weeks ago

change it in the eww.yuck file?

image

Doesn't the "1s" here means the battery level in eww will update every second?

gh0stzk commented 3 weeks ago

Yes the variable "battery" defined in

(defpoll battery    :interval "1s"    "scripts/battery icon")

Run the "icon" function every second within the bash script, and if you notice, within that function when the battery percentage is low, it sends the notification. And since it runs every second, that's why it sends notifications every second.

I have never added that function to the bar, that is why I have never modified the script, I would do it differently, but hey, the problem is solved by increasing the interval seconds/minutes.

gh0stzk commented 3 weeks ago

I would do it, directly in the yuck code without using any bash script, so I take advantage of the internal eww function EWW_BATTERY.

Momen-MKadry commented 3 weeks ago

Ok I changed to 5 minutes and will wait till my laptop discharge to 20%, sth weird I noticed tho, the battery script doesn't send notifications at 20% but at 10%, why did it send the notifications at 20% then?

gh0stzk commented 3 weeks ago

yes because

 elif [ "$per" -gt "20" ]; then
        icon=""
    elif [ "$per" -gt "10" ]; then
        icon=""
        notify-send -u critical "Battery Low" "Connect Charger"
    elif [ "$per" -gt "0" ]; then
        icon=""
        notify-send -u critical "Battery Low" "Connect Charger"
...

if percentage is greater than 10% will send the notification so, 11%, 12%, 13%, 14%,15%... 19% will send the notification, 20% will not.

Momen-MKadry commented 3 weeks ago

Oh, didn't notice the indentation my bad, thanks.

I will comment any updates when my battery reaches the threshold again

Momen-MKadry commented 3 weeks ago

The notification is working correctly now and appears every 5 minutes, thanks a lot for the help.

The icon updates every 5 minutes tho, but I think it's not a big deal really

gh0stzk commented 3 weeks ago

You can add a new var in eww.yuck for example

(defpoll battery_notif :interval "5m" "scripts/battery notifications")

and add a new function in the bash script

notifications () {
if [ "$per" -le "20" ]; then
       notify-send -u critical "Battery Low" "Connect Charger"
fi
}

Then call it, add, [ "$1" = "notifications" ] && notifications && exit

so now the icons and percentage will be 1s and just the notifications every 5 minutes.

Momen-MKadry commented 3 weeks ago

Ok thanks a lot