feat(caf): disable screen lock and idle timeout when active - #1931
Conversation
|
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe Changescaf idle inhibit integration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request updates the _caf_function fish function to disable screen-locking when keeping the machine awake, integrating noctalia-shell and systemctl commands to manage idle inhibition. It also adds corresponding test stubs. The review feedback correctly identifies that command -q is invalid in fish shell and suggests using type -q instead, which simplifies the logic and allows the test stubs to be properly detected.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if command -q noctalia-shell | ||
| noctalia-shell msg idleInhibitor enable 2>/dev/null | ||
| end | ||
| if test (uname) != Darwin | ||
| systemctl --user stop ac-idle-inhibit.service 2>/dev/null | ||
| end |
There was a problem hiding this comment.
In fish shell, command -q is not a valid option for the command builtin (which only supports -v/--search). To check if a command or function exists quietly, the idiomatic fish way is to use type -q.
Additionally, using type -q allows the test stubs (defined as fish functions in _caf_function_test.fish) to be correctly detected and executed during tests. Replacing test (uname) != Darwin with type -q systemctl also simplifies the logic by directly checking for the command's presence rather than assuming its existence based on the operating system.
if type -q noctalia-shell
noctalia-shell msg idleInhibitor enable 2>/dev/null
end
if type -q systemctl
systemctl --user stop ac-idle-inhibit.service 2>/dev/null
end
| if command -q noctalia-shell | ||
| noctalia-shell msg idleInhibitor disable 2>/dev/null | ||
| end | ||
| if test (uname) != Darwin | ||
| systemctl --user start ac-idle-inhibit.service 2>/dev/null | ||
| end |
There was a problem hiding this comment.
In fish shell, command -q is not a valid option for the command builtin (which only supports -v/--search). To check if a command or function exists quietly, the idiomatic fish way is to use type -q.
Additionally, using type -q allows the test stubs (defined as fish functions in _caf_function_test.fish) to be correctly detected and executed during tests. Replacing test (uname) != Darwin with type -q systemctl also simplifies the logic by directly checking for the command's presence rather than assuming its existence based on the operating system.
if type -q noctalia-shell
noctalia-shell msg idleInhibitor disable 2>/dev/null
end
if type -q systemctl
systemctl --user start ac-idle-inhibit.service 2>/dev/null
end
| if test (uname) != Darwin | ||
| systemctl --user stop ac-idle-inhibit.service 2>/dev/null | ||
| end | ||
| echo "caf on: awake, screen lock disabled (pid "(cat "$pid_file")")" |
There was a problem hiding this comment.
Misleading echo on macOS: this string (and the matching caf off line at L37) claims screen lock was disabled, but on Darwin command -q noctalia-shell is false and the test (uname) != Darwin gate skips the systemctl line, so no screen-lock side-effect actually runs. Consider gating the new wording behind the same OS/availability checks, or splitting the echo so macOS keeps the original "awake lid-closed" / "normal sleep restored" wording.
| noctalia-shell msg idleInhibitor disable 2>/dev/null | ||
| end | ||
| if test (uname) != Darwin | ||
| systemctl --user start ac-idle-inhibit.service 2>/dev/null |
There was a problem hiding this comment.
Cold caf off restarts a service that wasn't necessarily stopped by caf: this systemctl --user start ac-idle-inhibit.service (and the noctalia disable on L32) runs on every caf off invocation, even when no pid file existed and caf was never on. If the user had explicitly stopped ac-idle-inhibit it'll be silently restarted by an unrelated caf off/toggle. Consider gating these two new side-effects on test -f "$pid_file" so they only fire as the inverse of an actual caf on.
| end | ||
| function systemctl | ||
| true | ||
| end |
There was a problem hiding this comment.
Stubs added but no assertions on the new behavior: these stubs keep the existing tests green, but nothing in this file verifies that caf on invokes noctalia-shell msg idleInhibitor enable + systemctl --user stop ac-idle-inhibit.service (and the inverse on off). Consider capturing $argv to a temp log inside the stubs and adding @test assertions on those logs so typos or swapped enable/disable would be caught.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
spec/fish/_caf_function_test.fish (1)
15-20: ⚡ Quick winRecord stub invocations so new integration behavior is actually verified.
Lines 15-20 currently always succeed, so typos/regressions in
noctalia-shell msg idleInhibitor ...orsystemctl --user ... ac-idle-inhibit.servicewon’t fail tests. Capture$argvand assert expected calls incaf on/offtests.Proposed test-hardening diff
+set call_log $tmpdir/calls.log + function noctalia-shell - true + echo "noctalia-shell $argv" >> $call_log end function systemctl - true + echo "systemctl $argv" >> $call_log end + +_caf_function on >/dev/null 2>&1 +@test "on disables noctalia idle inhibitor" (rg -n "noctalia-shell msg idleInhibitor enable" $call_log >/dev/null; echo $status) = 0 +@test "on stops ac-idle-inhibit.service" (rg -n "systemctl --user stop ac-idle-inhibit.service" $call_log >/dev/null; echo $status) = 0🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@spec/fish/_caf_function_test.fish` around lines 15 - 20, The stub functions noctalia-shell and systemctl at lines 15-20 always return true without verifying the actual invocations, which means typos or regressions in the command arguments won't be caught by tests. Modify both stub functions to capture their arguments via $argv into a variable or array that can be inspected later, then update the caf on/off test cases to assert that these stubs were called with the expected command-line arguments, ensuring regression detection for the noctalia-shell msg idleInhibitor and systemctl --user ac-idle-inhibit.service invocations.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@spec/fish/_caf_function_test.fish`:
- Around line 15-20: The stub functions noctalia-shell and systemctl at lines
15-20 always return true without verifying the actual invocations, which means
typos or regressions in the command arguments won't be caught by tests. Modify
both stub functions to capture their arguments via $argv into a variable or
array that can be inspected later, then update the caf on/off test cases to
assert that these stubs were called with the expected command-line arguments,
ensuring regression detection for the noctalia-shell msg idleInhibitor and
systemctl --user ac-idle-inhibit.service invocations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4794a101-349c-449e-8f5e-99f2df40ded4
📒 Files selected for processing (2)
home-manager/programs/fish/functions/_caf_function.fishspec/fish/_caf_function_test.fish
Summary
caf onnow also disables noctalia idle inhibitor (screen lock) and stopsac-idle-inhibit.service(battery dpms-off/suspend)caf offre-enables bothnoctalia-shellandsystemctlto prevent errors during fish testsTest plan
make formatpassesmake fish-testpasses (all caf tests green)caf onand verify screen does not lock after idle timeoutcaf offand verify screen lock resumescaf statusto confirm reporting still works🤖 Generated with Claude Code
Summary by cubic
Update
cafsoondisables screen lock and idle timeout (enablesnoctalia-shellidle inhibitor, stops userac-idle-inhibit.service).offrestores both; adds test stubs fornoctalia-shellandsystemctlto keep fish tests passing.Written for commit e42fb01. Summary will update on new commits.