Fix plenty of big bugs

This commit is contained in:
Jacob 2023-08-12 04:23:04 +02:00
parent b471598eca
commit 1cc3f2a64b

View file

@ -6,26 +6,25 @@
[ -z "$RUNLAUNCHER" ] && RUNLAUNCHER=spmenu
# Bluetooth device control functions
trust_dev() { bluetoothctl trust "$dev" && return 0 || return 1; }
pair_dev() { bluetoothctl pair "$dev" && return 0 || return 1; }
remove_dev() { bluetoothctl remove "$dev" && return 0 || return 1; }
untrust_dev() { bluetoothctl untrust "$dev" && return 0 || return 1; }
connect_dev() { bluetoothctl connect "$dev"; }
disconnect_dev() { bluetoothctl disconnect "$dev"; }
trust_dev() { bluetoothctl trust "$dev" 2>/dev/null && return 0 || return 1; }
pair_dev() { bluetoothctl pair "$dev" 2>/dev/null && return 0 || return 1; }
remove_dev() { bluetoothctl remove "$dev" 2>/dev/null && return 0 || return 1; }
untrust_dev() { bluetoothctl untrust "$dev" 2>/dev/null && return 0 || return 1; }
connect_dev() { bluetoothctl connect "$dev" 2>/dev/null; }
disconnect_dev() { bluetoothctl disconnect "$dev" 2>/dev/null; }
# Misc functions
list_opts() { seldev_o="$(printf -- "<b>Options</b>\nConnect\nDisconnect\n<b>Toggle</b>\nPair\nRemove\nTrust\nUntrust\n\nExit" | sed "s/-e //g" | $RUNLAUNCHER -g 1 -l 20 -p "What do you want to do with this device?" | awk '{ print $1 }')"; }
list_dev() {
printf "%s\n\nExit" "$(bluetoothctl devices | cut -d\ -f3-)" > /tmp/btctrl-file
printf "%s\n\nExit" "$(bluetoothctl devices | cut -d\ -f3- 2>/dev/null)" > /tmp/btctrl-file
sleep 1
printf "update" > /tmp/spmenu.fifo
list_dev
printf "drawmenu" > /tmp/spmenu.fifo
}
scan_dev() {
bluetoothctl power on
bluetoothctl scan on
bluetoothctl power on 2>/dev/null
bluetoothctl scan on 2>/dev/null
}
# Enable bluetooth and scan for devices
@ -38,15 +37,15 @@ enable_bt() {
seldev="$($RUNLAUNCHER -lf /tmp/btctrl-file -l 12 -g 1 -p "Select a device")"
rm -f "/tmp/spmenu.fifo"
pkill -P $$
# Check what to do
case "$seldev" in
"") exit 0 ;;
"Exit") exit 0 ;;
"") rm -f /tmp/spmenu.fifo; exit 0 ;;
"Exit") rm -f /tmp/spmenu.fifo; exit 0 ;;
esac
dev="$(bluetoothctl devices | grep "$seldev$" | awk '{ print $2 }')"
dev="$(bluetoothctl devices | grep "$seldev$" | awk '{ print $2 }' 2>/dev/null)"
# Check if a MAC was grabbed
[ -z "$dev" ] && printf "Could not get MAC\n" && exit 1
@ -61,8 +60,8 @@ perform() {
"Disconnect") disconnect_dev ;;
"Untrust") untrust_dev && list_opts ;;
"Remove") remove_dev ;;
"Exit") pkill bluetoothctl; exit 0 ;;
"") pkill bluetoothctl; exit 0 ;;
"Exit") pkill bluetoothctl; rm -f /tmp/spmenu.fifo; exit 0 ;;
"") pkill bluetoothctl; rm -f /tmp/spmenu.fifo; enable_bt ;;
esac
}
@ -72,6 +71,8 @@ main() {
perform
pkill bluetoothctl
pkill list_dev
rm -f /tmp/spmenu.fifo
return 0
}