Wire up the disposer for cleaning up unused objects, i.e disposing a VM will remove it from the view
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class WidgetComponentViewModelFactory(IServiceFactory service,
|
||||
IMediator mediator) :
|
||||
IViewModelFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
|
||||
{
|
||||
public async ValueTask<IWidgetComponentViewModel?> CreateAsync(PrimaryCommandConfiguration value)
|
||||
{
|
||||
if (value is KeyAcceleratorCommandConfiguration keyAcceleratorCommand)
|
||||
{
|
||||
return await ValueTask.FromResult(service.Create<WidgetButtonViewModel>(keyAcceleratorCommand.Id, keyAcceleratorCommand.Icon,
|
||||
new RelayCommand(async () => await mediator.SendAsync(new KeyAcceleratorRequest((VirtualKey)
|
||||
keyAcceleratorCommand.Key, keyAcceleratorCommand.Modifiers?
|
||||
.Select(modifier => (VirtualKey)modifier).ToArray())))));
|
||||
}
|
||||
|
||||
if (value is ProcessCommandConfiguration commandConfiguration)
|
||||
{
|
||||
return await ValueTask.FromResult(service.Create<WidgetButtonViewModel>(commandConfiguration.Id,
|
||||
commandConfiguration.Icon, new RelayCommand(async () =>
|
||||
await mediator.SendAsync(new ProcessRequest(commandConfiguration.Path)))));
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user