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, "height": 35,
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"], "modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
"modules-center": ["sway/window"], "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": { "sway/workspaces": {
"disable-scroll": true, "disable-scroll": true,
"all-outputs": true "all-outputs": true
@ -68,9 +76,10 @@
"exec": "$HOME/.config/waybar/custom_modules/mediaplayer.py 2> /dev/null" "exec": "$HOME/.config/waybar/custom_modules/mediaplayer.py 2> /dev/null"
}, },
"custom/network": { "custom/network": {
"escape" :true, "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": "rofi-wifi-menu",
"on-click-right": "swaymsg exec \"~/.config/sway/scripts/tty-popup tunnel ~/.config/waybar/custom_modules/wifi.sh onclick\"",
"restart-interval": 1, "restart-interval": 1,
"return-type": "json" "return-type": "json"
} }

View File

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