Skip to content

Commit

Permalink
Make sure the main page still shows loading when apps are loading
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii committed Feb 13, 2025
1 parent ac60bf2 commit 1ae3be4
Showing 1 changed file with 16 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public partial class MainListPage : DynamicListPage,
private readonly TopLevelCommandManager _tlcManager;
private IEnumerable<IListItem>? _filteredItems;

private bool _appsLoading = true;
private bool _startedAppLoad;

public MainListPage(IServiceProvider serviceProvider)
{
Name = "Command Palette";
Expand All @@ -39,6 +36,17 @@ public MainListPage(IServiceProvider serviceProvider)
_tlcManager.PropertyChanged += TlcManager_PropertyChanged;
_tlcManager.TopLevelCommands.CollectionChanged += Commands_CollectionChanged;

// The all apps page will kick off a BG thread to start loading apps.
// We just want to know when it is done.
var allApps = AllAppsCommandProvider.Page;
allApps.PropChanged += (s, p) =>
{
if (p.PropertyName == nameof(allApps.IsLoading))
{
IsLoading = ActuallyLoading();
}
};

WeakReferenceMessenger.Default.Register<ClearSearchMessage>(this);
WeakReferenceMessenger.Default.Register<UpdateFallbackItemsMessage>(this);

Expand All @@ -61,12 +69,6 @@ private void TlcManager_PropertyChanged(object? sender, System.ComponentModel.Pr

public override IListItem[] GetItems()
{
if (!_startedAppLoad)
{
StartAppLoad();
_startedAppLoad = true;
}

if (string.IsNullOrEmpty(SearchText))
{
lock (_tlcManager.TopLevelCommands)
Expand Down Expand Up @@ -139,20 +141,8 @@ public override void UpdateSearchText(string oldSearch, string newSearch)
private bool ActuallyLoading()
{
var tlcManager = _serviceProvider.GetService<TopLevelCommandManager>()!;
return _appsLoading || tlcManager.IsLoading;
}

private void StartAppLoad()
{
// This _should_ start a background thread to start loading all the apps.
// It _feels_ like it does it's work on the main thread though, like it
// slows down startup... which doesn't make sense.
_ = Task.Run(() =>
{
_ = AppCache.Instance.Value;
_appsLoading = false;
IsLoading = ActuallyLoading();
});
var allApps = AllAppsCommandProvider.Page;
return allApps.IsLoading || tlcManager.IsLoading;
}

// Almost verbatim ListHelpers.ScoreListItem, but also accounting for the
Expand Down Expand Up @@ -187,9 +177,9 @@ private static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem)

var scores = new[]
{
nameMatch.Score,
(descriptionMatch.Score - 4) / 2,
isFallback ? 1 : 0, // Always give fallbacks a chance
nameMatch.Score,
(descriptionMatch.Score - 4) / 2,
isFallback ? 1 : 0, // Always give fallbacks a chance
};
var max = scores.Max();
var finalScore = (max / (isFallback ? 3 : 1))
Expand Down

0 comments on commit 1ae3be4

Please sign in to comment.