-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use WinGet API to improve Quick Fix results (#17614)
## Summary of the Pull Request Improves Quick Fix's suggestions to use WinGet API and actually query winget for packages based on the missing command. To interact with the WinGet API, we need the `Microsoft.WindowsPackageManager.ComInterop` NuGet package. `Microsoft.WindowsPackageManager.ComInterop.Additional.targets` is used to copy over the winmd into CascadiaPackage. The build variable `TerminalWinGetInterop` is used to import the package properly. `WindowsPackageManagerFactory` is used as a centralized way to generate the winget objects. Long-term, we may need to do manual activation for elevated sessions, which this class can easily be extended to support. In the meantime, we'll just use the normal `winrt::create_instance` on all sessions. In `TerminalPage`, we conduct the search asynchronously when a missing command was found. Search results are limited to 20 packages. We try to retrieve packages with the following filters set, then fallback into the next step: 1. `PackageMatchField::Command`, `PackageFieldMatchOption::StartsWithCaseInsensitive` 2. `PackageMatchField::Name`, `PackageFieldMatchOption::ContainsCaseInsensitive` 3. `PackageMatchField::Moniker`, `PackageFieldMatchOption::ContainsCaseInsensitive` This aligns with the Microsoft.WinGet.CommandNotFound PowerShell module ([link to relevant code](https://github.com/microsoft/winget-command-not-found/blob/9bc83617b94f6dc88e1fc9599e1c859bc3adf96f/src/WinGetCommandNotFoundFeedbackPredictor.cs#L165-L202)). Closes #17378 Closes #17631 Support for elevated sessions tracked in #17677 ## References - https://github.com/microsoft/winget-cli/blob/master/src/Microsoft.Management.Deployment/PackageManager.idl: winget object documentation ## Validation Steps Performed - [X] unelevated sessions --> winget query performed and presented - [X] elevated sessions --> nothing happens (got rid of `winget install {}` suggestion)
- Loading branch information
1 parent
1de142b
commit dbbc581
Showing
19 changed files
with
216 additions
and
20 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
build/rules/Microsoft.WindowsPackageManager.ComInterop.Additional.targets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. --> | ||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<Native-Platform Condition="'$(Platform)' == 'Win32'">x86</Native-Platform> | ||
<Native-Platform Condition="'$(Platform)' != 'Win32'">$(Platform)</Native-Platform> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="$(WinGetPackageRoot)\lib\Microsoft.Management.Deployment.winmd"> | ||
<IsWinMDFile>true</IsWinMDFile> | ||
</Reference> | ||
</ItemGroup> | ||
<Target Name="_FixWinGetWinmdPackaging" BeforeTargets="_ComputeAppxPackagePayload"> | ||
<ItemGroup> | ||
<PackagingOutputs Include="$(WinGetPackageRoot)\lib\Microsoft.Management.Deployment.winmd"> | ||
<OutputGroup>CustomOutputGroupForPackaging</OutputGroup> | ||
<ProjectName>$(ProjectName)</ProjectName> | ||
<TargetPath>Microsoft.Management.Deployment.winmd</TargetPath> | ||
</PackagingOutputs> | ||
</ItemGroup> | ||
</Target> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
// | ||
// Module Name: | ||
// - WindowsPackageManagerFactory.h | ||
// | ||
// Abstract: | ||
// - This factory is designed to create production-level instances of WinGet objects. | ||
// Elevated sessions require manual activation of WinGet objects and are not currently supported, | ||
// while non-elevated sessions can use the standard WinRT activation system. | ||
// Author: | ||
// - Carlos Zamora (carlos-zamora) 23-Jul-2024 | ||
|
||
#pragma once | ||
|
||
#include <winrt/Microsoft.Management.Deployment.h> | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
struct WindowsPackageManagerFactory | ||
{ | ||
public: | ||
static winrt::Microsoft::Management::Deployment::PackageManager CreatePackageManager() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::PackageManager>(PackageManagerGuid, CLSCTX_ALL); | ||
} | ||
|
||
static winrt::Microsoft::Management::Deployment::FindPackagesOptions CreateFindPackagesOptions() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::FindPackagesOptions>(FindPackageOptionsGuid, CLSCTX_ALL); | ||
} | ||
|
||
static winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions CreateCreateCompositePackageCatalogOptions() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::CreateCompositePackageCatalogOptions>(CreateCompositePackageCatalogOptionsGuid, CLSCTX_ALL); | ||
} | ||
|
||
static winrt::Microsoft::Management::Deployment::InstallOptions CreateInstallOptions() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::InstallOptions>(InstallOptionsGuid, CLSCTX_ALL); | ||
} | ||
|
||
static winrt::Microsoft::Management::Deployment::UninstallOptions CreateUninstallOptions() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::UninstallOptions>(UninstallOptionsGuid, CLSCTX_ALL); | ||
} | ||
|
||
static winrt::Microsoft::Management::Deployment::PackageMatchFilter CreatePackageMatchFilter() | ||
{ | ||
return winrt::create_instance<winrt::Microsoft::Management::Deployment::PackageMatchFilter>(PackageMatchFilterGuid, CLSCTX_ALL); | ||
} | ||
|
||
private: | ||
static constexpr winrt::guid PackageManagerGuid{ 0xC53A4F16, 0x787E, 0x42A4, { 0xB3, 0x04, 0x29, 0xEF, 0xFB, 0x4B, 0xF5, 0x97 } }; | ||
static constexpr winrt::guid FindPackageOptionsGuid{ 0x572DED96, 0x9C60, 0x4526, { 0x8F, 0x92, 0xEE, 0x7D, 0x91, 0xD3, 0x8C, 0x1A } }; | ||
static constexpr winrt::guid CreateCompositePackageCatalogOptionsGuid{ 0x526534B8, 0x7E46, 0x47C8, { 0x84, 0x16, 0xB1, 0x68, 0x5C, 0x32, 0x7D, 0x37 } }; | ||
static constexpr winrt::guid InstallOptionsGuid{ 0x1095F097, 0xEB96, 0x453B, { 0xB4, 0xE6, 0x16, 0x13, 0x63, 0x7F, 0x3B, 0x14 } }; | ||
static constexpr winrt::guid UninstallOptionsGuid{ 0xE1D9A11E, 0x9F85, 0x4D87, { 0x9C, 0x17, 0x2B, 0x93, 0x14, 0x3A, 0xDB, 0x8D } }; | ||
static constexpr winrt::guid PackageMatchFilterGuid{ 0xD02C9DAF, 0x99DC, 0x429C, { 0xB5, 0x03, 0x4E, 0x50, 0x4E, 0x4A, 0xB0, 0x00 } }; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.