From d86c5da7a9fdd107b74b4a265ead1d3c2b04c2b1 Mon Sep 17 00:00:00 2001 From: TheXamlGuy Date: Sun, 7 Jan 2024 13:18:38 +0000 Subject: [PATCH] fixed fetching configuration from root --- .../PrimaryWidgetConfiguration.cs | 2 +- .../WidgetComponentMappinglFactory.cs | 13 +++++++++---- .../Lifecycles/IServiceCollectionExtensions.cs | 7 +------ Hyperbar.Windows/Views/WidgetButtonView.xaml | 5 ++++- Hyperbar/Extensions/IServiceCollectionExtensions.cs | 5 +++-- 5 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Hyperbar.Windows.Primary/PrimaryWidgetConfiguration.cs b/Hyperbar.Windows.Primary/PrimaryWidgetConfiguration.cs index 59057c6..1017ca5 100644 --- a/Hyperbar.Windows.Primary/PrimaryWidgetConfiguration.cs +++ b/Hyperbar.Windows.Primary/PrimaryWidgetConfiguration.cs @@ -5,6 +5,6 @@ public class PrimaryWidgetConfiguration : { public static PrimaryWidgetConfiguration Defaults => new() { - new KeyAcceleratorCommandConfiguration { Icon = "Test", Key = "Test", Modifiers = ["Test", "Test"] } + new KeyAcceleratorCommandConfiguration { Icon = "\uE720", Key = "Test", Modifiers = ["Test", "Test"] } }; } \ No newline at end of file diff --git a/Hyperbar.Windows.Primary/WidgetComponentMappinglFactory.cs b/Hyperbar.Windows.Primary/WidgetComponentMappinglFactory.cs index fc91b99..033561f 100644 --- a/Hyperbar.Windows.Primary/WidgetComponentMappinglFactory.cs +++ b/Hyperbar.Windows.Primary/WidgetComponentMappinglFactory.cs @@ -5,21 +5,26 @@ public class WidgetComponentMappingFactory : { private readonly PrimaryWidgetConfiguration configuration; private readonly IServiceFactory service; + private readonly IMediator mediator; public WidgetComponentMappingFactory(PrimaryWidgetConfiguration configuration, - IServiceFactory service) + IServiceFactory service, + IMediator mediator) { this.configuration = configuration; this.service = service; + this.mediator = mediator; } public IEnumerable Create() { foreach (IPrimaryCommandConfiguration item in configuration) { - + if (item is KeyAcceleratorCommandConfiguration keyAcceleratorCommand) + { + yield return service.Create(keyAcceleratorCommand.Icon, new Action(() => + mediator.Send(new KeyAcceleratorCommand(VirtualKey.LeftWindows)))); + } } - - return Enumerable.Empty(); } } diff --git a/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs b/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs index 859cb6c..409154a 100644 --- a/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs +++ b/Hyperbar.Windows/Lifecycles/IServiceCollectionExtensions.cs @@ -1,10 +1,8 @@ using Hyperbar.Extensions; using Hyperbar.Windows.Interop; -using Hyperbar.Windows.Primary; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Options; namespace Hyperbar.Windows { @@ -45,11 +43,8 @@ namespace Hyperbar.Windows builder.Create(context, isolatedServices); }).Build(); - services.AddTransient(provider => new WidgetContext(host.Services)); - host.Start(); - - var d = host.Services.GetService>(); + services.AddTransient(provider => host); return services; } diff --git a/Hyperbar.Windows/Views/WidgetButtonView.xaml b/Hyperbar.Windows/Views/WidgetButtonView.xaml index b1651a1..3f631f6 100644 --- a/Hyperbar.Windows/Views/WidgetButtonView.xaml +++ b/Hyperbar.Windows/Views/WidgetButtonView.xaml @@ -9,12 +9,15 @@ + 0 32 32