Skip to content

[CmdPal] Add Power Display profile switching - #50432

Draft
Yu Leng (moooyo) wants to merge 10 commits into
mainfrom
codex/cmdpal-powerdisplay-profiles
Draft

[CmdPal] Add Power Display profile switching#50432
Yu Leng (moooyo) wants to merge 10 commits into
mainfrom
codex/cmdpal-powerdisplay-profiles

Conversation

@moooyo

@moooyo Yu Leng (moooyo) commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

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

  • Related issue: none linked.
  • Communication: Discussed with core contributors.
  • Tests: Added/updated and all pass. New unit tests are included; local execution at the current PR head is pending.
  • Localization: All new end-user-facing strings can be localized.
  • Dev docs: Added/updated.
  • New binaries: None added.
  • Documentation updated: Command Palette documentation remains pending.

Detailed Description of the Pull Request / Additional comments

  • Profile browsing and settings access: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Modules/PowerDisplayModuleCommandProvider.cs registers 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.cs shows 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.
  • Profile application through the existing CLI: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayCliService.cs invokes profiles --json and apply-profile <ID> --json, reusing PowerDisplay.Contracts and validating the response command, schema version, payload, and error/exit-code consistency. src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayProcessRunner.cs handles executable discovery, separate process arguments, concurrent output reads, timeout, and cancellation. src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Commands/PowerDisplay/ApplyPowerDisplayProfileCommand.cs shows 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.
  • Restoring saved profile actions: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.PowerToys/Helpers/PowerDisplayProfileCommandResolver.cs restores 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.cs starts 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.
  • Resources and project wiring: Add localizable Power Display strings, reference the existing contracts project from the extension and tests, include the CLI/contracts projects in the Command Palette solution filters, and wire the new extension tests into the existing test project.

Validation Steps Performed

  • Added unit tests for CLI arguments and response validation, stable command IDs, apply feedback, restored metadata and cancellation, and profile-page loading/refresh/reentry. CLI service tests use a fake process runner.
  • git diff --check against main passed.
  • XML/JSON parsing passed for the affected project files, resource file, and solution filters.
  • Local builds and unit tests have not been run at the current PR head.
  • Interactive Command Palette validation, including pinned/dock actions and switching profiles on physical monitors, remains pending.

@github-actions github-actions Bot added Product-Command Palette Refers to the Command Palette utility Product-PowerDisplay labels Sep 7, 2026
@moooyo
Yu Leng (moooyo) force-pushed the codex/cmdpal-powerdisplay-profiles branch from 0936fec to 14f5ade Compare September 7, 2026 04:53
@moooyo
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.
Base automatically changed from codex/powerdisplay-cli-json to main September 7, 2026 05:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Product-Command Palette Refers to the Command Palette utility Product-PowerDisplay

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant