refactor and adding custom wifi module.

This commit is contained in:
James Patrick 2020-09-16 22:08:52 -04:00
parent 4e5cb3baad
commit 50ef9fd177
2 changed files with 30 additions and 14 deletions

View File

@ -3,7 +3,7 @@
"height": 35,
"modules-left": ["sway/workspaces", "sway/mode", "custom/media"],
"modules-center": ["sway/window"],
"modules-right": ["pulseaudio", "network", "cpu", "memory", "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
@ -25,12 +25,6 @@
"tooltip-format": "{:%Y-%m-%d | %H:%M}",
"format-alt": "{:%Y-%m-%d}"
},
"cpu": {
"format": " {usage}%"
},
"memory": {
"format": " {}%"
},
"backlight": {
"format": "{icon} {percent}% ",
"format-icons": ["", "", "", ""]
@ -43,15 +37,9 @@
"critical": 15
},
"format": " {capacity}%",
"format-discharging": "{icon} {capacity}%",
"format-discharging": "{icon} {capacity}%",
"format-icons": ["", "", "", "", ""]
},
"network": {
"format-wifi": " {essid} ({signalStrength}%)",
"format-ethernet": "{ifname}: {ipaddr}/{cidr} ",
"format-disconnected": "⚠",
"on-click": "rofi-wifi-menu"
},
"pulseaudio": {
"format": "{icon} {volume}%",
"format-bluetooth": "{volume}% {icon}",
@ -78,5 +66,12 @@
"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"
}
}

21
waybar/custom_modules/wifi.sh Executable file
View File

@ -0,0 +1,21 @@
#! /usr/bin/env bash
main(){
connected_val="$(iwgetid 1> /dev/null ; echo $?)"
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
echo "{\"text\": \" $(iwgetid -r)\", \"class\":\"connected\"}"
else
echo "{\"text\": \"聯 $(iwgetid -r)\", \"class\":\"secured\"}"
fi
fi
}
while true; do
main
sleep 1
done