get HB widgets showing up again
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class WidgetComponentFactory(IServiceFactory service,
|
||||
public class WidgetComponentFactory(IServiceFactory factory,
|
||||
IMediator mediator,
|
||||
ICache<Guid, IWidgetComponentViewModel> cache) :
|
||||
IFactory<PrimaryCommandConfiguration, IWidgetComponentViewModel?>
|
||||
@@ -13,7 +13,7 @@ public class WidgetComponentFactory(IServiceFactory service,
|
||||
|
||||
if (configuration is KeyAcceleratorCommandConfiguration keyAcceleratorCommandConfiguration)
|
||||
{
|
||||
viewModel = service.Create<WidgetButtonViewModel>(keyAcceleratorCommandConfiguration.Id,
|
||||
viewModel = factory.Create<WidgetButtonViewModel>(keyAcceleratorCommandConfiguration.Id,
|
||||
keyAcceleratorCommandConfiguration.Text, keyAcceleratorCommandConfiguration.Icon,
|
||||
new RelayCommand(async () => await mediator.SendAsync(new KeyAccelerator((VirtualKey)
|
||||
keyAcceleratorCommandConfiguration.Key, keyAcceleratorCommandConfiguration.Modifiers?
|
||||
@@ -32,14 +32,14 @@ public class WidgetComponentFactory(IServiceFactory service,
|
||||
|
||||
if (childCommandConfiguration is ProcessCommandConfiguration childProcessCommandConfiguration)
|
||||
{
|
||||
childViewModel = service.Create<WidgetMenuViewModel>(childProcessCommandConfiguration.Id,
|
||||
childViewModel = factory.Create<WidgetMenuViewModel>(childProcessCommandConfiguration.Id,
|
||||
childProcessCommandConfiguration.Icon, childProcessCommandConfiguration.Text,
|
||||
new RelayCommand(async () => await mediator.SendAsync(new StartProcess(childProcessCommandConfiguration.Path))));
|
||||
}
|
||||
|
||||
if (childCommandConfiguration is KeyAcceleratorCommandConfiguration childKeyAcceleratorCommandConfiguration)
|
||||
{
|
||||
childViewModel = service.Create<WidgetMenuViewModel>(childKeyAcceleratorCommandConfiguration.Id,
|
||||
childViewModel = factory.Create<WidgetMenuViewModel>(childKeyAcceleratorCommandConfiguration.Id,
|
||||
childKeyAcceleratorCommandConfiguration.Text, childKeyAcceleratorCommandConfiguration.Icon,
|
||||
new RelayCommand(async () =>
|
||||
await mediator.SendAsync(new KeyAccelerator((VirtualKey)childKeyAcceleratorCommandConfiguration.Key,
|
||||
@@ -53,14 +53,14 @@ public class WidgetComponentFactory(IServiceFactory service,
|
||||
}
|
||||
}
|
||||
|
||||
viewModel = service.Create<WidgetSplitButtonViewModel>(childViewModels,
|
||||
viewModel = factory.Create<WidgetSplitButtonViewModel>(childViewModels,
|
||||
processCommandConfiguration.Id, processCommandConfiguration.Text,
|
||||
processCommandConfiguration.Icon, new RelayCommand(async () =>
|
||||
await mediator.SendAsync(new StartProcess(processCommandConfiguration.Path))));
|
||||
}
|
||||
else
|
||||
{
|
||||
viewModel = service.Create<WidgetButtonViewModel>(processCommandConfiguration.Id,
|
||||
viewModel = factory.Create<WidgetButtonViewModel>(processCommandConfiguration.Id,
|
||||
processCommandConfiguration.Text, processCommandConfiguration.Icon, new RelayCommand(async () =>
|
||||
await mediator.SendAsync(new StartProcess(processCommandConfiguration.Path))));
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.UI.Xaml;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using Windows.Media.Control;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
@@ -46,6 +47,7 @@ public partial class App :
|
||||
|
||||
services.AddSingleton<DesktopBar>();
|
||||
services.AddContentTemplate<WidgetBarViewModel, WidgetBarView>();
|
||||
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
|
||||
|
||||
services.AddTransient<IProxyServiceCollection<IWidgetBuilder>>(provider =>
|
||||
new ProxyServiceCollection<IWidgetBuilder>(services =>
|
||||
@@ -59,7 +61,6 @@ public partial class App :
|
||||
|
||||
services.AddTransient<IWidgetView, WidgetView>();
|
||||
|
||||
services.AddContentTemplate<WidgetContainerViewModel, WidgetContainerView>();
|
||||
services.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
|
||||
services.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
|
||||
}));
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Rectangle
|
||||
Width="1"
|
||||
Width="10"
|
||||
Height="40"
|
||||
Margin="6,2,6,2"
|
||||
Fill="{ThemeResource DividerStrokeColorDefaultBrush}"
|
||||
Visibility="{Binding Alternate}" />
|
||||
Fill="Red" />
|
||||
<ItemsControl
|
||||
Grid.Column="1"
|
||||
ItemTemplateSelector="{Binding Converter={ui:DataTemplateConverter}}"
|
||||
|
||||
@@ -155,7 +155,9 @@ public static class IServiceCollectionExtensions
|
||||
services.AddHandler<WidgetEnumerationHandler>();
|
||||
services.AddHandler<WidgetAssemblyHandler>();
|
||||
services.AddHandler<WidgetHandler>();
|
||||
services.AddHandler<WidgetHostHander>();
|
||||
services.AddHandler<WidgetHostHandler>();
|
||||
|
||||
services.AddTransient<IFactory<IWidgetHost, WidgetContainerViewModel?>, WidgetContainerFactory>();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
[NotificationHandler(nameof(WidgetBarViewModel))]
|
||||
public partial class WidgetBarViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IEnumerable<WidgetContainerViewModel> items) :
|
||||
ObservableCollectionViewModel<WidgetContainerViewModel>(serviceFactory, mediator, disposer, items),
|
||||
IDisposer disposer) :
|
||||
ObservableCollectionViewModel<WidgetContainerViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
public ITemplateFactory TemplateFactory => templateFactory;
|
||||
|
||||
@@ -7,15 +7,10 @@ public partial class WidgetContainerViewModel(ITemplateFactory templateFactory,
|
||||
IServiceFactory serviceFactory,
|
||||
IMediator mediator,
|
||||
IDisposer disposer,
|
||||
IEnumerable<IWidgetViewModel> items,
|
||||
Guid id,
|
||||
bool alternate) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer, items),
|
||||
Guid id) :
|
||||
ObservableCollectionViewModel<IWidgetViewModel>(serviceFactory, mediator, disposer),
|
||||
ITemplatedViewModel
|
||||
{
|
||||
[ObservableProperty]
|
||||
private bool alternate = alternate;
|
||||
|
||||
[ObservableProperty]
|
||||
private Guid id = id;
|
||||
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
public interface IWidgetHost :
|
||||
IInitializer
|
||||
{
|
||||
WidgetConfiguration Configuration { get; }
|
||||
|
||||
IServiceProvider Services { get; }
|
||||
}
|
||||
|
||||
@@ -50,15 +50,6 @@ public class WidgetBuilder<TConfiguration>(TConfiguration configuration) :
|
||||
public IWidgetHost Build()
|
||||
{
|
||||
IHost host = hostBuilder.Build();
|
||||
|
||||
//if (host.Services.GetRequiredService<IConfigurationInitializer<TConfiguration>>()
|
||||
// is IConfigurationInitializer<TConfiguration> configurationInitializer)
|
||||
//{
|
||||
// configurationInitializer.InitializeAsync()
|
||||
// .GetAwaiter()
|
||||
// .GetResult();
|
||||
//}
|
||||
|
||||
return (IWidgetHost)ActivatorUtilities.CreateInstance(host.Services,
|
||||
typeof(WidgetHost), host);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetContainerFactory(IServiceFactory factory) :
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?>
|
||||
{
|
||||
public WidgetContainerViewModel? Create(IWidgetHost value)
|
||||
{
|
||||
if (value.Services.GetServices<IWidgetViewModel>() is
|
||||
IEnumerable<IWidgetViewModel> viewModels)
|
||||
{
|
||||
return factory.Create<WidgetContainerViewModel>(value.Configuration.Id);
|
||||
}
|
||||
|
||||
return default;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
|
||||
namespace Hyperbar;
|
||||
|
||||
@@ -27,6 +28,8 @@ public class WidgetHost :
|
||||
mediator.Subscribe(this);
|
||||
}
|
||||
|
||||
public WidgetConfiguration Configuration => host.Services.GetRequiredService<WidgetConfiguration>();
|
||||
|
||||
public IServiceProvider Services => host.Services;
|
||||
|
||||
public async Task Handle(Changed<WidgetAvailability> notification,
|
||||
@@ -45,15 +48,14 @@ public class WidgetHost :
|
||||
|
||||
private async Task StartAsync()
|
||||
{
|
||||
if (proxyMediator.Proxy is IMediator mediator)
|
||||
{
|
||||
await mediator.PublishAsync(new Started<IWidgetHost>(this));
|
||||
}
|
||||
|
||||
foreach (IInitializer initializer in initializers)
|
||||
{
|
||||
await initializer.InitializeAsync();
|
||||
}
|
||||
|
||||
|
||||
//if (proxyMediator.Proxy is IMediator mediator)
|
||||
//{
|
||||
// await mediator.PublishAsync(new Started<IWidgetHost>(this));
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetHostHander :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
{
|
||||
public Task Handle(Started<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
// throw new NotImplementedException();
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Hyperbar;
|
||||
|
||||
public class WidgetHostHandler(IMediator mediator,
|
||||
IFactory<IWidgetHost, WidgetContainerViewModel?> factory) :
|
||||
INotificationHandler<Started<IWidgetHost>>,
|
||||
INotificationHandler<Stopped<IWidgetHost>>
|
||||
{
|
||||
public async Task Handle(Started<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value is IWidgetHost host)
|
||||
{
|
||||
if (factory.Create(host) is WidgetContainerViewModel containerViewModel)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<WidgetContainerViewModel>(containerViewModel), nameof(WidgetBarViewModel),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Handle(Stopped<IWidgetHost> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user