Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/omarchy-toggle-nightlight
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ if [[ ${1:-} == "--status" ]]; then
exit 0
fi

# Ensure hyprsunset is running
if ! pgrep -x hyprsunset >/dev/null; then
# Ensure hyprsunset is running in this session (another user may have their own)
if ! pgrep -u "$USER" -x hyprsunset >/dev/null; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Environment user can misidentify processes. If USER is unset, pgrep fails and the toggle tries to start another hyprsunset even when one is running. If it names another logged-in user, that user's process can prevent the current user's daemon from starting. Use the running UID for this check.

Suggested change
if ! pgrep -u "$USER" -x hyprsunset >/dev/null; then
if ! pgrep -u "$(id -u)" -x hyprsunset >/dev/null; then

setsid uwsm-app -- hyprsunset &
fi

Expand Down
6 changes: 6 additions & 0 deletions test/shell.d/nightlight-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trap 'rm -rf "$TMPDIR"' EXIT
mkdir -p "$TMPDIR/bin"
STATE="$TMPDIR/hyprsunset-temp"
SHELL_LOG="$TMPDIR/omarchy-shell-log"
PGREP_LOG="$TMPDIR/pgrep-log"

cat >"$TMPDIR/bin/hyprctl" <<'SH'
#!/bin/bash
Expand All @@ -39,6 +40,7 @@ SH

cat >"$TMPDIR/bin/pgrep" <<'SH'
#!/bin/bash
printf '%s\n' "$*" >>"$PGREP_LOG"
exit 0
Comment on lines +43 to 44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Startup branch remains untested. The pgrep stub always reports that a process exists, while the new assertion checks only the arguments passed to it. The test therefore cannot catch a failure to start hyprsunset when only another user has one running. Model that case in the stub and assert that startup occurs.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

SH

Expand All @@ -53,6 +55,7 @@ nightlight_cli() {
PATH="$TMPDIR/bin:$PATH" \
HYPRSUNSET_STATE="$STATE" \
OMARCHY_SHELL_LOG="$SHELL_LOG" \
PGREP_LOG="$PGREP_LOG" \
"$ROOT/bin/omarchy-toggle-nightlight" "$@"
}

Expand Down Expand Up @@ -82,6 +85,9 @@ 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"

grep -Fqx -- "-u $USER -x hyprsunset" "$PGREP_LOG" || fail "nightlight toggle only looks for the current user's hyprsunset"
pass "nightlight toggle only looks for the current user's hyprsunset"

nightlight_cli >/dev/null
[[ $(<"$STATE") == 6500 ]] || fail "nightlight toggle restores daylight from night light"
pass "nightlight toggle restores daylight from night light"
Expand Down