Skip to content

Commit 58be30b

Browse files
author
klea
committed
Add blocked toggle
1 parent 0cca4d4 commit 58be30b

1 file changed

Lines changed: 28 additions & 1 deletion

File tree

rofi-bluetooth

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,29 @@ toggle_trust() {
178178
fi
179179
}
180180

181+
# Checks if a device is blocked
182+
device_blocked() {
183+
device_info=$(bluetoothctl info "$1")
184+
if echo "$device_info" | grep -q "Blocked: yes"; then
185+
echo "Blocked: yes"
186+
return 0
187+
else
188+
echo "Blocked: no"
189+
return 1
190+
fi
191+
}
192+
193+
# Toggles device blocked
194+
toggle_blocked() {
195+
if device_blocked "$1"; then
196+
bluetoothctl unblock "$1"
197+
device_menu "$device"
198+
else
199+
bluetoothctl block "$1"
200+
device_menu "$device"
201+
fi
202+
}
203+
181204
# Prints a short string with the current bluetooth status
182205
# Useful for status bars like polybar, etc.
183206
print_status() {
@@ -228,7 +251,8 @@ device_menu() {
228251
fi
229252
paired=$(device_paired "$mac")
230253
trusted=$(device_trusted "$mac")
231-
options="$connected\n$paired\n$trusted\n$divider\n$goback\nExit"
254+
blocked=$(device_blocked "$mac")
255+
options="$connected\n$paired\n$trusted\n$blocked\n$divider\n$goback\nExit"
232256

233257
# Open rofi menu, read chosen option
234258
chosen="$(echo -e "$options" | $rofi_command "$device_name")"
@@ -247,6 +271,9 @@ device_menu() {
247271
"$trusted")
248272
toggle_trust "$mac"
249273
;;
274+
"$blocked")
275+
toggle_blocked "$mac"
276+
;;
250277
"$goback")
251278
show_menu
252279
;;

0 commit comments

Comments
 (0)