Skip to content

feat(caf): disable screen lock and idle timeout when active - #1931

Merged
shunkakinoki merged 1 commit into
mainfrom
feat/caf-disable-screen-lock
Jun 19, 2026
Merged

feat(caf): disable screen lock and idle timeout when active#1931
shunkakinoki merged 1 commit into
mainfrom
feat/caf-disable-screen-lock

Conversation

@shunkakinoki

@shunkakinoki shunkakinoki commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Summary

  • caf on now also disables noctalia idle inhibitor (screen lock) and stops ac-idle-inhibit.service (battery dpms-off/suspend)
  • caf off re-enables both
  • Test stubs added for noctalia-shell and systemctl to prevent errors during fish tests

Test plan

  • make format passes
  • make fish-test passes (all caf tests green)
  • Run caf on and verify screen does not lock after idle timeout
  • Run caf off and verify screen lock resumes
  • Run caf status to confirm reporting still works

🤖 Generated with Claude Code


Summary by cubic

Update caf so on disables screen lock and idle timeout (enables noctalia-shell idle inhibitor, stops user ac-idle-inhibit.service). off restores both; adds test stubs for noctalia-shell and systemctl to keep fish tests passing.

Written for commit e42fb01. Summary will update on new commits.

Review in cubic

@indent-zero

indent-zero Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
PR Summary

Extends the caf fish helper so toggling caf on also suppresses screen lock / idle-driven dpms (not just sleep), and caf off restores it. The new side-effects are gated on noctalia-shell being installed and on non-Darwin for the swayidle-based ac-idle-inhibit.service, so macOS behavior is unchanged.

  • Add new branches in _caf_function on: enable noctalia's idleInhibitor IPC (if noctalia-shell exists) and systemctl --user stop ac-idle-inhibit.service on Linux.
  • Add symmetric branches in _caf_function off: disable the noctalia inhibitor and systemctl --user start ac-idle-inhibit.service.
  • Update the function description and on/off echo strings to mention screen lock state.
  • Stub noctalia-shell and systemctl in spec/fish/_caf_function_test.fish so existing assertions keep passing on Linux.

Issues

3 potential issues found:

  • On macOS, caf on/caf off print "screen lock disabled/restored" even though neither the noctalia nor the systemctl branches execute there, so the message overstates what actually changed. → Autofix
  • The spec adds noctalia-shell and systemctl stubs but doesn't assert the new branches are invoked with the right arguments, so regressions like a typo in idleInhibitor, swapped enable/disable, or a wrong unit name would slip through CI. → Autofix
  • caf off unconditionally runs systemctl --user start ac-idle-inhibit.service even when there was no prior caf on, so a cold off (or toggle) will re-enable the service if the user previously stopped it intentionally — asymmetric with the existing pid-file-gated cleanup. → Autofix

CI Checks

Waiting for CI checks...


⚡ Autofix All Issues

@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Keep-awake feature now integrates with system services to manage idle and screen-lock behavior.
    • Improved status messages provide clearer feedback about system state changes.

Walkthrough

The caf fish function gains two new side effects: it calls noctalia-shell to toggle its idleInhibitor and, on non-Darwin systems, stops or starts the ac-idle-inhibit.service systemd user service when turning caffeination on or off. The function description and status output messages are updated to mention screen-lock. Tests add stub functions for noctalia-shell and systemctl.

Changes

caf idle inhibit integration

Layer / File(s) Summary
caf on/off: noctalia-shell and systemctl integration
home-manager/programs/fish/functions/_caf_function.fish, spec/fish/_caf_function_test.fish
Function description updated to include screen-lock wording. case on adds noctalia-shell idleInhibitor enable (if available) and systemctl --user stop ac-idle-inhibit.service (non-Darwin), with updated output message. case off adds the inverse calls and updated message. Test file adds always-succeeding stubs for noctalia-shell and systemctl to prevent real invocations during spec runs.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • shunkakinoki/dotfiles#1651: Introduced ac-idle-inhibit.service, the same systemd user service that this PR's caf function now starts and stops.
  • shunkakinoki/dotfiles#1907: Previous modification to the same _caf_function.fish file, extending the caf enable/disable behavior.

Poem

🐇 Hop hop, the screen stays bright,
No lock shall darken this machine tonight!
Noctalia nods, systemd sleeps—
The keeper PID the rabbit keeps.
caf on, we say, and all is well,
A cozy warren, under caffeinate's spell! ☕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly reflects the main change: the caf command now disables screen lock and idle timeout when active, which is the primary objective of this PR.
Description check ✅ Passed The description clearly relates to the changeset, outlining how caf on/off now manages screen lock and idle timeout, and notes the test stubs added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/caf-disable-screen-lock

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

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.

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.

Comment on lines +16 to +21
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

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.

medium

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

Comment on lines +31 to +36
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

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.

medium

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")")"

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.

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

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.

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

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.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
spec/fish/_caf_function_test.fish (1)

15-20: ⚡ Quick win

Record stub invocations so new integration behavior is actually verified.

Lines 15-20 currently always succeed, so typos/regressions in noctalia-shell msg idleInhibitor ... or systemctl --user ... ac-idle-inhibit.service won’t fail tests. Capture $argv and assert expected calls in caf on/off tests.

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

📥 Commits

Reviewing files that changed from the base of the PR and between cdd168e and e42fb01.

📒 Files selected for processing (2)
  • home-manager/programs/fish/functions/_caf_function.fish
  • spec/fish/_caf_function_test.fish

@shunkakinoki
shunkakinoki merged commit f366f85 into main Jun 19, 2026
35 checks passed
@shunkakinoki
shunkakinoki deleted the feat/caf-disable-screen-lock branch June 19, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant