Repository navigation
[Light Switch] Add CLI for status and theme control - #50459
Merged
Merged
Conversation
Authenticate pipe connections by user, session, and logon SID while restoring the service identity before command execution. Initialize missing settings safely at startup and refresh the settings page after atomic file replacement. Validated x64 Debug builds and 168 tests: 59 native, 106 CLI, and 3 settings tests.
Parse presentation flags with the command-line library and expand response files once. Refresh the initial settings cache and all derived UI values without writing stale binding values back to settings. Preserve manual choices across delayed notifications, unchanged settings, sleep, and clock rollback. Track full dates for schedule and solar state. Keep a share-delete settings handle during concurrent startup reads, and include the CLI and shim in installer process cleanup. Validation: x64 Debug service, CLI and related UI builds; 277 passing unit tests; 7 independent state probes; 20 repeated startup diagnostic runs; local CLI help/version smoke; x64 Release installer custom-action build.
Reject unsupported parser directives before any command executes. Apply location settings as a complete snapshot, preserve valid offsets, and project missing sun times safely to TimePicker controls. Reconcile Night Light after transient failures without discarding newer manual choices. Distinguish recovered and unverified own theme writes from external changes. Serialize sun-time persistence with CLI settings updates and discard calculations for superseded configurations. Validation: x64 Debug service, CLI and settings UI builds; 323 passing unit tests and 21 independent probes; x64 Release Native AOT publish and three local executable smoke checks.
Distinguish unavailable Night Light data from OFF and preserve manual choices across read failures and recovery. Reuse verified theme snapshots and replay pending scheduled PowerDisplay notifications without discarding them when a manual write fails. Add 18 regression and boundary tests and document recovery behavior. Validated x64 Debug builds for the service, module interface, and native test project; all 120 native tests pass.
Preserve pending external theme choices across failed explicit commands and notify PowerDisplay when an idempotent command or verification retry confirms a change. Keep scheduled boundaries and newer configurations authoritative. Share worker recovery between Command Palette and hotkey requests, serialize module lifecycle operations, and keep saved solar offsets visible in Settings. Validation: x64 Debug builds passed; 130 native, 193 CLI, and 44 settings tests passed. Real module event and callback recovery probes each restarted the service and consumed exactly one request, with the environment restored.
Contributor
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
Localize CLI and service user-facing text while preserving JSON fields, protocol values, error codes, and exit codes. Package available CLI and parser satellite resources without requiring missing translations. Simplify theme verification, minute-tick handling, and unused settings/UI paths. Include the Light Switch service and CLI in BugReport diagnostics. Validation: x64 Debug builds; 136 native and 209 CLI tests passed; x64 Release Native AOT publish and JSON smoke checks passed; per-user and per-machine satellite MSI fixtures passed; git diff --check passed.
Preserve PowerDisplay notifications after unverified or partially applied toggles without replacing an earlier pending scheduled notification. Normalize effective solar preview times while retaining saved offsets, and post the pipe test's accept before a rejected client can disconnect. Add regression coverage for notification recovery, mixed themes, pending notifications, wrapped solar times, and overflow-safe display projections. Validation: x64 Debug service, CLI, and Settings UI builds passed; 140 native, 221 CLI, and 49 settings tests passed. The pipe rejection test also passed 10 repeated runs. git diff --check passed.
Reuse the theme observations already recorded by ToggleTheme and let the Night Light observer destructor stop its worker. Remove unused native headers and Settings UI imports without changing behavior. Validation: x64 Debug builds passed with no warnings or errors; 140 native, 221 CLI, and 49 Light Switch settings tests passed via vstest.console.exe.
Yu Leng (moooyo)
marked this pull request as ready for review
September 28, 2026 13:01
🧭 PR intakeVisual evidence: Required — The pull request changes product UI files, so reviewers need to see the visible result. Visual evidence is currently missing. Author actionYu Leng (@moooyo), please update the following before review:
See the contribution guide for the full checklist. If there is no author response within 7 days, this PR will be automatically closed. Automated PR intake; PowerToys maintainers make final decisions. |
Contributor
|
This pull request has been automatically closed because it has been marked as requiring author feedback but has not had any activity for 7 days. If you would like to continue working on it, please reopen the PR and push your changes or leave a comment. |
Preserve both the Settings CLI added on main and the Light Switch CLI in the shared manifest and installer component references, including their original target paths and component identities. Validated the six mappings, components, and references; the x64 Debug CliShim.UnitTests build succeeded and all 8 tests passed via VSTest.
Boliang Zhang (LegendaryBlair)
approved these changes
Oct 9, 2026
Contributor
Author
Clint Rutkas (crutkas)
added a commit
that referenced
this pull request
Oct 9, 2026
Light Switch CLI (#50459) and Settings CLI (#50507) merged to main using System.CommandLine beta APIs, breaking the 2.0 GA upgrade build. Port them to the GA API while preserving command names, options, output, and exit codes. Light Switch clears the default RootCommand help/version/directives, ignores implicit option results, and reports leading [directive] tokens as unrecognized to keep the previous parsing behavior.
4 tasks done
Yu Leng (moooyo)
added a commit
that referenced
this pull request
Oct 15, 2026
## Summary of the Pull Request Add `LightSwitch_CLICommand` and `PowerDisplay_CLICommand` using the Settings CLI telemetry pattern, providing a basic usage signal for the two CLIs. Each invocation records an allowlisted `CommandName` and a `Successful` flag based on its final exit code, through the existing diagnostics consent check. Related CLI work: #50459 and #48632. Telemetry pattern: #50507. ## PR Checklist - [x] **Tests:** Existing CLI regression suites pass. - [x] **Localization:** No new user-facing strings. - [x] **Dev docs:** Not applicable to this telemetry-only change. - [x] **New binaries:** No new binaries or external dependencies; ManagedTelemetry was already a transitive dependency. ## Detailed Description of the Pull Request / Additional comments - Wrap execution in `src/modules/LightSwitch/LightSwitch.Cli/Program.cs` and `src/modules/powerdisplay/PowerDisplay.Cli/Program.cs` to attempt one event per invocation, including help/version, validation failures, and exceptions. Telemetry failures preserve the command's output, exit code, and exception. - Match Settings CLI's first-token allowlist. Option-first and response-file invocations use `unknown`; raw arguments, monitor IDs, profile values, and file paths are excluded from telemetry. - Enable `EventSourceSupport` in both NativeAOT projects and preserve the event properties for trimming. ## Validation Steps Performed - Repository `build-essentials.ps1`, Debug/x64: exit 0. - Existing CLI regression tests passed with `vstest.console.exe`: LightSwitch **221/221**, PowerDisplay **130/130**. - Publish both CLIs with `tools/build/build.ps1 /t:Publish`, Release/win-x64 NativeAOT: exit 0, 0 warnings, 0 errors. - Eight checks against the published native executables passed: help, version, and no-argument behavior for both CLIs, LightSwitch JSON help, and PowerDisplay JSON argument errors. PowerDisplay's existing missing-command exit code remains 1. - `git diff --check` passed. Restores used the configured host NuGet source. --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com>
Boliang Zhang (LegendaryBlair)
pushed a commit
that referenced
this pull request
Oct 16, 2026
## Summary of the Pull Request Add `LightSwitch_CLICommand` and `PowerDisplay_CLICommand` using the Settings CLI telemetry pattern, providing a basic usage signal for the two CLIs. Each invocation records an allowlisted `CommandName` and a `Successful` flag based on its final exit code, through the existing diagnostics consent check. Related CLI work: #50459 and #48632. Telemetry pattern: #50507. ## PR Checklist - [x] **Tests:** Existing CLI regression suites pass. - [x] **Localization:** No new user-facing strings. - [x] **Dev docs:** Not applicable to this telemetry-only change. - [x] **New binaries:** No new binaries or external dependencies; ManagedTelemetry was already a transitive dependency. ## Detailed Description of the Pull Request / Additional comments - Wrap execution in `src/modules/LightSwitch/LightSwitch.Cli/Program.cs` and `src/modules/powerdisplay/PowerDisplay.Cli/Program.cs` to attempt one event per invocation, including help/version, validation failures, and exceptions. Telemetry failures preserve the command's output, exit code, and exception. - Match Settings CLI's first-token allowlist. Option-first and response-file invocations use `unknown`; raw arguments, monitor IDs, profile values, and file paths are excluded from telemetry. - Enable `EventSourceSupport` in both NativeAOT projects and preserve the event properties for trimming. ## Validation Steps Performed - Repository `build-essentials.ps1`, Debug/x64: exit 0. - Existing CLI regression tests passed with `vstest.console.exe`: LightSwitch **221/221**, PowerDisplay **130/130**. - Publish both CLIs with `tools/build/build.ps1 /t:Publish`, Release/win-x64 NativeAOT: exit 0, 0 warnings, 0 errors. - Eight checks against the published native executables passed: help, version, and no-argument behavior for both CLIs, LightSwitch JSON help, and PowerDisplay JSON argument errors. PowerDisplay's existing missing-command exit code remains 1. - `git diff --check` passed. Restores used the configured host NuGet source. --------- Co-authored-by: Yu Leng (from Dev Box) <yuleng@microsoft.com> (cherry picked from commit 7f149ab) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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 of the Pull Request
Adds
PowerToys.LightSwitch.CLI.exefor querying and controlling the running Light Switch service. Scripts can read status, set or toggle the configured theme targets, and enable or disable the existing schedule, with JSON output and documented exit codes.Closes #49904.
PR Checklist
Detailed Description of the Pull Request / Additional comments
src/modules/LightSwitch/LightSwitch.Cli/addsstatus,light,dark,toggle,schedule enable [--mode], andschedule disable. All commands support--json; help and version work without the service. Enabling a schedule fromOffrequires an explicit existing mode:fixed-hours,sunset-to-sunrise, orfollow-night-light.src/modules/LightSwitch/LightSwitchService/CliPipeServer.cppandCliProtocol.cppimplement bounded, versioned request/response IPC with user/session/logon isolation, server identity checks in the client, timeouts, and shutdown handling. The CLI requires a running service and does not automatically retry mutations after an uncertain result.src/modules/LightSwitch/LightSwitchService/LightSwitchStateManager.cppexposes serialized theme operations and status snapshots using the existing scheduling rules.src/modules/LightSwitch/LightSwitchModuleInterface/dllmain.cppsubmits counted toggle requests to the service so theme writes and manual-override updates occur together. Theme access failures and partial changes are reported to callers; verified recovery preserves downstream theme notifications.scheduleModesetting and complete the worker's settings handling before replying. Duplicate settings notifications preserve manual overrides, and settings loaded before a delayed notification are not mistaken for an external theme change. Overrides account for sleep, clock changes, and unavailable Night Light data.src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.csrefreshes after settings-file replacement. Concurrent editors retain the existing whole-file save behavior.tools/CliShim/CliShimManifest.props,installer/PowerToysSetupVNext/CliShims.wxs, and.pipelines/ESRPSigning_core.jsonregister deployment and signing. The CLI and service are included in BugReport diagnostics. Usage, protocol behavior, and exit codes are documented indoc/devdocs/modules/lightswitch-cli.md.Validation Steps Performed
LightSwitchService.UnitTests,LightSwitch.Cli.UnitTests, andSettings.UI.UnitTests, including their Light Switch service, CLI, and Settings UI dependencies. Each build returned exit code 0 with 0 warnings and 0 errors.vstest.console.exe, covering protocol/identity/framing, shutdown and queue handling, settings persistence, manual overrides, recovery, and schedule boundaries.vstest.console.exe, covering parsing, output/exit codes, bounded IPC, response validation, and resource-based output.vstest.console.exewithFullyQualifiedName~LightSwitch, covering the ViewModel and settings watcher. This was a filtered run, not the complete Settings test suite.git diff --checkpassed. The cleanup preserves behavior, removes redundant theme-observation and observer-stop calls, and removes unused imports; existing regression tests cover the affected paths.Desktop theme/hotkey acceptance, real translated-satellite acceptance, ARM64/Release verification, and full installer acceptance are not covered by these latest checks.