Skip to content

[Light Switch] Add CLI for status and theme control - #50459

Draft
Yu Leng (moooyo) wants to merge 4 commits into
mainfrom
yuleng/light-switch-cli-49904
Draft

[Light Switch] Add CLI for status and theme control#50459
Yu Leng (moooyo) wants to merge 4 commits into
mainfrom
yuleng/light-switch-cli-49904

Conversation

@moooyo

Copy link
Copy Markdown
Contributor

Summary of the Pull Request

Adds PowerToys.LightSwitch.CLI.exe for 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

  • Closes: [Light Switch] Add CLI for status and theme control #49904
  • Communication: Discussed with core contributors.
  • Tests: Added/updated; all 152 module tests pass locally.
  • Localization: CLI help and diagnostics are currently English.
  • Dev docs: Added/updated.
  • New binaries: Added to the solution, signing list, CLI shim manifest, and installer shim components.
  • Documentation updated: External PowerToys documentation PR.

Detailed Description of the Pull Request / Additional comments

  • src/modules/LightSwitch/LightSwitch.Cli/ adds status, light, dark, toggle, schedule enable [--mode], and schedule disable. All commands support --json; help and version work without the service. Enabling a schedule from Off requires an explicit existing mode: fixed-hours, sunset-to-sunrise, or follow-night-light.
  • src/modules/LightSwitch/LightSwitchService/CliPipeServer.cpp and CliProtocol.cpp implement 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.cpp exposes serialized theme operations and status snapshots using the existing scheduling rules. src/modules/LightSwitch/LightSwitchModuleInterface/dllmain.cpp submits 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.
  • Schedule commands update the existing scheduleMode setting 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.cs also 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.json register deployment and signing. Usage, protocol behavior, and exit codes are documented in doc/devdocs/modules/lightswitch-cli.md.

Validation Steps Performed

  • x64 Debug builds passed for Runner, Settings UI, Light Switch service/module interface, CLI and test projects, and CLI shim. The service and native tests were rebuilt successfully after the final regression fix.
  • 106 managed CLI tests passed in src/modules/LightSwitch/Tests/LightSwitch.Cli.UnitTests/.
  • 46 native tests passed via vstest.console.exe in src/modules/LightSwitch/Tests/LightSwitchService.UnitTests/, including the regression for a minute tick loading settings before the debounced notification.
  • Built shim smoke checks passed for JSON help, invalid-mode exit code 2, and unavailable-service JSON output with exit code 3.
  • git diff --check passed.

Desktop theme/hotkey acceptance, ARM64/Release validation, and full installer acceptance remain pending. Settings UI's successful build reported an existing CsWinRT1028 warning in src/common/ManagedCommon/HotkeySettingsControlHook.cs.

Yu Leng (from Dev Box) 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Light Switch] Add CLI for status and theme control

1 participant