From 70a8af11d2c79e489d71d3929f7b6e0d5f73cf5e Mon Sep 17 00:00:00 2001 From: default Date: Sun, 1 Sep 2024 15:11:11 +0530 Subject: [PATCH] Add prompt to confirm disconnection if Bluetooth device is already connected - Added logic to check if a selected Bluetooth device is currently connected. - If the device is connected, prompt the user with a confirmation dialog via dmenu. - If the user confirms, the script switches to disconnect mode and disconnects the device. - If the user cancels, the disconnection process is aborted. --- btmenu | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/btmenu b/btmenu index 6de9fb9..8a46181 100755 --- a/btmenu +++ b/btmenu @@ -61,6 +61,30 @@ execute_mode() { [[ $name ]] || return mac=${DEVICES["$name"]} + + # Check if the device is already connected + if printf 'info %s\n' "$mac" | _bluetoothctl | grep -Pq '^[\t ]+Connected: yes'; then + # Prompt to disconnect if already connected + if echo -e "yes\nno" | dmenu -p "$name is already connected. Disconnect?" | grep -q "^yes$"; then + mode=disconnect + else + notify "Cancelled disconnecting from $name" + return 0 + fi + fi + + case $mode in + connect) + preposition=to + expected_to_connect=yes + ;; + disconnect) + preposition=from + expected_to_connect=no + ;; + esac + + notify "Attempting to $mode $preposition $name" while (( retries-- )); do