aboutsummaryrefslogtreecommitdiff
path: root/dotfiles/hyprland/.local/bin/waybar-airplane
blob: 21f869c57ed71c162b7b87f984fa6e216c51dd97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/sh
# Airplane-mode indicator for waybar.
# Reads the state file the airplane-mode toggle maintains; emits one JSON line
# (text + tooltip + class) for the custom/airplane module. The file holds
# key=value lines; only `mode` (on/off) matters here. Anything other than
# "on" reads as off, so a missing or garbled state file fails safe (airplane
# mode shown as inactive — i.e. radios assumed on).
#
# Laptop-only: airplane mode is meaningless on a desktop, so the module hides
# itself (emits nothing → waybar drops it) on machines with no battery.

STATE_FILE="${XDG_RUNTIME_DIR:-/tmp}/airplane-state"
PS_DIR="${AIRPLANE_POWER_SUPPLY_DIR:-/sys/class/power_supply}"

# Laptop check: a battery present means this is a portable machine.
is_laptop() {
    for b in "$PS_DIR"/BAT*; do
        [ -e "$b" ] && return 0
    done
    return 1
}

is_laptop || exit 0

mode=$(sed -n 's/^mode=//p' "$STATE_FILE" 2>/dev/null | head -n1)

# Same clear plane glyph in both states; the class drives the color (gold when
# engaged, default gray when not) so there's no slash to obscure the wings.
if [ "$mode" = "on" ]; then
    echo "{\"text\": \"<span size='large'></span>\", \"tooltip\": \"Airplane mode ON — wifi off, low power\", \"class\": \"active\"}"
else
    echo "{\"text\": \"<span size='large'></span>\", \"tooltip\": \"Airplane mode OFF\", \"class\": \"inactive\"}"
fi