diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs index 176fae30d2..d907277ddc 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Apps/AppListItem.cs @@ -17,12 +17,25 @@ public sealed partial class AppListItem : ListItem { private readonly AppCommand _appCommand; private readonly AppItem _app; - private readonly Lazy
_details; private readonly Lazy> _iconLoadTask; + private readonly Lazy> _detailsLoadTask; private InterlockedBoolean _isLoadingIcon; + private InterlockedBoolean _isLoadingDetails; - public override IDetails? Details { get => _details.Value; set => base.Details = value; } + public override IDetails? Details + { + get + { + if (_isLoadingDetails.Set()) + { + _ = LoadDetailsAsync(); + } + + return base.Details; + } + set => base.Details = value; + } public override IIconInfo? Icon { @@ -52,16 +65,22 @@ public sealed partial class AppListItem : ListItem MoreCommands = AddPinCommands(_app.Commands!, isPinned); - _details = new Lazy
(() => - { - var t = BuildDetails(); - t.Wait(); - return t.Result; - }); - + _detailsLoadTask = new Lazy>(BuildDetails); _iconLoadTask = new Lazy>(async () => await FetchIcon(useThumbnails)); } + private async Task LoadDetailsAsync() + { + try + { + Details = await _detailsLoadTask.Value; + } + catch (Exception ex) + { + Logger.LogWarning($"Failed to load details for {AppIdentifier}\n{ex}"); + } + } + private async Task LoadIconAsync() { try