Skip to content

Commit

Permalink
adjust for perf
Browse files Browse the repository at this point in the history
  • Loading branch information
jgonz120 committed Dec 17, 2024
1 parent 00e9ff4 commit 4f2531a
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<UserControl
x:Name="PackageDetailsTab"
x:Class="NuGet.PackageManagement.UI.PackageDetailsTabControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Expand Down Expand Up @@ -134,9 +135,10 @@
Margin="0,5,0,0"/>
</DataTemplate>
<DataTemplate DataType="{x:Type vm:ReadmePreviewViewModel}">
<nuget:PackageReadmeControl
<ContentControl
Margin="22,0,0,0"
x:Name="_packageReadmeControl"/>
Content="{Binding ElementName=PackageDetailsTab, Path=PackageReadmeControl}"
/>
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ public PackageDetailsTabControl()
{
InitializeComponent();
DataContext = new PackageDetailsTabViewModel();
PackageReadmeControl = new PackageReadmeControl();
}

public PackageReadmeControl PackageReadmeControl { get; private set; }

public void Dispose()
{
Dispose(disposing: true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ private async ValueTask InitializeAsync(PackageManagerModel model, INuGetUILogge
_nugetPackageFileService = await _serviceBroker.GetProxyAsync<INuGetPackageFileService>(NuGetServices.PackageFileService, CancellationToken.None);

await _packageDetail._packageDetailsTabControl.PackageDetailsTabViewModel.InitializeAsync(_detailModel, _nugetPackageFileService, _topPanel.Filter, settings.SelectedPackageMetadataTab);

await _packageDetail._packageDetailsTabControl.PackageReadmeControl.InitializeAsync();
await InitPackageSourcesAsync(settings, CancellationToken.None);
ApplySettings(settings, Settings);
_initialized = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Windows.Controls;
using Microsoft.VisualStudio.Markdown.Platform;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Threading;
using NuGet.PackageManagement.UI.ViewModels;
using NuGet.VisualStudio;
using NuGet.VisualStudio.Telemetry;
Expand All @@ -30,6 +31,22 @@ public PackageReadmeControl()

public ReadmePreviewViewModel ReadmeViewModel { get => (ReadmePreviewViewModel)DataContext; }

public async Task InitializeAsync()
{
if (_markdownPreview is null)
{
await TaskScheduler.Default;
var componentModel = await AsyncServiceProvider.GlobalProvider.GetComponentModelAsync();
var markdownPreviewSingleton = componentModel.GetService<MarkdownPreviewSingleton>();
await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
_markdownPreview = markdownPreviewSingleton.GetInstance();
}
if (descriptionMarkdownPreview.Content is null)
{
descriptionMarkdownPreview.Content = _markdownPreview.VisualElement;
}
}

private void ReadmeViewModel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(ReadmePreviewViewModel.ReadmeMarkdown))
Expand Down Expand Up @@ -79,18 +96,13 @@ private void PackageReadmeControl_Unloaded(object sender, RoutedEventArgs e)
{
await _markdownPreview.UpdateContentAsync("", ScrollHint.None);
});
ReadmeViewModel.PropertyChanged -= ReadmeViewModel_PropertyChanged;
}
}

private void PackageReadmeControl_Loaded(object sender, RoutedEventArgs e)
{
NuGetUIThreadHelper.JoinableTaskFactory.Run(async () =>
{
var componentModel = await AsyncServiceProvider.GlobalProvider.GetComponentModelAsync();
var markdownPreviewSingleton = componentModel.GetService<MarkdownPreviewSingleton>();
_markdownPreview = markdownPreviewSingleton.GetInstance();
descriptionMarkdownPreview.Content = _markdownPreview.VisualElement;
await UpdateMarkdownAsync();
});
}
Expand Down

0 comments on commit 4f2531a

Please sign in to comment.