feat(daemon): Windows lid auto-pause via SystemEvents.PowerModeChanged - #22
Merged
Conversation
Subscribes the always-running cmux-daemon to PowerModeChanged and toggles %TEMP%\cmux-paused.flag on Suspend/Resume. The flag is the cross-platform SSOT shared with cmuxO (macOS sleepwatcher hook), so orchestration skills can pause/resume worker activity uniformly on both platforms. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cmux-daemontoSystemEvents.PowerModeChangedand toggles%TEMP%\cmux-paused.flagon Suspend/Resume.src/Cmux.Daemon/LidPauseWatcher.cs; one-line hookup inProgram.cs;Microsoft.Win32.SystemEvents9.0.0 added toCmux.Daemon.csproj.~/.sleep/~/.wakeup). Orchestration skills poll this single file on both platforms.Why here (daemon, not WPF app)
cmux-daemonis the always-on background process. Hooking there means lid events are captured even when no WPF window is open, and the logic stays out of UI code.Why SystemEvents.PowerModeChanged
NativeWindow, noWM_POWERBROADCASTP/Invoke.Microsoft.Win32.SystemEventsis the supported path for non-WinForms/WPF executables onnet*-windows.Alternative considered:
PowerRegisterSuspendResumeNotification(powrprof.dll) — rejected for complexity; no advantage for this use case.Test plan
dotnet build Cmux.sln -c Debugsucceeds on Windows (unverified — authored on macOS, no local .NET 10 Windows SDK).cmux-daemon, close laptop lid / trigger Sleep →%TEMP%\cmux-paused.flagexists; daemon-debug.log shows[lid-watcher] Suspend.[lid-watcher] Resume.Risks / follow-up
net10.0-windowsresolvesMicrosoft.Win32.SystemEvents9.0.0 cleanly (may want to pin to 10.0.0 once published to match TFM).File.Delete(FlagPath)beforeLidPauseWatcher.Start) if this proves annoying in practice — left out of this PR to keep it minimal.Global\CmuxDaemonmutex ensures only one subscriber, so no duplicate flag toggling.🤖 Generated with Claude Code