PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

Refactor async void methods to async Task in PowerRenameViewModel

Open Copilot opened this issue 1 month ago • 1 comments

Summary of the Pull Request

Converts InstallHeifExtension and InstallAvifExtension from async void to async Task methods, addressing exception handling and testability concerns raised in PR #44466.

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

Async void methods prevent proper exception propagation and cannot be awaited in tests. Changed both extension installer methods to return Task and use AsyncCommand instead of RelayCommand.

Before:

public ICommand InstallHeifExtensionCommand => new RelayCommand(InstallHeifExtension);

private async void InstallHeifExtension()
{
    try
    {
        await Launcher.LaunchUriAsync(new Uri(HeifExtensionStoreUri));
    }
    catch (Exception ex)
    {
        Logger.LogError("Failed to open HEIF extension store page", ex);
    }
}

After:

public ICommand InstallHeifExtensionCommand => new AsyncCommand(InstallHeifExtensionAsync);

private async Task InstallHeifExtensionAsync()
{
    try
    {
        await Launcher.LaunchUriAsync(new Uri(HeifExtensionStoreUri));
    }
    catch (Exception ex)
    {
        Logger.LogError("Failed to open HEIF extension store page", ex);
    }
}

Pattern follows existing AsyncCommand usage in MouseWithoutBordersPage.xaml.cs.

Validation Steps Performed

  • Code review: No issues
  • Security scan: No issues
  • Follows existing codebase patterns

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

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 -c Release --no-restore verters/EnvironmentStateToTitleConverter.cs rep *AsyncCommand cher/ResultList.-l /home/REDACTED/.loclass.*AsyncRelayCommand\|class.*AsyncCommand grep -l *AsyncCommand NativeMethods.cs nfig/composer/vendor/bin/grep *AsyncCommand cherWrapper.cs ndor/bin/grep grep (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