More refactoring

This commit is contained in:
TheXamlGuy
2024-01-11 19:52:48 +00:00
parent 7ccfedb5e2
commit 814c806240
16 changed files with 125 additions and 78 deletions
@@ -0,0 +1,26 @@
namespace Hyperbar.Windows.Primary;
public class WidgetComponentViewModelFactory(PrimaryWidgetConfiguration configuration,
IServiceFactory service,
IMediator mediator) :
IFactory<IEnumerable<IWidgetComponentViewModel>>
{
public IEnumerable<IWidgetComponentViewModel> Create()
{
foreach (PrimaryCommandConfiguration item in configuration)
{
if (item is KeyAcceleratorCommandConfiguration keyAcceleratorCommandConfiguration)
{
yield return service.Create<WidgetButtonViewModel>(keyAcceleratorCommandConfiguration.Icon, new Action(async () =>
await mediator.SendAsync(new KeyAcceleratorRequest((VirtualKey)keyAcceleratorCommandConfiguration.Key,
keyAcceleratorCommandConfiguration.Modifiers?.Select(modifier => (VirtualKey)modifier).ToArray()))));
}
if (item is ProcessCommandConfiguration processCommandConfiguration)
{
yield return service.Create<WidgetButtonViewModel>(processCommandConfiguration.Icon, new Action(async () =>
await mediator.SendAsync(new ProcessRequest(processCommandConfiguration.Path))));
}
}
}
}