slowed down startup again, breaks scan otherwise

This commit is contained in:
Alexander Bocken 2020-07-05 19:45:12 +02:00
parent bbad7146b3
commit e1fe5f134a

15
bt
View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
SCAN_PERIOD=5 SCAN_PERIOD=5
AUTOTRUST=false AUTOTRUST=false #trust every newly paired device
AUTOSCAN=true #immediately start scanning when started to speed up pairing process AUTOSCAN=true #immediately start scanning when started to speed up pairing process
#locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install) #locations of blacklist and hard coded list of paired devices (watch out, need to modify Makefile as well if you want to change these values and still use make install)
BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist BLACKLIST=${XDG_DATA_HOME:-$HOME/.local/share}/bt/blacklist
@ -25,10 +25,11 @@ power(){
[ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on [ "$powerstatus" = "no" ] && [ "$1" = on ] && bluetoothctl power on
[ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off [ "$powerstatus" = "yes" ] && [ "$1" = off ] && bluetoothctl power off
} }
scan(){ scan(){
scanstatus="$( bluetoothctl show | grep Discovering | awk '{print $2}' )" scanstatus="$( bluetoothctl show | grep Discovering | awk '{print $2}' )"
if [ "$1" = on ]; then if [ "$1" = on ]; then
#sets variable in case scanning was already on before the start of bt #sets variable in case scanning was no already on before the start of bt
[ "$start_scan" = "" ] && start_scan="$( date +'%s' )" [ "$start_scan" = "" ] && start_scan="$( date +'%s' )"
if [ "$scanstatus" = "no" ]; then if [ "$scanstatus" = "no" ]; then
bluetoothctl scan on & bluetoothctl scan on &
@ -61,7 +62,9 @@ startup(){
scan on scan on
fi fi
} }
startup &
#Sadly needs to be run without '&' for now, since it otherwise breaks start_scan variable
startup
update_pair_list & update_pair_list &
# shellcheck disable=SC1091 # shellcheck disable=SC1091
@ -111,11 +114,11 @@ pair(){
new_devices="$( echo "$all_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )" new_devices="$( echo "$all_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
bt_IDS="$( echo "$all_devices" | awk '{print $2}' )" bt_IDS="$( echo "$all_devices" | awk '{print $2}' )"
else else
echo "$paired_devices" > /tmp/paired_devices$$ #echo "$paired_devices" > /tmp/paired_devices$$
filtered_devices="$( echo "$all_devices" | grep -vf "/tmp/paired_devices$$")" filtered_devices="$( echo "$all_devices" | grep -v "$paired_devices")"
bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )" bt_IDS="$( echo "$filtered_devices" | awk '{print $2}' )"
new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )" new_devices="$( echo "$filtered_devices" | awk '{for (i=3; i<NF; i++) printf $i " "; print $NF}' )"
rm /tmp/paired_devices$$ #rm /tmp/paired_devices$$
fi fi
[ "$new_devices" = "" ] && options="rescan" || options=$(echo "$new_devices" && echo 'rescan') [ "$new_devices" = "" ] && options="rescan" || options=$(echo "$new_devices" && echo 'rescan')
choice=$( echo "$options" | dmenu -l 10 -i -p 'pair with which device?' ) choice=$( echo "$options" | dmenu -l 10 -i -p 'pair with which device?' )