From f511670032a2174b5ff2a2ff35dcb1995f0fb2e3 Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sun, 4 Jun 2023 01:39:41 -0500 Subject: [PATCH] refactor(waybar): improvements for network status This includes a script to toggle all wireless devices --- dots/.config/waybar/config | 3 +- dots/.config/waybar/scripts/set-rfkill.bash | 51 +++++++++++++++++++++ dots/.config/waybar/style.css | 6 ++- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100755 dots/.config/waybar/scripts/set-rfkill.bash diff --git a/dots/.config/waybar/config b/dots/.config/waybar/config index 0cc3eb8d..c36d5c71 100644 --- a/dots/.config/waybar/config +++ b/dots/.config/waybar/config @@ -97,13 +97,14 @@ "on-click": "swaylock" }, "network": { - "on-click-right": "iwctl station wlan0 disconnect", + "on-click-right": "~/.config/waybar/scripts/set-rfkill.bash", "interval": 1, "format-alt": " {bandwidthUpBytes} |  {bandwidthDownBytes}", "format-disconnected": "{icon} Disconnected", "format-linked": " {ifname} | ↕ {bandwidthTotalBytes}", "format-wifi": "{icon} {essid} | ↕ {bandwidthTotalBytes}", "format-ethernet": "{icon} {ipaddr}/{cidr} | ↕ {bandwidthTotalBytes}", + "format-disabled": "󰀝 Wireless Networking Disabled", "tooltip-format": "{ifname}: {ipaddr}/{cidr} 󰌹 {gwaddr}", "format-icons": { "ethernet": "󰈀", diff --git a/dots/.config/waybar/scripts/set-rfkill.bash b/dots/.config/waybar/scripts/set-rfkill.bash new file mode 100755 index 00000000..4af57846 --- /dev/null +++ b/dots/.config/waybar/scripts/set-rfkill.bash @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +main () { + local notify_application_name="RF Status" + local enable_airplane_mode=true + + local unblocked_devices="" + + local rf_soft_status + local rf_hard_status + local device + local device_type + + + for rf_status in $(rfkill -J | jq '.rfkilldevices[]' | jq -r tostring); do + rf_soft_status="$(printf "%s" "${rf_status}" | jq -r '.soft')" + rf_hard_status="$(printf "%s" "${rf_status}" | jq -r '.hard')" + device="$(printf "%s" "${rf_status}" | jq -r '.device')" + device_type="$(printf "%s" "${rf_status}" | jq -r '.type')" + printf "RF Status JSON: %s\n" "${rf_status}" + + if [[ "${rf_soft_status}" == "blocked" ]]; then + enable_airplane_mode=false + unblocked_devices+=" - ${device} (${device_type})\n" + fi + + if [[ "${rf_hard_status}" == "blocked" ]]; then + notify-send " Hard Block Detected In Network Device" "${device} (${device_type}) has a hard block!" -a "${notify_application_name}" -u "critical" + fi + done + + if [[ "${enable_airplane_mode}" = true ]]; then + printf "Airplane mode to be enabled\n" + if rfkill block all; then + notify-send "󱡻 Enabled Airplane Mode" "All wireless network devices have been blocked!" -a "${notify_application_name}" + else + notify-send "󱡺 Failed to Enable Airplane Mode" "An error has occurred! Unable to modify rf status of some devices" -a "${notify_application_name}" -u "critical" + fi + else + printf "Airplane mode to be disabled\n" + if rfkill unblock all; then + notify-send "󱢂 Disabled Airplane Mode" "Unblocked Devices:\n${unblocked_devices}" -a "${notify_application_name}" + else + notify-send "󱡺 Failed to Disable Airplane Mode" "An error has occurred! Unable to modify rf status of some devices!" -a "${notify_application_name}" -u "critical" + fi + fi + + +} + +main diff --git a/dots/.config/waybar/style.css b/dots/.config/waybar/style.css index 79366c5b..258156a4 100644 --- a/dots/.config/waybar/style.css +++ b/dots/.config/waybar/style.css @@ -259,9 +259,13 @@ color: #e6c384; } +#network.disabled { + color: #FF5D62; +} + /* Clock */ #clock { - color: #ff5d62; + color: #FF9E3B; } /* Lock */