From aaa68fa351eb72543bea1a4cef09ac1bcb5c3042 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 23 Oct 2025 15:32:39 -0500 Subject: [PATCH] look ma, those are from CmdPal --- .../Messages/CommandsReloadedMessage.cs | 7 +++ .../TopLevelCommandManager.cs | 2 + .../cmdpal/Microsoft.CmdPal.UI/App.xaml.cs | 2 + .../Dock/DockWindow.xaml.cs | 49 +++++++++++++++++-- 4 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CommandsReloadedMessage.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CommandsReloadedMessage.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CommandsReloadedMessage.cs new file mode 100644 index 0000000000..f9e2d70200 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/Messages/CommandsReloadedMessage.cs @@ -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(); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs index 5dd41280bf..e11e644f41 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/TopLevelCommandManager.cs @@ -308,6 +308,8 @@ public partial class TopLevelCommandManager : ObservableObject, timer.Stop(); Logger.LogDebug($"Loading extensions took {timer.ElapsedMilliseconds} ms"); + + WeakReferenceMessenger.Default.Send(); } private async Task StartExtensionWithTimeoutAsync(IExtensionWrapper extension) diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs index 9ba41a08fb..5386babeae 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs @@ -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(); + services.AddSingleton(); services.AddSingleton(); return services.BuildServiceProvider(); diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockWindow.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockWindow.xaml.cs index c5eef88dbb..d62207a853 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockWindow.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Dock/DockWindow.xaml.cs @@ -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()!; _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 { + 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 EndItems { get; } = new(); + public DockViewModel(TopLevelCommandManager tlcManager, SettingsModel settings) + { + _topLevelCommandManager = tlcManager; + WeakReferenceMessenger.Default.Register(this); + } + + private static string[] _startCommands = ["com.microsoft.cmdpal.windowwalker", "com.microsoft.cmdpal.timedate"]; + + private void SetupBands() + { + List 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