Added wifi click behavior.

This commit is contained in:
James Patrick 2020-12-08 22:02:44 -05:00
parent f0fd387fbf
commit aee151dbb9
2 changed files with 108 additions and 89 deletions

View File

@ -3,7 +3,15 @@
"height": 35,
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
"modules-center": ["sway/window"],
"modules-right": ["pulseaudio", "custom/network","backlight", "battery", "clock", "tray", "idle_inhibitor"],
"modules-right": [
"pulseaudio",
"custom/network",
"backlight",
"battery",
"clock",
"tray",
"idle_inhibitor"
],
"sway/workspaces": {
"disable-scroll": true,
"all-outputs": true
@ -69,8 +77,9 @@
},
"custom/network": {
"escape": true,
"exec": "$HOME/.config/waybar/custom_modules/wifi.sh 2> /dev/null",
"exec": "$HOME/.config/waybar/custom_modules/wifi.sh status 2> /dev/null",
"on-click": "rofi-wifi-menu",
"on-click-right": "swaymsg exec \"~/.config/sway/scripts/tty-popup tunnel ~/.config/waybar/custom_modules/wifi.sh onclick\"",
"restart-interval": 1,
"return-type": "json"
}

View File

@ -1,13 +1,13 @@
#! /usr/bin/env bash
main(){
status(){
connected_val="$(iwgetid 1> /dev/null ; echo $?)"
if [ $connected_val -eq 255 ]; then
if [ "$connected_val" -eq 255 ]; then
echo '{"text": "⚠ Disconnected", "class":"disconnected"}'
return
else
wg_val="$(wg 2> /dev/null ; echo $?)"
if [ $wg_val -eq 0 ]; then
if [ "$wg_val" -eq 0 ]; then
echo "{\"text\": \" $(iwgetid -r)\", \"class\":\"connected\"}"
else
echo "{\"text\": \"聯 $(iwgetid -r)\", \"class\":\"secured\"}"
@ -15,7 +15,17 @@ main(){
fi
}
while true; do
main
sleep 1
done
onclick(){
wg_val="$(wg 2> /dev/null ; echo $?)"
if [ "$wg_val" -eq 0 ]; then
echo "Securing Connection"
wg-quick up mullvad-us18
else
echo "Disconnecting tunnel"
wg-quick down mullvad-us18
fi
}
case "$1" in
onclick|status) $1 ;;
esac