Skip to content

Commit 5157ffc

Browse files
authored
cmdpal: Skip dependency installs for extensions (#38175)
It appears there are two issues in WinGet regarding the installation of dependencies. microsoft/winget-cli#4661 microsoft/winget-cli#4679 For CmdPal 0.1, we're going to skip installing dependencies to make extension installation more robust. This will mostly work because extensions will depend on the same frameworks as the command palette itself (for now). We will revert this once these two issues are fixed.
1 parent 60bbf07 commit 5157ffc

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.WinGet/Pages/InstallPackageCommand.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace Microsoft.CmdPal.Ext.WinGet.Pages;
1717
public partial class InstallPackageCommand : InvokableCommand
1818
{
1919
private readonly CatalogPackage _package;
20-
2120
private readonly StatusMessage _installBanner = new();
2221
private IAsyncOperationWithProgress<InstallResult, InstallProgress>? _installAction;
2322
private IAsyncOperationWithProgress<UninstallResult, UninstallProgress>? _unInstallAction;
@@ -43,6 +42,8 @@ public partial class InstallPackageCommand : InvokableCommand
4342
private static readonly CompositeFormat UninstallPackageFinishing = System.Text.CompositeFormat.Parse(Properties.Resources.winget_uninstall_package_finishing);
4443
private static readonly CompositeFormat DownloadProgress = System.Text.CompositeFormat.Parse(Properties.Resources.winget_download_progress);
4544

45+
internal bool SkipDependencies { get; set; }
46+
4647
public InstallPackageCommand(CatalogPackage package, bool isInstalled)
4748
{
4849
_package = package;
@@ -96,6 +97,9 @@ public override ICommandResult Invoke()
9697

9798
var installOptions = WinGetStatics.WinGetFactory.CreateInstallOptions();
9899
installOptions.PackageInstallScope = PackageInstallScope.Any;
100+
101+
installOptions.SkipDependencies = SkipDependencies;
102+
99103
_installAction = WinGetStatics.Manager.InstallPackageAsync(_package, installOptions);
100104

101105
var handler = new AsyncOperationProgressHandler<InstallResult, InstallProgress>(OnInstallProgress);

src/modules/cmdpal/exts/Microsoft.CmdPal.Ext.WinGet/Pages/InstallPackageListItem.cs

+25-15
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public InstallPackageListItem(CatalogPackage package)
3131
{
3232
_package = package;
3333

34-
PackageVersionInfo version = _package.DefaultInstallVersion;
34+
var version = _package.DefaultInstallVersion;
3535
var versionTagText = "Unknown";
3636
if (version != null)
3737
{
@@ -49,16 +49,24 @@ public InstallPackageListItem(CatalogPackage package)
4949

5050
private Details? BuildDetails(PackageVersionInfo? version)
5151
{
52-
CatalogPackageMetadata? metadata = version?.GetCatalogPackageMetadata();
52+
var metadata = version?.GetCatalogPackageMetadata();
5353
if (metadata != null)
5454
{
55+
if (metadata.Tags.Where(t => t.Equals(WinGetExtensionPage.ExtensionsTag, StringComparison.OrdinalIgnoreCase)).Any())
56+
{
57+
if (_installCommand != null)
58+
{
59+
_installCommand.SkipDependencies = true;
60+
}
61+
}
62+
5563
var description = string.IsNullOrEmpty(metadata.Description) ? metadata.ShortDescription : metadata.Description;
5664
var detailsBody = $"""
5765
5866
{description}
5967
""";
6068
IconInfo heroIcon = new(string.Empty);
61-
IReadOnlyList<Icon> icons = metadata.Icons;
69+
var icons = metadata.Icons;
6270
if (icons.Count > 0)
6371
{
6472
// There's also a .Theme property we could probably use to
@@ -89,21 +97,23 @@ private List<IDetailsElement> GetDetailsMetadata(CatalogPackageMetadata metadata
8997
{ Properties.Resources.winget_publisher, (metadata.Publisher, metadata.PublisherUrl) },
9098
{ Properties.Resources.winget_copyright, (metadata.Copyright, metadata.CopyrightUrl) },
9199
{ Properties.Resources.winget_license, (metadata.License, metadata.LicenseUrl) },
92-
{ Properties.Resources.winget_release_notes, (metadata.ReleaseNotes, string.Empty) },
100+
{ Properties.Resources.winget_publisher_support, (string.Empty, metadata.PublisherSupportUrl) },
93101

94102
// The link to the release notes will only show up if there is an
95103
// actual URL for the release notes
96104
{ Properties.Resources.winget_view_release_notes, (string.IsNullOrEmpty(metadata.ReleaseNotesUrl) ? string.Empty : Properties.Resources.winget_view_online, metadata.ReleaseNotesUrl) },
97-
{ Properties.Resources.winget_publisher_support, (string.Empty, metadata.PublisherSupportUrl) },
105+
106+
// These can be l o n g
107+
{ Properties.Resources.winget_release_notes, (metadata.ReleaseNotes, string.Empty) },
98108
};
99-
Documentation[] docs = metadata.Documentations.ToArray();
100-
foreach (Documentation? item in docs)
109+
var docs = metadata.Documentations.ToArray();
110+
foreach (var item in docs)
101111
{
102112
simpleData.Add(item.DocumentLabel, (string.Empty, item.DocumentUrl));
103113
}
104114

105115
UriCreationOptions options = default;
106-
foreach (KeyValuePair<string, (string, string)> kv in simpleData)
116+
foreach (var kv in simpleData)
107117
{
108118
var text = string.IsNullOrEmpty(kv.Value.Item1) ? kv.Value.Item2 : kv.Value.Item1;
109119
var target = kv.Value.Item2;
@@ -136,8 +146,8 @@ private List<IDetailsElement> GetDetailsMetadata(CatalogPackageMetadata metadata
136146

137147
private async void UpdatedInstalledStatus()
138148
{
139-
CheckInstalledStatusResult status = await _package.CheckInstalledStatusAsync();
140-
bool isInstalled = _package.InstalledVersion != null;
149+
var status = await _package.CheckInstalledStatusAsync();
150+
var isInstalled = _package.InstalledVersion != null;
141151

142152
// might be an uninstall command
143153
InstallPackageCommand installCommand = new(_package, isInstalled);
@@ -155,8 +165,8 @@ private async void UpdatedInstalledStatus()
155165

156166
if (WinGetStatics.AppSearchCallback != null)
157167
{
158-
Func<string, ICommandItem?> callback = WinGetStatics.AppSearchCallback;
159-
ICommandItem? installedApp = callback(_package.DefaultInstallVersion == null ? _package.Name : _package.DefaultInstallVersion.DisplayName);
168+
var callback = WinGetStatics.AppSearchCallback;
169+
var installedApp = callback(_package.DefaultInstallVersion == null ? _package.Name : _package.DefaultInstallVersion.DisplayName);
160170
if (installedApp != null)
161171
{
162172
this.Command = installedApp.Command;
@@ -193,11 +203,11 @@ private void InstallStateChangedHandler(object? sender, InstallPackageCommand e)
193203
Stopwatch s = new();
194204
Logger.LogDebug($"Starting RefreshPackageCatalogAsync");
195205
s.Start();
196-
PackageCatalogReference[] refs = WinGetStatics.AvailableCatalogs.ToArray();
206+
var refs = WinGetStatics.AvailableCatalogs.ToArray();
197207

198-
foreach (PackageCatalogReference? catalog in refs)
208+
foreach (var catalog in refs)
199209
{
200-
global::Windows.Foundation.IAsyncOperationWithProgress<RefreshPackageCatalogResult, double> operation = catalog.RefreshPackageCatalogAsync();
210+
var operation = catalog.RefreshPackageCatalogAsync();
201211
operation.Wait();
202212
}
203213

0 commit comments

Comments
 (0)