marioortizmanero / polybar-pulseaudio-control

A feature-full Polybar module to control PulseAudio
MIT License
471 stars 49 forks source link

Error when pulseaudio is loading #13

Closed marioortizmanero closed 4 years ago

marioortizmanero commented 4 years ago

image

This only happens when pulseaudio starts running (sometimes). It does go away, but it still should be fixed. At this line:

# Fixed volume icons over max volume
local iconsLen=${#VOLUME_ICONS[@]}
if [ "$iconsLen" -ne 0 ]; then
    local volSplit=$((MAX_VOL / iconsLen))
    for i in $(seq 1 "$iconsLen"); do
        if [ $((i * volSplit)) -ge $curVol ]; then  # <-- Here
            volIcon="${VOLUME_ICONS[$((i-1))]}"
            break
        fi
    done
else
    volIcon=""
fi

It happens in the ouput function, which does check if pulseaudio is running, but as it's still loading some obtained variable is probably incorrect (curVol?). The bug should be fixed by checking for errors when getCurSink, getCurVol and getCurMuteStatus are called. This could also implement a better solution to check if pulseaudio is running, rather than this:

if [ -z "$(pgrep pulseaudio)" ]; then echo "Pulseaudio not running"; return 1; fi

The design choice here is whether the return value of these functions should be checked, or maybe they handle the errors by themselves and exit the script.