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

@ -1,77 +1,86 @@
{ {
"layer": "top", "layer": "top",
"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": [
"sway/workspaces": { "pulseaudio",
"disable-scroll": true, "custom/network",
"all-outputs": true "backlight",
}, "battery",
"sway/mode": { "clock",
"format": "<span style=\"italic\">{}</span>" "tray",
}, "idle_inhibitor"
"idle_inhibitor": { ],
"format": "{icon}", "sway/workspaces": {
"format-icons": { "disable-scroll": true,
"activated": "", "all-outputs": true
"deactivated": "" },
} "sway/mode": {
}, "format": "<span style=\"italic\">{}</span>"
"tray": { },
"spacing": 10 "idle_inhibitor": {
}, "format": "{icon}",
"clock": { "format-icons": {
"tooltip-format": "{:%Y-%m-%d | %H:%M}", "activated": "",
"format-alt": "{:%Y-%m-%d}" "deactivated": ""
},
"backlight": {
"format": "{icon} {percent}% ",
"format-icons": ["", "", "", ""]
},
"battery": {
"interval": 1,
"states": {
"good": 95,
"warning": 30,
"critical": 15
},
"format": " {capacity}%",
"format-discharging": "{icon} {capacity}%",
"format-icons": ["", "", "", "", ""]
},
"pulseaudio": {
"format": "{icon} {volume}%",
"format-bluetooth": "{volume}% {icon}",
"format-muted": "",
"format-icons": {
"headphones": "",
"handsfree": "",
"headset": "",
"phone": "",
"portable": "",
"car": "",
"default": ["", ""]
},
"on-click": "pavucontrol"
},
"custom/media": {
"format": "{icon} {}",
"return-type": "json",
"max-length": 40,
"format-icons": {
"spotify": "",
"default": "🎜"
},
"on-click": "playerctl play-pause",
"escape": true,
"exec": "$HOME/.config/waybar/custom_modules/mediaplayer.py 2> /dev/null"
},
"custom/network": {
"escape" :true,
"exec": "$HOME/.config/waybar/custom_modules/wifi.sh 2> /dev/null",
"on-click": "rofi-wifi-menu",
"restart-interval": 1,
"return-type": "json"
} }
},
"tray": {
"spacing": 10
},
"clock": {
"tooltip-format": "{:%Y-%m-%d | %H:%M}",
"format-alt": "{:%Y-%m-%d}"
},
"backlight": {
"format": "{icon} {percent}% ",
"format-icons": ["", "", "", ""]
},
"battery": {
"interval": 1,
"states": {
"good": 95,
"warning": 30,
"critical": 15
},
"format": " {capacity}%",
"format-discharging": "{icon} {capacity}%",
"format-icons": ["", "", "", "", ""]
},
"pulseaudio": {
"format": "{icon} {volume}%",
"format-bluetooth": "{volume}% {icon}",
"format-muted": "",
"format-icons": {
"headphones": "",
"handsfree": "",
"headset": "",
"phone": "",
"portable": "",
"car": "",
"default": ["", ""]
},
"on-click": "pavucontrol"
},
"custom/media": {
"format": "{icon} {}",
"return-type": "json",
"max-length": 40,
"format-icons": {
"spotify": "",
"default": "🎜"
},
"on-click": "playerctl play-pause",
"escape": true,
"exec": "$HOME/.config/waybar/custom_modules/mediaplayer.py 2> /dev/null"
},
"custom/network": {
"escape": true,
"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,21 +1,31 @@
#! /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
wg_val="$(wg 2> /dev/null ; echo $?)"
if [ "$wg_val" -eq 0 ]; then
echo "{\"text\": \" $(iwgetid -r)\", \"class\":\"connected\"}"
else else
wg_val="$(wg 2> /dev/null ; echo $?)" echo "{\"text\": \"聯 $(iwgetid -r)\", \"class\":\"secured\"}"
if [ $wg_val -eq 0 ]; then
echo "{\"text\": \" $(iwgetid -r)\", \"class\":\"connected\"}"
else
echo "{\"text\": \"聯 $(iwgetid -r)\", \"class\":\"secured\"}"
fi
fi 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