More refreshing

This commit is contained in:
Michael Jolley
2025-12-02 16:23:27 -06:00
parent 638935284a
commit 817162ef8e
8 changed files with 47 additions and 31 deletions

View File

@@ -69,7 +69,7 @@
This is present due to a bug in CsWinRT where WPF projects cause the analyzer to fail.
-->
<PackageVersion Include="Microsoft.Windows.CsWinRT" Version="2.2.0" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.6901" />
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.7175" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.8.250907003" />
<PackageVersion Include="Microsoft.WindowsAppSDK.AI" Version="1.8.37" />
<PackageVersion Include="Microsoft.WindowsAppSDK.Runtime" Version="1.8.250907003" />

View File

@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Microsoft.CmdPal.UI.Core</RootNamespace>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<WinUISDKReferences>false</WinUISDKReferences>
</PropertyGroup>
</Project>

View File

@@ -9,6 +9,7 @@ using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using CommunityToolkit.Mvvm.ComponentModel;
using ManagedCommon;
using Microsoft.CmdPal.UI.ViewModels.Services;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Windows.Foundation;
@@ -25,7 +26,7 @@ public partial class AppStateModel : ObservableObject
// STATE HERE
// Make sure that you make the setters public (JsonSerializer.Deserialize will fail silently otherwise)!
// Make sure that any new types you add are added to JsonSerializationContext!
public RecentCommandsManager RecentCommands { get; set; } = new();
public RecentCommandsService RecentCommands { get; set; } = new();
public List<string> RunHistory { get; set; } = [];

View File

@@ -231,7 +231,7 @@ public sealed partial class CommandProviderWrapper
private void CommandProvider_ItemsChanged(object sender, IItemsChangedEventArgs args) =>
// We don't want to handle this ourselves - we want the
// TopLevelCommandManager to know about this, so they can remove
// TopLevelCommandService to know about this, so they can remove
// our old commands from their own list.
//
// In handling this, a call will be made to `LoadTopLevelCommands` to

View File

@@ -14,6 +14,7 @@ using Microsoft.CmdPal.Ext.Apps.Programs;
using Microsoft.CmdPal.Ext.Apps.State;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CmdPal.UI.ViewModels.Properties;
using Microsoft.CmdPal.UI.ViewModels.Services;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
@@ -38,9 +39,9 @@ public partial class MainListPage : DynamicListPage,
"com.microsoft.cmdpal.builtin.remotedesktop",
];
private readonly TopLevelCommandManager _tlcManager;
private readonly TopLevelCommandService _tlcService;
private readonly SettingsModel _settingsModel;
private readonly AliasManager _aliasManager;
private readonly AliasService _aliasService;
private readonly AppStateModel _appStateModel;
private List<Scored<IListItem>>? _filteredItems;
private List<Scored<IListItem>>? _filteredApps;
@@ -55,18 +56,22 @@ public partial class MainListPage : DynamicListPage,
private CancellationTokenSource? _cancellationTokenSource;
public MainListPage(TopLevelCommandManager topLevelCommandManager, SettingsModel settingsModel, AliasManager aliasManager, AppStateModel appStateModel)
public MainListPage(
TopLevelCommandService topLevelCommandService,
SettingsModel settingsModel,
AliasService aliasService,
AppStateModel appStateModel)
{
Title = Resources.builtin_home_name;
Icon = IconHelpers.FromRelativePath("Assets\\StoreLogo.scale-200.png");
PlaceholderText = Properties.Resources.builtin_main_list_page_searchbar_placeholder;
_aliasManager = aliasManager;
_aliasService = aliasService;
_appStateModel = appStateModel;
_tlcManager = topLevelCommandManager;
_tlcManager.PropertyChanged += TlcManager_PropertyChanged;
_tlcManager.TopLevelCommands.CollectionChanged += Commands_CollectionChanged;
_tlcService = topLevelCommandService;
_tlcService.PropertyChanged += TlcManager_PropertyChanged;
_tlcService.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.
@@ -85,7 +90,7 @@ public partial class MainListPage : DynamicListPage,
_settingsModel = settingsModel;
_settingsModel.SettingsChanged += SettingsChangedHandler;
HotReloadSettings(_settingsModel);
_includeApps = _tlcManager.IsProviderActive(AllAppsCommandProvider.WellKnownId);
_includeApps = _tlcService.IsProviderActive(AllAppsCommandProvider.WellKnownId);
IsLoading = true;
}
@@ -100,7 +105,7 @@ public partial class MainListPage : DynamicListPage,
private void Commands_CollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
_includeApps = _tlcManager.IsProviderActive(AllAppsCommandProvider.WellKnownId);
_includeApps = _tlcService.IsProviderActive(AllAppsCommandProvider.WellKnownId);
if (_includeApps != _filteredItemsIncludesApps)
{
ReapplySearchInBackground();
@@ -129,7 +134,7 @@ public partial class MainListPage : DynamicListPage,
do
{
_refreshRequested.Clear();
lock (_tlcManager.TopLevelCommands)
lock (_tlcService.TopLevelCommands)
{
if (_filteredItemsIncludesApps == _includeApps)
{
@@ -160,9 +165,9 @@ public partial class MainListPage : DynamicListPage,
{
if (string.IsNullOrEmpty(SearchText))
{
lock (_tlcManager.TopLevelCommands)
lock (_tlcService.TopLevelCommands)
{
return _tlcManager
return _tlcService
.TopLevelCommands
.Where(tlc => !string.IsNullOrEmpty(tlc.Title))
.ToArray();
@@ -170,7 +175,7 @@ public partial class MainListPage : DynamicListPage,
}
else
{
lock (_tlcManager.TopLevelCommands)
lock (_tlcService.TopLevelCommands)
{
var limitedApps = new List<Scored<IListItem>>();
@@ -228,11 +233,11 @@ public partial class MainListPage : DynamicListPage,
return;
}
if (_aliasManager.CheckAlias(newSearch))
if (_aliasService.CheckAlias(newSearch))
{
if (_filteredItemsIncludesApps != _includeApps)
{
lock (_tlcManager.TopLevelCommands)
lock (_tlcService.TopLevelCommands)
{
_filteredItemsIncludesApps = _includeApps;
ClearResults();
@@ -248,7 +253,7 @@ public partial class MainListPage : DynamicListPage,
return;
}
var commands = _tlcManager.TopLevelCommands;
var commands = _tlcService.TopLevelCommands;
lock (commands)
{
if (token.IsCancellationRequested)
@@ -486,13 +491,13 @@ public partial class MainListPage : DynamicListPage,
private bool ActuallyLoading()
{
var allApps = AllAppsCommandProvider.Page;
return allApps.IsLoading || _tlcManager.IsLoading;
return allApps.IsLoading || _tlcService.IsLoading;
}
// Almost verbatim ListHelpers.ScoreListItem, but also accounting for the
// fact that we want fallback handlers down-weighted, so that they don't
// _always_ show up first.
internal static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem, IRecentCommandsManager history)
internal static int ScoreTopLevelItem(string query, IListItem topLevelOrAppItem, IRecentCommandsService history)
{
var title = topLevelOrAppItem.Title;
if (string.IsNullOrWhiteSpace(title))
@@ -601,7 +606,7 @@ public partial class MainListPage : DynamicListPage,
public void Receive(ClearSearchMessage message) => SearchText = string.Empty;
public void Receive(UpdateFallbackItemsMessage message) => RaiseItemsChanged(_tlcManager.TopLevelCommands.Count);
public void Receive(UpdateFallbackItemsMessage message) => RaiseItemsChanged(_tlcService.TopLevelCommands.Count);
private void SettingsChangedHandler(SettingsModel sender, object? args) => HotReloadSettings(sender);
@@ -612,8 +617,8 @@ public partial class MainListPage : DynamicListPage,
_cancellationTokenSource?.Cancel();
_cancellationTokenSource?.Dispose();
_tlcManager.PropertyChanged -= TlcManager_PropertyChanged;
_tlcManager.TopLevelCommands.CollectionChanged -= Commands_CollectionChanged;
_tlcService.PropertyChanged -= TlcManager_PropertyChanged;
_tlcService.TopLevelCommands.CollectionChanged -= Commands_CollectionChanged;
if (_settingsModel is not null)
{

View File

@@ -13,12 +13,11 @@ using Microsoft.CmdPal.Core.Common.Helpers;
using Microsoft.CmdPal.Core.Common.Services;
using Microsoft.CmdPal.Core.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CmdPal.UI.ViewModels.Services;
using Microsoft.CommandPalette.Extensions;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.Extensions.Logging;
namespace Microsoft.CmdPal.UI.ViewModels.ViewModels;
namespace Microsoft.CmdPal.UI.ViewModels.Services;
public partial class TopLevelCommandService : ObservableObject,
IRecipient<ReloadCommandsMessage>,
@@ -336,7 +335,7 @@ public partial class TopLevelCommandService : ObservableObject,
try
{
await extension.StartExtensionAsync().WaitAsync(TimeSpan.FromSeconds(10));
return new CommandProviderWrapper(extension, _taskScheduler, logger, _aliasManager, _hotkeyManager);
return new CommandProviderWrapper(extension, _taskScheduler, logger, _aliasService, _hotkeyManager);
}
catch (Exception ex)
{
@@ -430,7 +429,7 @@ public partial class TopLevelCommandService : ObservableObject,
void IPageContext.ShowException(Exception ex, string? extensionHint)
{
var message = DiagnosticsHelper.BuildExceptionMessage(ex, extensionHint ?? "TopLevelCommandManager");
var message = DiagnosticsHelper.BuildExceptionMessage(ex, extensionHint ?? "TopLevelCommandService");
_commandPaletteHost.Log(message);
}

View File

@@ -185,7 +185,7 @@ public partial class SettingsViewModel : INotifyPropertyChanged
private IEnumerable<CommandProviderWrapper> GetCommandProviders()
{
var manager = _serviceProvider.GetService<TopLevelCommandManager>()!;
var manager = _serviceProvider.GetService<TopLevelCommandService>()!;
var allProviders = manager.CommandProviders;
return allProviders;
}

View File

@@ -226,7 +226,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
{
GenerateId();
FetchAliasFromAliasManager();
FetchAliasFromAliasService();
UpdateHotkey();
UpdateTags();
UpdateInitialIcon();
@@ -275,7 +275,7 @@ public sealed partial class TopLevelViewModel : ObservableObject, IListItem
UpdateTags();
}
private void FetchAliasFromAliasManager()
private void FetchAliasFromAliasService()
{
if (_aliasService is not null)
{