look ma, those are from CmdPal

This commit is contained in:
Mike Griese
2025-10-23 15:32:39 -05:00
parent d9e4133b5a
commit aaa68fa351
4 changed files with 57 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace Microsoft.CmdPal.UI.ViewModels.Messages;
public record CommandsReloadedMessage();

View File

@@ -308,6 +308,8 @@ public partial class TopLevelCommandManager : ObservableObject,
timer.Stop();
Logger.LogDebug($"Loading extensions took {timer.ElapsedMilliseconds} ms");
WeakReferenceMessenger.Default.Send<CommandsReloadedMessage>();
}
private async Task<CommandProviderWrapper?> StartExtensionWithTimeoutAsync(IExtensionWrapper extension)

View File

@@ -22,6 +22,7 @@ using Microsoft.CmdPal.Ext.WindowsSettings;
using Microsoft.CmdPal.Ext.WindowsTerminal;
using Microsoft.CmdPal.Ext.WindowWalker;
using Microsoft.CmdPal.Ext.WinGet;
using Microsoft.CmdPal.UI.Dock;
using Microsoft.CmdPal.UI.Helpers;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
@@ -164,6 +165,7 @@ public partial class App : Application
// ViewModels
services.AddSingleton<ShellViewModel>();
services.AddSingleton<DockViewModel>();
services.AddSingleton<IPageViewModelFactoryService, CommandPalettePageViewModelFactory>();
return services.BuildServiceProvider();

View File

@@ -6,8 +6,12 @@ using System.Collections.ObjectModel;
using System.Runtime.InteropServices;
using CommunityToolkit.Mvvm.Messaging;
using ManagedCommon;
using Microsoft.CmdPal.Core.Common;
using Microsoft.CmdPal.Core.ViewModels;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.CommandPalette.Extensions.Toolkit;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Composition;
using Microsoft.UI.Composition.SystemBackdrops;
using Microsoft.UI.Dispatching;
@@ -59,7 +63,7 @@ public sealed partial class DockWindow : WindowEx, // , IRecipient<OpenSettingsM
// _settings = DockSettingsWindow.LoadUserSettings();
_settings = new(); // TODO!
viewModel = new DockViewModel();
viewModel = App.Current.Services.GetService<DockViewModel>()!;
_dock = new DockControl(viewModel);
InitializeComponent();
@@ -581,11 +585,13 @@ internal static class DockSettingsToViews
}
}
internal sealed partial class DockViewModel : IDisposable
internal sealed partial class DockViewModel : IDisposable, IRecipient<CommandsReloadedMessage>
{
private readonly TopLevelCommandManager _topLevelCommandManager;
// private TaskbarWindowsService _taskbarWindows;
// private Settings _settings;
private Microsoft.UI.Dispatching.DispatcherQueue dispatcherQueue = Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread();
private DispatcherQueue _dispatcherQueue = DispatcherQueue.GetForCurrentThread();
private DispatcherQueue _updateWindowsQueue = DispatcherQueueController.CreateOnDedicatedThread().DispatcherQueue;
// TODO! make these DockBandViewModel
@@ -593,9 +599,46 @@ internal sealed partial class DockViewModel : IDisposable
public ObservableCollection<CommandItemViewModel> EndItems { get; } = new();
public DockViewModel(TopLevelCommandManager tlcManager, SettingsModel settings)
{
_topLevelCommandManager = tlcManager;
WeakReferenceMessenger.Default.Register<CommandsReloadedMessage>(this);
}
private static string[] _startCommands = ["com.microsoft.cmdpal.windowwalker", "com.microsoft.cmdpal.timedate"];
private void SetupBands()
{
List<CommandItemViewModel> newBands = new();
foreach (var commandId in _startCommands)
{
var topLevelCommand = _topLevelCommandManager.LookupCommand(commandId);
if (topLevelCommand is not null)
{
// var band = CreateBandItem(topLevelCommand);
newBands.Add(topLevelCommand.ItemViewModel);
}
}
var beforeCount = StartItems.Count;
var afterCount = newBands.Count;
_dispatcherQueue.TryEnqueue(() =>
{
ListHelpers.InPlaceUpdateList(StartItems, newBands, out var removed);
Logger.LogDebug($"({beforeCount}) -> ({afterCount}), Removed {removed?.Count ?? 0} items");
});
}
public void Dispose()
{
}
public void Receive(CommandsReloadedMessage message)
{
SetupBands();
CoreLogger.LogDebug("Bands reloaded");
}
}
internal sealed class DockBandViewModel