some more improvements, these will have to be rewritten though

This commit is contained in:
speedie 2023-04-08 15:16:14 +02:00
parent d88dfa171d
commit ddad32b432
2 changed files with 40 additions and 34 deletions

View file

@ -20,8 +20,8 @@ NOTIFY_DISCONNECT() { SEND_NOTIF " Disconnected" " Disconnected from ${SEL
NOTIFY_REMOVE() { SEND_NOTIF " Removed" " Removed device ${SELDEVICE}!"; } NOTIFY_REMOVE() { SEND_NOTIF " Removed" " Removed device ${SELDEVICE}!"; }
# Misc functions # 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 }')"; } 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; } 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; } 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 # Enable bluetooth and scan for devices
@ -30,7 +30,7 @@ ENABLE_BT() {
bluetoothctl scan on & # Start scanning for devices bluetoothctl scan on & # Start scanning for devices
bluetoothctl devices | grep -q "No default controller" && printf "No Bluetooth controller was found.\n" && exit 1 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 # Check what to do
case "$SELDEVICE" in case "$SELDEVICE" in

View file

@ -3,29 +3,26 @@
# spmenu/other run launcher GUI for iwd # spmenu/other run launcher GUI for iwd
# Licensed under the GNU GPLv3 free software license. # Licensed under the GNU GPLv3 free software license.
case "$RUNLAUNCHER" in RUNLAUNCHER="${RUNLAUNCHER:-spmenu}"
"") RUNLAUNCHER=spmenu ;; BINDIR="${BINDIR:-/usr/bin/}"
esac
BINDIR="$(dirname $(command -v speedwm-winnav))/"
command -v iwctl > /dev/null || exit 1 command -v iwctl > /dev/null || exit 1
# Get the device used to connect. # Get the device used to connect.
getdevice() { getdevice() {
seldevice=$1 seldevice="$1"
if [ -e "$HOME/.local/share/seldevice" ]; then if [ -e "$HOME/.local/share/seldevice" ]; then
seldevice=$(cat $HOME/.local/share/seldevice) seldevice="$(cat "$HOME/.local/share/seldevice")"
else else
case "$1" in case "$1" in
"") devices="$(printf "\n$(ip link)" | awk '{ print $2 }' | awk 'NR%2==0' | sed "s/://g")" "") 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 ;; 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 esac
fi fi
case "$seldevice" in touch "$HOME/.local/share/networks"
"") exit 0 ;;
esac #[ -z "$seldevice" ] && exit 0
} }
# connect to wifi # connect to wifi
@ -34,42 +31,51 @@ connectwifi() {
# if it is disconnect, disconnect # if it is disconnect, disconnect
if [ "$INARGS" != "disconnect" ]; then if [ "$INARGS" != "disconnect" ]; then
iwctl station $seldevice scan 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 case "$network" in
"") exit 0 ;; "") exit 0 ;;
"Disconnect") disconnect=true ;; "No networks found") exit 0 ;;
"Exit") exit 0 ;; "Disconnect") disconnect=true ;;
"Exit") exit 0 ;;
"Refresh") getdevice "$@" && connectwifi "$@" ;;
esac esac
else else
disconnect=true disconnect=true
fi fi
if [ "$disconnect" != "true" ]; then 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() { connect_pass() {
PASSPHRASE=$(printf "\n" | $RUNLAUNCHER -p "This network is protected. Enter the passphrase." -l 1 -g 1 -P) iwctl station "$seldevice" disconnect
case "$PASSPHRASE" in passphrase=$(printf "\n" | $RUNLAUNCHER -p "This network is protected. Enter the passphrase." -l 1 -g 1 -P -im)
"") exit 0 ;; [ -z "$passphrase" ] && exit 0
esac
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 exit 0
} }
connect_no_pass() { 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 fi
disconnect() { disconnect() {
iwctl station $seldevice disconnect iwctl station "$seldevice" disconnect
if [ -e "${BINDIR}notify-send" ]; then if [ -e "${BINDIR}notify-send" ]; then
notify-send " Disconnected from the network!" notify-send " Disconnected from the network!"
fi fi
@ -77,8 +83,8 @@ connectwifi() {
} }
if [ "$disconnect" != "true" ]; then if [ "$disconnect" != "true" ]; then
grep $network $HOME/.local/share/networks && connect_no_pass && exit 0 grep -q "$network" "$HOME/.local/share/networks" && connect_no_pass && exit 0
iwctl station $seldevice get-networks | grep psk && connect_pass && exit 0 iwctl station "$seldevice" get-networks | grep -q psk && connect_pass && exit 0
else else
disconnect disconnect
fi fi
@ -86,4 +92,4 @@ connectwifi() {
INARGS="$1" INARGS="$1"
getdevice "$@" && connectwifi "$@" getdevice "$@" && connectwifi "$@"
pgrep -x status > /dev/null && pkill status && status & pgrep -x speedwm_status > /dev/null && pkill speedwm_status && speedwm_status &