omarchy/bin/omarchy-status-daemon
David Heinemeier Hansson 210481d758 Style
2025-08-23 21:21:00 +02:00

65 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
# Status indicator daemon for waybar
# Calls individual status scripts and caches results
STATE_DIR=~/.local/state/omarchy/status
DAEMON_PID_FILE="$STATE_DIR/daemon.pid"
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
mkdir -p "$STATE_DIR"
# Update all status files by calling individual scripts
update_all_status_files() {
"$SCRIPT_DIR/omarchy-status-dnd" >"$STATE_DIR/dnd"
"$SCRIPT_DIR/omarchy-status-nightlight" >"$STATE_DIR/nightlight"
"$SCRIPT_DIR/omarchy-status-recording" >"$STATE_DIR/recording"
"$SCRIPT_DIR/omarchy-status-idle" >"$STATE_DIR/idle"
}
# Generate hash for change detection
get_status_hash() {
echo "$(pgrep -c "mako|hyprsunset|wl-screenrec|wf-recorder|obs|hypridle" 2>/dev/null)$(makoctl mode 2>/dev/null | grep -c 'do-not-disturb')$(hyprctl hyprsunset temperature 2>/dev/null)"
}
# Start background monitoring daemon
start_daemon() {
if [ -f "$DAEMON_PID_FILE" ] && kill -0 $(cat "$DAEMON_PID_FILE") 2>/dev/null; then
return 0
fi
{
last_hash=""
while true; do
current_hash=$(get_status_hash)
if [ "$current_hash" != "$last_hash" ]; then
update_all_status_files
last_hash="$current_hash"
fi
sleep 0.5
done
} &
echo $! >"$DAEMON_PID_FILE"
}
# Main execution
MODULE="$1"
if [ -z "$MODULE" ]; then
echo "Usage: $0 [dnd|nightlight|recording|idle]"
exit 1
fi
start_daemon
# Return cached status for requested module
if [ -f "$STATE_DIR/$MODULE" ]; then
cat "$STATE_DIR/$MODULE"
else
update_all_status_files
cat "$STATE_DIR/$MODULE" 2>/dev/null || echo '{"text": "", "tooltip": "", "class": "hidden"}'
fi