Move Night Light onto a first-party nightlight service
Same treatment as Stay Awake: the indicator polled the toggle CLI over a Process with a timer to paper over the race after clicking, and the CLI ended by asking the shell to refresh every indicator over IPC. A new omarchy.nightlight service owns hyprsunset instead - it probes the temperature on startup, applies changes itself for in-shell toggles, and answers on the nightlight IPC target. The indicator becomes a plain binding. The CLI still drives hyprctl directly so keybindings, the menu, and ssh work without the shell, but now just nudges the service to re-probe since hyprsunset has no state file to watch. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
61b7cd1c12
commit
ba91bad3a4
@@ -33,11 +33,20 @@ ShellRoot {
|
||||
}
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: nightlightService
|
||||
property bool enabled: false
|
||||
function setNightlight(value) {
|
||||
enabled = !!value
|
||||
}
|
||||
}
|
||||
|
||||
QtObject {
|
||||
id: mockShell
|
||||
function firstPartyServiceFor(id) {
|
||||
if (id === "omarchy.notifications") return notificationService
|
||||
if (id === "omarchy.idle") return idleService
|
||||
if (id === "omarchy.nightlight") return nightlightService
|
||||
return null
|
||||
}
|
||||
}
|
||||
@@ -175,7 +184,7 @@ ShellRoot {
|
||||
nightLight.moduleName = "NightLight"
|
||||
root.injectBar(nightLight)
|
||||
nightLight.triggerPress(Qt.LeftButton)
|
||||
root.assertTrue(root.commandCount("omarchy-toggle-nightlight") === 1, "Night Light left click runs toggle command")
|
||||
root.assertTrue(nightlightService.enabled === true, "Night Light left click toggles the nightlight service")
|
||||
}
|
||||
|
||||
var screenRecording = root.createIndicator("ScreenRecording")
|
||||
|
||||
@@ -4,26 +4,61 @@ set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
run_node_test <<'JS'
|
||||
const nightlight = requireFromRoot('shell/plugins/services/nightlight/NightlightModel.js')
|
||||
|
||||
assertEqual(nightlight.temperatureFromOutput('4000\n'), 4000, 'nightlight parses probe temperature')
|
||||
assertEqual(nightlight.temperatureFromOutput("Couldn't connect to hyprsunset"), null, 'nightlight treats unreachable hyprsunset as unknown')
|
||||
assertEqual(nightlight.isNightlight(4000), true, 'nightlight reports warm temperatures as enabled')
|
||||
assertEqual(nightlight.isNightlight(5999), true, 'nightlight reports warmer-than-identity values as enabled')
|
||||
assertEqual(nightlight.isNightlight(6000), false, 'nightlight reports identity temperature as disabled')
|
||||
assertEqual(nightlight.isNightlight(null), false, 'nightlight reports unknown temperature as disabled')
|
||||
JS
|
||||
|
||||
TMPDIR=$(mktemp -d)
|
||||
trap 'rm -rf "$TMPDIR"' EXIT
|
||||
|
||||
mkdir -p "$TMPDIR/bin"
|
||||
STATE="$TMPDIR/hyprsunset-temp"
|
||||
SHELL_LOG="$TMPDIR/omarchy-shell-log"
|
||||
|
||||
cat >"$TMPDIR/bin/hyprctl" <<'SH'
|
||||
#!/bin/bash
|
||||
|
||||
if [[ ${1:-} == "hyprsunset" && ${2:-} == "temperature" ]]; then
|
||||
printf '%s\n' "${HYPRSUNSET_TEMP:-6500}"
|
||||
if [[ -n ${3:-} ]]; then
|
||||
printf '%s\n' "$3" >"$HYPRSUNSET_STATE"
|
||||
else
|
||||
cat "$HYPRSUNSET_STATE" 2>/dev/null || exit 1
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit 1
|
||||
SH
|
||||
|
||||
chmod +x "$TMPDIR/bin/hyprctl"
|
||||
cat >"$TMPDIR/bin/pgrep" <<'SH'
|
||||
#!/bin/bash
|
||||
exit 0
|
||||
SH
|
||||
|
||||
cat >"$TMPDIR/bin/omarchy-shell" <<'SH'
|
||||
#!/bin/bash
|
||||
printf '%s\n' "$*" >>"$OMARCHY_SHELL_LOG"
|
||||
SH
|
||||
|
||||
chmod +x "$TMPDIR/bin/hyprctl" "$TMPDIR/bin/pgrep" "$TMPDIR/bin/omarchy-shell"
|
||||
|
||||
nightlight_cli() {
|
||||
PATH="$TMPDIR/bin:$PATH" \
|
||||
HYPRSUNSET_STATE="$STATE" \
|
||||
OMARCHY_SHELL_LOG="$SHELL_LOG" \
|
||||
"$ROOT/bin/omarchy-toggle-nightlight" "$@"
|
||||
}
|
||||
|
||||
nightlight_status() {
|
||||
HYPRSUNSET_TEMP="$1" PATH="$TMPDIR/bin:$PATH" "$ROOT/bin/omarchy-toggle-nightlight" --status
|
||||
printf '%s\n' "$1" >"$STATE"
|
||||
nightlight_cli --status
|
||||
}
|
||||
|
||||
[[ $(nightlight_status 4000 | jq -r .enabled) == "true" ]] || fail "nightlight status reports 4000K as enabled"
|
||||
@@ -37,3 +72,21 @@ pass "nightlight status reports identity temperature as disabled"
|
||||
|
||||
[[ $(nightlight_status 6500 | jq -r .enabled) == "false" ]] || fail "nightlight status reports daylight temperature as disabled"
|
||||
pass "nightlight status reports daylight temperature as disabled"
|
||||
|
||||
printf '6500\n' >"$STATE"
|
||||
: >"$SHELL_LOG"
|
||||
nightlight_cli >/dev/null
|
||||
[[ $(<"$STATE") == 4000 ]] || fail "nightlight toggle warms the screen from daylight"
|
||||
pass "nightlight toggle warms the screen from daylight"
|
||||
|
||||
grep -Fqx -- '-q nightlight refresh' "$SHELL_LOG" || fail "nightlight toggle nudges the shell nightlight service"
|
||||
pass "nightlight toggle nudges the shell nightlight service"
|
||||
|
||||
nightlight_cli >/dev/null
|
||||
[[ $(<"$STATE") == 6500 ]] || fail "nightlight toggle restores daylight from night light"
|
||||
pass "nightlight toggle restores daylight from night light"
|
||||
|
||||
if rg -q 'omarchy.indicators' "$ROOT/bin/omarchy-toggle-nightlight"; then
|
||||
fail "nightlight toggle leaves indicator refresh to the nightlight service"
|
||||
fi
|
||||
pass "nightlight toggle leaves indicator refresh to the nightlight service"
|
||||
|
||||
Reference in New Issue
Block a user