[Light Switch] Add CLI for status and theme control - #50459
Draft
Yu Leng (moooyo) wants to merge 4 commits into
Draft
[Light Switch] Add CLI for status and theme control#50459Yu Leng (moooyo) wants to merge 4 commits into
Yu Leng (moooyo) wants to merge 4 commits into
Conversation
added 3 commits
September 9, 2026 14:44
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.
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 session/user 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.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.src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.csalso refreshes 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. Usage, protocol behavior, and exit codes are documented indoc/devdocs/modules/lightswitch-cli.md.Validation Steps Performed
src/modules/LightSwitch/Tests/LightSwitch.Cli.UnitTests/.vstest.console.exeinsrc/modules/LightSwitch/Tests/LightSwitchService.UnitTests/, including the regression for a minute tick loading settings before the debounced notification.git diff --checkpassed.Desktop theme/hotkey acceptance, ARM64/Release validation, and full installer acceptance remain pending. Settings UI's successful build reported an existing
CsWinRT1028warning insrc/common/ManagedCommon/HotkeySettingsControlHook.cs.