some changes to btctrl

This commit is contained in:
speedie 2022-12-31 16:30:32 +01:00
parent 47e5be68a3
commit cd256ff66c

View file

@ -8,7 +8,7 @@ CHECK() {
case "$RUNLAUNCHER" in
"") RUNLAUNCHER=dmenu ;;
esac
BINDIR="$(dirname $(command -v speedwm-core))/"
}
@ -17,7 +17,7 @@ HAVE_GRID="true"
if [ -e "$HOME/.config/speedwm/globalrc" ]; then
. $HOME/.config/speedwm/globalrc
else
printf "HAVE_GRID=$HAVE_GRID # Whether or not to use the Grid argument. If you do not have the dmenu grid patch, set this to false. Doing so will disable grid." > $HOME/.config/speedwm/globalrc
fi
@ -33,7 +33,7 @@ CHECK
# Help
HELP() {
printf "\n1. Turn on your device\n2. Make sure the bluetooth service is running. If it is not, start it.\n3. Press the pair button on your device\n4. Select your device in the list of devices. If it does not show up, select 'Refresh'.\n5. Select 'Pair' and then optionally 'Trust' to save it in the list of devices.\n6. And finally, select 'Connect' to connect the device." | $RUNLAUNCHER -l 12 $GRIDARG $GRIDNUM -p 'How to use'
printf "\n1. Turn on your device\n2. Make sure the bluetooth service is running. If it is not, start it.\n3. Press the pair button on your device\n4. Select your device in the list of devices. If it does not show up, select 'Refresh'.\n5. Select 'Pair' and then optionally 'Trust' to save it in the list of devices.\n6. And finally, select 'Connect' to connect the device." | $RUNLAUNCHER -l 12 $GRIDARG $GRIDNUM -p 'How to use'
$0 && exit 0
}
@ -43,7 +43,7 @@ ENABLE_BT() {
bluetoothctl scan on & # Start scanning for devices
bluetoothctl devices | grep -q "No default controller" && printf "No Bluetooth controller was found.\n" && exit 1
USEROPT_1="$(printf "$(bluetoothctl devices | cut -d\ -f3-)\n------\nRefresh\nHelp\nExit" | $RUNLAUNCHER -l 12 $GRIDARG $GRIDNUM -p "Select a device")"
# Check what to do
case "$USEROPT_1" in
"") exit 0 ;;
@ -72,31 +72,31 @@ LIST_OPTIONS
# Trust device
TRUST() {
bluetoothctl trust $SELDEVICE_MAC
bluetoothctl trust $SELDEVICE_MAC && return 0 || return 1
}
# Pair device
PAIR() {
bluetoothctl pair $SELDEVICE_MAC
bluetoothctl pair $SELDEVICE_MAC && return 0 || return 1
}
# Remove device
REMOVE() {
bluetoothctl remove $SELDEVICE_MAC
bluetoothctl remove $SELDEVICE_MAC && return 0 || return 1
}
UNTRUST() {
bluetoothctl untrust $SELDEVICE_MAC
bluetoothctl untrust $SELDEVICE_MAC && return 0 || return 1
}
# Connect
CONNECT() {
if [ -e "$/tmp/isconnected" ]; then
if [ -e "/tmp/isconnected" ]; then
NOTIFY_ALREADY_CONNECTED && exit 0
fi
bluetoothctl connect $SELDEVICE_MAC
touch /tmp/isconnected
bluetoothctl connect $SELDEVICE_MAC && isconnected=true
[ "$isconnected" = "true" ] && touch /tmp/isconnected && return 0 || return 1
}
# Disconnect
@ -107,7 +107,11 @@ DISCONNECT() {
# Notification when connecting
NOTIFY_CONNECT() {
notify-send " Connected to ${USEROPT_1}!"
if [ "$isconnected" = "true" ]; then
notify-send " Connected to ${USEROPT_1}!"
else
notify-send " Failed to connect to ${USEROPT_1}! Is the device on and available?"
fi
}
# Notification when disconnecting
@ -130,7 +134,7 @@ PERFORM() {
case "$USEROPT_2" in
"Trust") TRUST && LIST_OPTIONS ;;
"Pair") PAIR && LIST_OPTIONS ;;
"Connect") CONNECT && NOTIFY_CONNECT && LIST_OPTIONS ;;
"Connect") CONNECT; NOTIFY_CONNECT ;;
"Disconnect") DISCONNECT && NOTIFY_DISCONNECT && LIST_OPTIONS ;;
"Untrust") UNTRUST && LIST_OPTIONS ;;
"Remove") REMOVE && NOTIFY_REMOVE && LIST_OPTIONS ;;
@ -141,5 +145,3 @@ PERFORM() {
}
PERFORM
$0 && exit 0