From ddad32b4328e287699b6dcd74bc88dcc1eb02a96 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 8 Apr 2023 15:16:14 +0200 Subject: [PATCH] some more improvements, these will have to be rewritten though --- src/speedwm-btctrl | 6 ++-- src/speedwm-netctrl | 68 ++++++++++++++++++++++++--------------------- 2 files changed, 40 insertions(+), 34 deletions(-) diff --git a/src/speedwm-btctrl b/src/speedwm-btctrl index 8d83fff..1eeee4a 100755 --- a/src/speedwm-btctrl +++ b/src/speedwm-btctrl @@ -20,8 +20,8 @@ NOTIFY_DISCONNECT() { SEND_NOTIF " Disconnected" " Disconnected from ${SEL NOTIFY_REMOVE() { SEND_NOTIF " Removed" " Removed device ${SELDEVICE}!"; } # Misc functions -LIST_OPTIONS() { SELDEVICE_ACTION="$(printf -- "-- Options --\nConnect\nDisconnect\n-- Toggle --\nPair\nRemove\nTrust\nUntrust\n------\nAbout\nExit" | sed "s/-e //g" | $RUNLAUNCHER -g 1 -l 20 -p "What do you want to do with this device?" | awk '{ print $1 }')"; } -ABOUT() { printf -- "speedwm-btctrl\ndmenu bluez frontend\n------\nVersion %s\n" "$([ -e "/usr/share/speedwm/speedwm-extras-version" ] && cat /usr/share/speedwm/speedwm-extras-version || printf "1.9")" | $RUNLAUNCHER -l 40 -g 1 -p 'About'; pkill bluetoothctl; exit 0; } +LIST_OPTIONS() { SELDEVICE_ACTION="$(printf -- "-- Options --\nConnect\nDisconnect\n-- Toggle --\nPair\nRemove\nTrust\nUntrust\n‎\nAbout\nExit" | sed "s/-e //g" | $RUNLAUNCHER -g 1 -l 20 -p "What do you want to do with this device?" | awk '{ print $1 }')"; } +ABOUT() { printf -- "speedwm-btctrl\nspmenu bluez frontend\n‎\nVersion %s\n" "$([ -e "/usr/share/speedwm/speedwm-extras-version" ] && cat /usr/share/speedwm/speedwm-extras-version || printf "1.9")" | $RUNLAUNCHER -l 40 -g 1 -p 'About'; pkill bluetoothctl; exit 0; } SEND_NOTIF() { [ "$NOTIF_SYSTEM" = "dnote" ] && command -v dnote && [ ! -z "$*" ] && printf "$2\n" | dnote -loc 4 && exit 1 || command -v notify-send && notify-send "$1" "$2" > /dev/null; } # Enable bluetooth and scan for devices @@ -30,7 +30,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 - SELDEVICE="$(printf "$(bluetoothctl devices | cut -d\ -f3-)\n------\nRefresh\nAbout\nExit" | $RUNLAUNCHER -l 12 -g 1 -p "Select a device")" + SELDEVICE="$(printf "$(bluetoothctl devices | cut -d\ -f3-)\n‎\nRefresh\nAbout\nExit" | $RUNLAUNCHER -l 12 -g 1 -p "Select a device")" # Check what to do case "$SELDEVICE" in diff --git a/src/speedwm-netctrl b/src/speedwm-netctrl index 6f4aac7..d9cef0f 100755 --- a/src/speedwm-netctrl +++ b/src/speedwm-netctrl @@ -3,29 +3,26 @@ # spmenu/other run launcher GUI for iwd # Licensed under the GNU GPLv3 free software license. -case "$RUNLAUNCHER" in -"") RUNLAUNCHER=spmenu ;; -esac - -BINDIR="$(dirname $(command -v speedwm-winnav))/" +RUNLAUNCHER="${RUNLAUNCHER:-spmenu}" +BINDIR="${BINDIR:-/usr/bin/}" command -v iwctl > /dev/null || exit 1 # Get the device used to connect. getdevice() { - seldevice=$1 + seldevice="$1" if [ -e "$HOME/.local/share/seldevice" ]; then - seldevice=$(cat $HOME/.local/share/seldevice) + seldevice="$(cat "$HOME/.local/share/seldevice")" else case "$1" in - "") devices="$(printf "\n$(ip link)" | awk '{ print $2 }' | awk 'NR%2==0' | sed "s/://g")" - seldevice=$(echo $devices | sed 's/ /\n/g' | $RUNLAUNCHER -p "What device do you want to connect with?" -l 10 -g 1) && echo $seldevice > $HOME/.local/share/seldevice ;; + "") devices="$(printf "$(ip link)" | awk '{ print $2 }' | awk 'NR%2==0' | sed "s/://g")" + seldevice=$(echo $devices | sed 's/ /\n/g' | $RUNLAUNCHER -p "What device do you want to connect with?" -l 10 -g 1) && echo "$seldevice" > $HOME/.local/share/seldevice ;; esac fi - case "$seldevice" in - "") exit 0 ;; - esac + touch "$HOME/.local/share/networks" + + #[ -z "$seldevice" ] && exit 0 } # connect to wifi @@ -34,42 +31,51 @@ connectwifi() { # if it is disconnect, disconnect if [ "$INARGS" != "disconnect" ]; then iwctl station $seldevice scan - network="$(printf "$(iwctl station $seldevice get-networks | sed -n 6,20p | sed "s|>||g" | awk '{ print $1 }')\nDisconnect\n------\nExit" | sed "s| |No networks found|g" | $RUNLAUNCHER -l 10 -g 1 -p "Select a network to connect to" | sed "s|------||g" | sed "s|No networks found| |g")" + network="$(printf "%s\n‎\nRefresh\nDisconnect\nExit" \ + "$(iwctl station "$seldevice" get-networks | sed -n 6,20p | sed "s|>||g" | awk '{ print $1 }')" | sed "s| |No networks found|g" | \ + $RUNLAUNCHER -l 10 -g 1 -p "Select a network to connect to" | sed "s|‎||g")" + # check output case "$network" in - "") exit 0 ;; - "Disconnect") disconnect=true ;; - "Exit") exit 0 ;; + "") exit 0 ;; + "No networks found") exit 0 ;; + "Disconnect") disconnect=true ;; + "Exit") exit 0 ;; + "Refresh") getdevice "$@" && connectwifi "$@" ;; esac else disconnect=true fi if [ "$disconnect" != "true" ]; then - iwctl station $seldevice get-networks | grep "$network" > /dev/null || exit 1 + iwctl station "$seldevice" get-networks | grep "$network" > /dev/null || exit 1 connect_pass() { - PASSPHRASE=$(printf "\n" | $RUNLAUNCHER -p "This network is protected. Enter the passphrase." -l 1 -g 1 -P) - case "$PASSPHRASE" in - "") exit 0 ;; - esac + iwctl station "$seldevice" disconnect + passphrase=$(printf "\n" | $RUNLAUNCHER -p "This network is protected. Enter the passphrase." -l 1 -g 1 -P -im) + [ -z "$passphrase" ] && exit 0 - printf "$network\n" >> $HOME/.local/share/networks + printf "%s\n" "$network" >> "$HOME/.local/share/networks" + + # in case of wrong password + wrong_pass() { + [ -x "$(command -v notify-send)" ] && notify-send " Wrong password" "Wrong password, try again." + connect_pass "$@" + } + + iwctl station "$seldevice" connect "$network" -P "$passphrase" || wrong_pass "$@" + [ -x "$(command -v notify-send)" ] && notify-send " Connected to '$network'!" - iwctl station $seldevice connect $network -P $PASSPHRASE || connect_pass - if [ -e "${BINDIR}notify-send" ]; then - notify-send " Connected to $network!" - fi exit 0 } connect_no_pass() { - iwctl station $seldevice connect $network && notify-send " Connected to $network!" || exit + iwctl station "$seldevice" connect "$network" && notify-send " Connected to '$network'!" || exit } fi disconnect() { - iwctl station $seldevice disconnect + iwctl station "$seldevice" disconnect if [ -e "${BINDIR}notify-send" ]; then notify-send " Disconnected from the network!" fi @@ -77,8 +83,8 @@ connectwifi() { } if [ "$disconnect" != "true" ]; then - grep $network $HOME/.local/share/networks && connect_no_pass && exit 0 - iwctl station $seldevice get-networks | grep psk && connect_pass && exit 0 + grep -q "$network" "$HOME/.local/share/networks" && connect_no_pass && exit 0 + iwctl station "$seldevice" get-networks | grep -q psk && connect_pass && exit 0 else disconnect fi @@ -86,4 +92,4 @@ connectwifi() { INARGS="$1" getdevice "$@" && connectwifi "$@" -pgrep -x status > /dev/null && pkill status && status & +pgrep -x speedwm_status > /dev/null && pkill speedwm_status && speedwm_status &