mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
Extract EnsureProcessRunning helper to eliminate code duplication (#44235)
## Summary of the Pull Request Addresses code review feedback on #42642 by extracting duplicated process launching logic into a reusable helper method. ## PR Checklist - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments The `ApplyColorTemperature` and `ApplyProfile` custom action handlers contained identical 6-line blocks for process state checking, launching, and synchronization. **Changes:** - Added `EnsureProcessRunning()` helper encapsulating the pattern: check if running → launch if needed → wait for ready signal - Replaced duplicated blocks in both handlers with single helper call **Before:** ```cpp if (!is_process_running()) { Logger::trace(L"PowerDisplay process not running, launching before applying..."); launch_process(); wait_for_process_ready(); } ``` **After:** ```cpp EnsureProcessRunning(); ``` ## Validation Steps Performed Code review and security checks passed. <!-- START COPILOT CODING AGENT TIPS --> --- 💬 We'd love your input! Share your thoughts on Copilot coding agent in our [2 minute survey](https://gh.io/copilot-coding-agent-survey). --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: moooyo <42196638+moooyo@users.noreply.github.com>
This commit is contained in:
@@ -217,6 +217,18 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
// Helper method to ensure PowerDisplay process is running
|
||||
// Checks if process is running, launches it if needed, and waits for ready signal
|
||||
void EnsureProcessRunning()
|
||||
{
|
||||
if (!is_process_running())
|
||||
{
|
||||
Logger::trace(L"PowerDisplay process not running, launching");
|
||||
launch_process();
|
||||
wait_for_process_ready();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
PowerDisplayModule()
|
||||
{
|
||||
@@ -360,13 +372,7 @@ public:
|
||||
Logger::trace(L"Event name: {}", CommonSharedConstants::APPLY_COLOR_TEMPERATURE_POWER_DISPLAY_EVENT);
|
||||
|
||||
// Ensure PowerDisplay process is running before signaling event
|
||||
if (!is_process_running())
|
||||
{
|
||||
Logger::trace(L"PowerDisplay process not running, launching before applying color temperature");
|
||||
launch_process();
|
||||
// Wait for process to signal ready
|
||||
wait_for_process_ready();
|
||||
}
|
||||
EnsureProcessRunning();
|
||||
|
||||
if (m_hApplyColorTemperatureEvent)
|
||||
{
|
||||
@@ -391,13 +397,7 @@ public:
|
||||
Logger::trace(L"ApplyProfile action received");
|
||||
|
||||
// Ensure PowerDisplay process is running before signaling event
|
||||
if (!is_process_running())
|
||||
{
|
||||
Logger::trace(L"PowerDisplay process not running, launching before applying profile");
|
||||
launch_process();
|
||||
// Wait for process to signal ready
|
||||
wait_for_process_ready();
|
||||
}
|
||||
EnsureProcessRunning();
|
||||
|
||||
if (m_hApplyProfileEvent)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user