feat(nightlight): persistent off via state marker
A manual `off` now drops ~/.local/state/nomarchy/nightlight-off and the hyprsunset unit refuses to (re)start while it exists (Unit.ConditionPathExists=!%h/...), so the off survives logout/reboot until toggled back on. `on`/toggle-on remove the marker before starting (a failed condition would otherwise no-op the start). Without the marker behaviour is unchanged: the service stays WantedBy=graphical-session.target and resumes its schedule at login, so persistence is opt-in via the toggle. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -21,6 +21,12 @@ let
|
||||
# module hides itself — same pattern as the power-profile indicator.
|
||||
nomarchy-nightlight = pkgs.writeShellScriptBin "nomarchy-nightlight" ''
|
||||
unit=hyprsunset.service
|
||||
# Persistent-off marker — mirrors the unit's ConditionPathExists below.
|
||||
# Present => night-light stays off across logout/reboot until toggled on.
|
||||
# Path is literal (not XDG_STATE_HOME) so it matches the unit's %h check.
|
||||
marker="$HOME/.local/state/nomarchy/nightlight-off"
|
||||
mark_off() { mkdir -p "$(dirname "$marker")"; : > "$marker"; }
|
||||
mark_on() { rm -f "$marker"; }
|
||||
if ! systemctl --user cat "$unit" >/dev/null 2>&1; then
|
||||
[ "''${1:-}" = status ] && exit 0
|
||||
notify-send "Night light" "Not enabled — set nomarchy.nightlight.enable."
|
||||
@@ -33,14 +39,14 @@ let
|
||||
else
|
||||
printf '{"text":"","tooltip":"Night light off (click to enable)","class":"off"}\n'
|
||||
fi ;;
|
||||
on) systemctl --user start "$unit" ;;
|
||||
off) systemctl --user stop "$unit" ;;
|
||||
on) mark_on; systemctl --user start "$unit" ;;
|
||||
off) mark_off; systemctl --user stop "$unit" ;;
|
||||
toggle)
|
||||
if systemctl --user is-active --quiet "$unit"; then
|
||||
systemctl --user stop "$unit"
|
||||
notify-send "Night light off" "Screen back to true colours."
|
||||
mark_off; systemctl --user stop "$unit"
|
||||
notify-send "Night light off" "Screen back to true colours (stays off until re-enabled)."
|
||||
else
|
||||
systemctl --user start "$unit"
|
||||
mark_on; systemctl --user start "$unit"
|
||||
notify-send "Night light on" "Warm filter follows your schedule."
|
||||
fi ;;
|
||||
*) echo "usage: nomarchy-nightlight [toggle|status|on|off]" >&2; exit 64 ;;
|
||||
@@ -59,6 +65,13 @@ in
|
||||
];
|
||||
};
|
||||
|
||||
# Persistent off: a manual `off` drops ~/.local/state/nomarchy/nightlight-off,
|
||||
# and this Condition makes the unit refuse to (re)start while it exists — so
|
||||
# an off survives logout/reboot. `nomarchy-nightlight on` removes it first
|
||||
# (a failed condition would otherwise no-op the start). %h = $HOME.
|
||||
systemd.user.services.hyprsunset.Unit.ConditionPathExists =
|
||||
lib.mkIf cfg.enable "!%h/.local/state/nomarchy/nightlight-off";
|
||||
|
||||
# Always on PATH (it self-gates at runtime), so a static whole-swap Waybar
|
||||
# can exec it even when night-light is off without the call failing.
|
||||
home.packages = [ nomarchy-nightlight ];
|
||||
|
||||
Reference in New Issue
Block a user