Skip to content

Commit

Permalink
[common] Check for PulseAudio on WSL2
Browse files Browse the repository at this point in the history
  • Loading branch information
goldyfruit committed Nov 20, 2023
1 parent 4cfa883 commit 771572c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
14 changes: 13 additions & 1 deletion tests/bats/sound.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ function setup() {
unset pgrep command
}

@test "function_detect_sound_pulseaudio_wsl2" {
PULSE_SOCKET_WSL2=/tmp/PulseServer
run touch "$PULSE_SOCKET_WSL2"
function pactl() {
echo "Server Name: pulseaudio"
}
export -f pactl
detect_sound
assert_equal "$SOUND_SERVER" "pulseaudio"
unset pactl
}

@test "function_detect_sound_pipewire" {
function pgrep() {
echo "pipewire"
Expand All @@ -59,5 +71,5 @@ function setup() {
}

function teardown() {
rm -f "$LOG_FILE"
rm -f "$LOG_FILE" "$PULSE_SOCKET_WSL2"
}
7 changes: 7 additions & 0 deletions utils/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ function detect_sound() {
SOUND_SERVER="PulseAudio (on PipeWire)"
fi
export SOUND_SERVER
elif [ -f "$PULSE_SOCKET_WSL2" ]; then
# This condition is only related to WSL2 as PulseServer socket will be under
# /mnt/wslg/ directory.
if command -v pactl &>>"$LOG_FILE"; then
SOUND_SERVER="$(pactl info | awk -F":" '$1 ~ /Server Name/ { print $2 }' | sed 's/^ *//')"\
export SOUND_SERVER
fi
# Looking for strictly for pipepire process
elif [ "$(pgrep -a -f "pipewire$" | awk -F"/" '{ print $NF }' 2>>"$LOG_FILE")" == "pipewire" ]; then
export SOUND_SERVER="PipeWire"
Expand Down
1 change: 1 addition & 0 deletions utils/constants.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export NEWT_COLORS="
roottext=lightgrey,black
"
export OS_RELEASE=/etc/os-release
export PULSE_SOCKET_WSL2=/mnt/wslg/PulseServer
export USER_ID="$EUID"

0 comments on commit 771572c

Please sign in to comment.