Repository: microsoft/PowerToys
File: src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/Commands/UninstallApplicationCommand.cs (C#)

Code before:
        _uwpTarget = target ?? throw new ArgumentNullException(nameof(target));
    }

    public UninstallApplicationCommand(Win32Program target)
    {
        Name = Resources.uninstall_application;
        Icon = Icons.UninstallApplicationIcon;
        _win32Target = target ?? throw new ArgumentNullException(nameof(target));
    }

    public static async Task<CommandResult> UninstallUwpAppAsync(UWPApplication app)
    {
        if (string.IsNullOrWhiteSpace(app.Package.FullName))
        {
            Logger.LogError($"Critical error while uninstalling: packageFullName cannot be null or empty.");
            return CommandResult.ShowToast(new ToastArgs()
            {
                Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_failed), app.DisplayName),
                Result = CommandResult.KeepOpen(),
            });
        }

        try
        {
            // Which timeout to use for the uninstallation operation?
            using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60));
            var packageManager = new PackageManager();

            var result = await packageManager.RemovePackageAsync(app.Package.FullName);

            if (result.ErrorText is not null && result.ErrorText.Length > 0)
            {
                Logger.LogError($"Failed to uninstall {app.Package.FullName}: {result.ErrorText}");
                return CommandResult.ShowToast(new ToastArgs()
                {
                    Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_failed), app.DisplayName),
                    Result = CommandResult.KeepOpen(),
                });
            }

            // TODO: Update the Search results after uninstalling the app
            return CommandResult.ShowToast(new ToastArgs()
            {
                Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_successful), app.DisplayName),
                Result = CommandResult.KeepOpen(),
            });
        }
        catch (OperationCanceledException)
        {
            Logger.LogError($"Timeout exceeded while uninstalling {app.Package.FullName}");
            return CommandResult.ShowToast(new ToastArgs()

Review comment (bug):
Command Palette can also show a confirmation dialog. It might be a good idea to ask the user before uninstalling the package, in case they accidentally select the wrong menu item.

Docs: [CommandResult.Confirm](https://learn.microsoft.com/en-us/windows/powertoys/command-palette/microsoft-commandpalette-extensions-toolkit/commandresult_confirm)

Usage: 
https://github.com/mKpwnz/PowerToys/blob/main/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.System/EmptyRecycleBinConfirmation.cs

Code after:

    public UninstallApplicationCommand(UWPApplication target)
    {
        Name = Resources.uninstall_application;
        Icon = Icons.UninstallApplicationIcon;
        _uwpTarget = target ?? throw new ArgumentNullException(nameof(target));
    }

    public UninstallApplicationCommand(Win32Program target)
    {
        Name = Resources.uninstall_application;
        Icon = Icons.UninstallApplicationIcon;
        _win32Target = target ?? throw new ArgumentNullException(nameof(target));
    }

    private async Task<CommandResult> UninstallUwpAppAsync(UWPApplication app)
    {
        if (string.IsNullOrWhiteSpace(app.Package.FullName))
        {
            Logger.LogError($"Critical error while uninstalling: packageFullName cannot be null or empty.");
            return CommandResult.ShowToast(new ToastArgs()
            {
                Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_failed), app.DisplayName),
                Result = CommandResult.KeepOpen(),
            });
        }

        try
        {
            // Which timeout to use for the uninstallation operation?
            using (var cts = new CancellationTokenSource(TimeSpan.FromSeconds(60)))
            {
                var packageManager = new PackageManager();
                var result = await packageManager.RemovePackageAsync(app.Package.FullName).AsTask(cts.Token);

                if (result.ErrorText is not null && result.ErrorText.Length > 0)
                {
                    Logger.LogError($"Failed to uninstall {app.Package.FullName}: {result.ErrorText}");
                    return CommandResult.ShowToast(new ToastArgs()
                    {
                        Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_failed), app.DisplayName),
                        Result = CommandResult.KeepOpen(),
                    });
                }
            }

            // TODO: Update the Search results after uninstalling the app - unsure how to do this yet.
            return CommandResult.ShowToast(new ToastArgs()
            {
                Message = string.Format(CultureInfo.CurrentCulture, CompositeFormat.Parse(Resources.uninstall_application_successful), app.DisplayName),
                Result = CommandResult.GoHome(),