nixos/pkgs/eww-hyprland/scripts/airplane

41 lines
982 B
Bash
Executable file

#!/usr/bin/env bash
# shellcheck source=/dev/null
source "$(dirname "$0")"/utils
STATUS="$(rfkill list | sed -n 2p | awk '{print $3}')"
icon() {
[ "$STATUS" = "no" ] && echo "" || echo ""
}
toggle() {
if [ "$STATUS" = "no" ]; then
rfkill block all
notify-send --urgency=normal -i airplane-mode-symbolic "Airplane Mode" "Airplane mode has been turned on!"
else
rfkill unblock all
notify-send --urgency=normal -i airplane-mode-disabled-symbolic "Airplane Mode" "Airplane mode has been turned off!"
fi
}
if [ "$1" = "toggle" ]; then
toggle
else
last_time=$(get_time_ms)
STATUS="$(rfkill list | sed -n 2p | awk '{print $3}')"
icon
rfkill event | while read -r _; do
current_time=$(get_time_ms)
delta=$((current_time - last_time))
# 50ms debounce
if [[ $delta -gt 50 ]]; then
STATUS="$(rfkill list | sed -n 2p | awk '{print $3}')"
icon
# reset debounce timer
last_time=$(get_time_ms)
fi
done
fi