[CmdPal] Add Power Display profile switching - #50432
Draft
Yu Leng (moooyo) wants to merge 10 commits into
Draft
Conversation
5 tasks
Yu Leng (moooyo)
force-pushed
the
codex/cmdpal-powerdisplay-profiles
branch
from
September 7, 2026 04:53
0936fec to
14f5ade
Compare
Yu Leng (moooyo)
changed the base branch from
main
to
codex/powerdisplay-cli-json
September 7, 2026 04:53
Yu Leng (moooyo)
added a commit
that referenced
this pull request
Sep 7, 2026
## Summary of the Pull Request Add a global `--json` flag to PowerDisplay CLI for scripting and automation. Commands emit compact JSON Lines results to stdout and structured errors to stderr, including parse errors and localized IPC errors. Text output remains the default. ## PR Stack 1. **This PR — CLI:** `main` ← `codex/powerdisplay-cli-json` 2. **#50432 — Command Palette:** `codex/powerdisplay-cli-json` ← `codex/cmdpal-powerdisplay-profiles` Review and merge this PR first. After it is squash-merged, rebase the CmdPal-only commit onto the updated `main` and retarget #50432 to `main` before merging the second PR. ## PR Checklist - Related issue: none linked. - [ ] **Communication:** Discussed with core contributors. - [ ] **Tests:** Added/updated and all pass. Historical results and exclusions are recorded below; tests were not rerun for the split. - [x] **Localization:** Structured errors reuse existing CLI-localized messages and hints. - [ ] **Dev docs:** Added/updated. - **New binaries:** None added. - [ ] **Documentation updated:** Follow-up documentation for the new CLI flag. ## Detailed Description of the Pull Request / Additional comments - `src/modules/powerdisplay/PowerDisplay.Cli/Options/CliOptions.cs` and `Commands/PowerDisplayRootCommand.cs` register `--json` as a global presence flag. - `src/modules/powerdisplay/PowerDisplay.Cli/Output/JsonCliOutput.cs` serializes all six existing result types with the source-generated v1.0 contracts and preserves structured error fields while localizing a copy of the error. - `src/modules/powerdisplay/PowerDisplay.Cli/Program.cs` selects the renderer before handling parse errors; help and version output keep their existing behavior. - `src/modules/powerdisplay/PowerDisplay.Cli.UnitTests/` covers serialization, stdout/stderr routing, localized errors, flag placement, and renderer selection. The eight changed files are independent of Command Palette. Existing contracts and project references are sufficient; this PR adds no dependency or IPC schema change. ## Validation Steps Performed - Split verification: this PR contains exactly the eight CLI and CLI-test files from original #50432 at `0936fecded49935870bf8016f5260b27b635959f`, with identical file contents. - `git diff --check` passed. The two-PR stack reconstructs the original repository tree exactly. - Builds/tests were not rerun for this history-only split; no source code was changed by the split. - Historical validation reported in the original PR: Release/x64 build of `PowerDisplay.Cli.UnitTests` through `tools/build/build.ps1` passed with exit code 0; VSTest passed **108/108**, excluding `CliPipeClientTests`. - That real-pipe class was excluded after two failures in a prior full run (116/118 passed) attributed to the installed PowerDisplay occupying the same pipe name. Those tests remain unvalidated in isolation.
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
Add Power Display: Profiles and a Power Display settings shortcut to the PowerToys Command Palette extension. Users can search saved display profiles, see their monitor counts and modification times, and apply a profile directly from Command Palette. Profile actions can also be restored in pinned commands and the dock.
PR Checklist
Detailed Description of the Pull Request / Additional comments
src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Modules/PowerDisplayModuleCommandProvider.csregisters the profiles page and settings shortcut. Profile commands respect Power Display's enablement setting and GPO policy.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Pages/PowerDisplayProfilesPage.csshows profile names with IDs, monitor counts, and local modification times. It loads asynchronously on each visit, provides refresh/retry actions, and links to settings when no profiles exist. Leaving the page cancels its load; an older response cannot replace data from a later visit.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayCliService.csinvokesprofiles --jsonandapply-profile <ID> --json, reusingPowerDisplay.Contractsand validating the response command, schema version, payload, and error/exit-code consistency.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayProcessRunner.cshandles executable discovery, separate process arguments, concurrent output reads, timeout, and cancellation.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/PowerDisplay/ApplyPowerDisplayProfileCommand.csshows localized feedback, dismisses Command Palette after success, and keeps it open on failure. Success feedback explains that unsupported or unavailable monitor settings may have been skipped.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayProfileCommandResolver.csrestores commands by stable profile ID, initially with fallback metadata. Restored items share one profile query per provider restoration batch and receive current names and details asynchronously. A failed metadata query preserves the invokable action.src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/PowerToysExtensionCommandsProvider.csstarts a fresh resolver batch on reload and cancels pending work on disposal. If a restored profile name arrives during an active main-page search, a fresh search may be needed before the profile appears.Validation Steps Performed
git diff --checkagainstmainpassed.