Files
Nomarchy/themes/engine/scripts/nomarchy-toggle-nightlight
Bernardo Magri dc3346bc55
Some checks failed
Check / eval-and-lint (push) Has been cancelled
feat: implement hybrid declarative state with automatic Nix sync
2026-05-31 20:09:12 +01:00

31 lines
1.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -e
# Toggles the nightlight (hyprsunset). Writes the new state to state.json
# (so the next home-manager rebuild realigns services.hyprsunset.enable
# via features/desktop/nightlight.nix) and flips the running systemd
# user unit for instant feedback. Reads nightlightTemperature from
# state.json so the value the user picked is honoured instead of a
# hardcoded constant.
STATE_DIR="$HOME/.config/nomarchy"
STATE_FILE="$STATE_DIR/state.json"
mkdir -p "$STATE_DIR"
[[ ! -f $STATE_FILE ]] && echo "{}" > "$STATE_FILE"
if [[ $NOMARCHY_TOGGLE_NIGHTLIGHT == "false" ]]; then
NEW_VALUE="true"
systemctl --user start hyprsunset.service 2>/dev/null || true
TEMP=$(jq -r '.nightlightTemperature // 4000' "$STATE_FILE")
notify-send -u low " Nightlight enabled (${TEMP}K)"
else
NEW_VALUE="false"
systemctl --user stop hyprsunset.service 2>/dev/null || true
notify-send -u low " Nightlight disabled"
fi
nomarchy-state-write nightlight "$NEW_VALUE" --type bool
echo "Nightlight state set to $NEW_VALUE."