Skip to content

Commit

Permalink
Don't prevent the user from switching to HFS profile.
Browse files Browse the repository at this point in the history
  • Loading branch information
valderman committed Aug 1, 2019
1 parent 17ea4d7 commit 579f667
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.EXPORT_ALL_VARIABLES:

# Package version; sync with debian/control
VERSION ?= 0.1
VERSION ?= 0.2
BINDIR ?= /usr/local/bin

RULES=70-bt-reload-headphones.rules
Expand Down
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: bt-reload-headphones
Version: 0.1-1
Version: 0.2-1
Section: base
Priority: optional
Architecture: all
Expand Down
14 changes: 9 additions & 5 deletions src/bt-reload-headphones
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ whitelist_exists() {
}

is_headset() {
BTINFO=$(bluetoothctl info $1)
local BTINFO=$(bluetoothctl info $1)
(echo $BTINFO | grep -q "UUID: Audio Sink") && (echo $BTINFO | grep -q "Icon: audio-card") && (echo $BTINFO | grep -q "Connected: yes")
}

Expand All @@ -47,17 +47,21 @@ find_pulse_user() {
return 1
}

has_a2dp_sink() {
grep -A20 bluez_card.$1 | egrep ^\\s+a2dp_sink | grep -q 'available: yes'
}

can_set_a2dp() {
sleep 1 # PulseAudio needs some time to get into gear
UNDERSCORE_MAC=$(echo $1 | sed -e 's/:/_/g')
CMD="pactl set-card-profile bluez_card.$UNDERSCORE_MAC a2dp_sink"
local MAC=$(echo $1 | sed -e 's/:/_/g')
local LIST_CARDS="/usr/bin/pactl list cards"
if [[ "$(whoami)" == "root" ]] ; then
PA_USER=$(find_pulse_user)
RUNDIR="/run/user/$(id -u $PA_USER)"
USER=$(getent passwd $PA_USER | cut -d: -f1)
su -c "XDG_RUNTIME_DIR=$RUNDIR $CMD" $USER
su -c "XDG_RUNTIME_DIR=$RUNDIR $LIST_CARDS" $USER | has_a2dp_sink $MAC
else
$CMD
$LIST_CARDS | has_a2dp_sink $MAC
fi
}

Expand Down

0 comments on commit 579f667

Please sign in to comment.