PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

Refactor duplicate HEIF/AVIF extension code into reusable helper

Open Copilot opened this issue 1 month ago • 1 comments

Summary of the Pull Request

Addresses code duplication in PowerRename's HEIF/AVIF extension management by extracting common logic into a reusable StoreExtensionHelper class. Reduces ~60 lines of duplicate code while maintaining identical public API for XAML bindings.

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
  • [ ] Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Changes

  • New StoreExtensionHelper class encapsulates:

    • Package installation status checking with lazy evaluation and caching
    • Store launcher command using AsyncCommand with proper async Task pattern
    • INotifyPropertyChanged implementation for UI binding
  • PowerRenameViewModel refactored to use two helper instances instead of duplicated HEIF/AVIF code:

    // Constructor initializes helpers
    HeifExtension = new StoreExtensionHelper(
        "Microsoft.HEIFImageExtension_8wekyb3d8bbwe",
        "ms-windows-store://pdp/?ProductId=9PMMSR1CGPWG",
        "HEIF");
    
    // Convenience properties delegate to helper
    public bool IsHeifExtensionInstalled => HeifExtension.IsInstalled;
    public ICommand InstallHeifExtensionCommand => HeifExtension.InstallCommand;
    
  • Removed unused imports: System.Linq, Windows.Management.Deployment, Windows.System

Benefits

  • Future store extensions can reuse StoreExtensionHelper without duplication
  • Async command handling uses async Task instead of async void pattern
  • All XAML bindings remain compatible

Validation Steps Performed

Code review and security scan completed with no issues. Build validation deferred to CI due to dependency availability.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot avatar Jan 07 '26 01:01 Copilot

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: /usr/bin/dotnet dotnet build src/settings-ui/Settings.UI/PowerToys.Settings.csproj --configuration Release (dns block)
    • Triggering command: /usr/bin/dotnet dotnet msbuild src/settings-ui/Settings.UI/PowerToys.Settings.csproj /t:Compile /p:Configuration=Release /p:BuildProjectReferences=false /nologo (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot avatar Jan 07 '26 01:01 Copilot

@Copilot solve merge conflict.

moooyo avatar Jan 08 '26 02:01 moooyo

@Copilot solve merge conflict.

Merge conflict resolved successfully. Rebased the branch onto the updated base PR #44466 (commit 21900d4).

The conflict occurred because the base PR added async Task refactoring to the duplicate HEIF/AVIF code, while this PR refactored that duplicate code into a StoreExtensionHelper class. The resolution keeps the helper class approach (which already uses async Task) and removes the now-redundant duplicate code from the base PR.

Changes are ready locally but require force-push to update the remote branch due to rebase. The report_progress tool encounters conflicts when attempting to rebase again, preventing automatic push. Manual force-push may be needed to complete the update.

Local commits after resolving conflict:

  • 0e731e4: Remove unused System.Threading.Tasks import
  • 35d4997: Use AsyncCommand with async Task
  • 33a1a39: Refactor duplicate code into StoreExtensionHelper
  • 1417dde: Initial plan Base: 21900d4 (updated PR #44466)

Copilot avatar Jan 08 '26 02:01 Copilot