-
Notifications
You must be signed in to change notification settings - Fork 0
feat(night-shift): default Night Shift to always on #2091
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/usr/bin/env bash | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| nightlight_bin="@nightlightBin@" | ||
| temperature=@temperature@ | ||
|
|
||
| # A sunset-to-sunrise schedule turns Night Shift back off at sunrise, so the | ||
| # schedule has to be cleared before `on` can mean "stays on". | ||
| "$nightlight_bin" schedule stop | ||
| "$nightlight_bin" temp "$temperature" | ||
| "$nightlight_bin" on | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| { pkgs }: | ||
| let | ||
| # 0 = least warm, 100 = warmest. | ||
| temperature = 100; | ||
|
|
||
| applyNightShiftScript = pkgs.replaceVars ./apply-night-shift.sh { | ||
| nightlightBin = "${pkgs.nightlight}/bin/nightlight"; | ||
| inherit temperature; | ||
| }; | ||
| in | ||
| { | ||
| # Night Shift state lives in the per-user CoreBrightness session and is not | ||
| # exposed through any plist `system.defaults` can write, so the only way to | ||
| # express "on by default" is to talk to that session on login. | ||
| # | ||
| # RunAtLoad without a StartInterval deliberately makes this a default rather | ||
| # than an enforcement: a manual toggle sticks until the next login. | ||
| launchd.agents.night-shift = pkgs.lib.mkIf pkgs.stdenv.isDarwin { | ||
| enable = true; | ||
| config = { | ||
| ProgramArguments = [ | ||
| "${pkgs.bash}/bin/bash" | ||
| "${applyNightShiftScript}" | ||
| ]; | ||
| RunAtLoad = true; | ||
| StandardOutPath = "/tmp/night-shift.log"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: Using fixed paths in Prompt for AI agents |
||
| StandardErrorPath = "/tmp/night-shift.error.log"; | ||
| }; | ||
| }; | ||
| } | ||
|
Comment on lines
+1
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactoring addresses two important issues:
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| #!/usr/bin/env bash | ||
| # shellcheck disable=SC2329 | ||
|
|
||
| Describe 'home-manager/services/night-shift/apply-night-shift.sh' | ||
| SCRIPT="$PWD/home-manager/services/night-shift/apply-night-shift.sh" | ||
|
|
||
| Describe 'script properties' | ||
| It 'uses bash shebang' | ||
| When run bash -c "head -1 '$SCRIPT'" | ||
| The output should include '#!/usr/bin/env bash' | ||
| End | ||
|
|
||
| It 'uses strict mode' | ||
| When run bash -c "head -5 '$SCRIPT'" | ||
| The output should include 'set -euo pipefail' | ||
| End | ||
|
|
||
| It 'passes bash syntax check after replacing placeholders' | ||
| When run bash -c "sed -e 's|@nightlightBin@|/usr/bin/true|g' -e 's|@temperature@|100|g' '$SCRIPT' | bash -n" | ||
| The status should be success | ||
| End | ||
| End | ||
|
|
||
| setup_night_shift_script() { | ||
| TEST_DIR=$(mktemp -d) | ||
| NIGHTLIGHT_LOG="$TEST_DIR/nightlight.log" | ||
| NIGHTLIGHT_BIN="$TEST_DIR/nightlight" | ||
| PREPROCESSED_SCRIPT="$TEST_DIR/apply-night-shift.sh" | ||
| : >"$NIGHTLIGHT_LOG" | ||
|
|
||
| cat >"$NIGHTLIGHT_BIN" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| set -eu | ||
| printf '%s\n' "$*" >>"$NIGHTLIGHT_LOG" | ||
| EOF | ||
| chmod +x "$NIGHTLIGHT_BIN" | ||
|
|
||
| sed \ | ||
| -e "s|@nightlightBin@|$NIGHTLIGHT_BIN|g" \ | ||
| -e 's|@temperature@|100|g' \ | ||
| "$SCRIPT" >"$PREPROCESSED_SCRIPT" | ||
| chmod +x "$PREPROCESSED_SCRIPT" | ||
| } | ||
|
|
||
| cleanup_night_shift_script() { | ||
| rm -rf "$TEST_DIR" | ||
| } | ||
|
|
||
| Describe 'applying the Night Shift default' | ||
| Before 'setup_night_shift_script' | ||
| After 'cleanup_night_shift_script' | ||
|
|
||
| It 'clears the schedule before turning Night Shift on' | ||
| When run bash -c ': >"'"$NIGHTLIGHT_LOG"'"; NIGHTLIGHT_LOG="'"$NIGHTLIGHT_LOG"'" "'"$PREPROCESSED_SCRIPT"'" >/dev/null && cat "'"$NIGHTLIGHT_LOG"'"' | ||
| The status should be success | ||
| The line 1 of output should eq 'schedule stop' | ||
| The line 2 of output should eq 'temp 100' | ||
| The line 3 of output should eq 'on' | ||
| End | ||
| End | ||
|
|
||
| End |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Login resets temperature too, not just on/off: The PR description frames this agent as a default that a manual toggle can override until next login, and that's true for
on/off— but this line unconditionally re-appliestemp 100at every login, so a manualnightlight temp 60(or any other value) gets silently stomped on the next login. If that's intentional (i.e. the 'default' is reallyon @ temp=100, not juston), consider calling it out in the module comment; if not, gating thetempcall on the current preference (or dropping it and relying on macOS to remember the last temp) would keep temperature adjustments sticky the same way on/off is.