UI threading work
This commit is contained in:
@@ -39,14 +39,17 @@ public partial class App :
|
||||
services.AddSingleton<IDisposer, Disposer>();
|
||||
|
||||
services.AddHostedService<AppService>();
|
||||
services.AddConfiguration<AppConfiguration>();
|
||||
|
||||
services.AddTransient<IInitializer, AppInitializer>();
|
||||
services.AddTransient<ITemplateFactory, TemplateFactory>();
|
||||
|
||||
services.AddTransient<DesktopFlyout>();
|
||||
services.AddSingleton<DesktopFlyout>();
|
||||
|
||||
services.AddContentTemplate<WidgetBarViewModel, WidgetBarView>();
|
||||
|
||||
services.AddHandler<AppConfigurationChangedHandler>();
|
||||
|
||||
//services.AddWidgetProvider<MediaControllerWidgetProvider>();
|
||||
services.AddWidgetProvider<PrimaryWidgetProvider>();
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using Hyperbar.Windows.Controls;
|
||||
|
||||
namespace Hyperbar.Windows;
|
||||
|
||||
public class AppConfiguration
|
||||
{
|
||||
public DesktopFlyoutPlacement Placement { get; set; }
|
||||
}
|
||||
@@ -5,14 +5,15 @@ namespace Hyperbar.Windows;
|
||||
|
||||
public class AppInitializer([FromKeyedServices(nameof(WidgetBarViewModel))] WidgetBarView view,
|
||||
[FromKeyedServices(nameof(WidgetBarViewModel))] WidgetBarViewModel viewModel,
|
||||
DesktopFlyout desktopFlyout) :
|
||||
DesktopFlyout desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
view.DataContext = viewModel;
|
||||
|
||||
desktopFlyout.Placement = DesktopFlyoutPlacement.Top;
|
||||
desktopFlyout.Placement = configuration.Placement;
|
||||
desktopFlyout.Content = view;
|
||||
|
||||
return Task.CompletedTask;
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using Hyperbar.Windows.Controls;
|
||||
|
||||
namespace Hyperbar.Windows.Primary;
|
||||
|
||||
public class AppConfigurationChangedHandler(DesktopFlyout desktopFlyout,
|
||||
AppConfiguration configuration) :
|
||||
INotificationHandler<ConfigurationChanged<AppConfiguration>>
|
||||
{
|
||||
public ValueTask Handle(ConfigurationChanged<AppConfiguration> notification, CancellationToken cancellationToken)
|
||||
{
|
||||
desktopFlyout.Placement = configuration.Placement;
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -6,9 +6,11 @@ namespace Hyperbar;
|
||||
public class Mediator(IServiceProvider provider) :
|
||||
IMediator
|
||||
{
|
||||
private readonly SynchronizationContext? context = SynchronizationContext.Current;
|
||||
|
||||
private readonly ConditionalWeakTable<Type, dynamic> subjects = [];
|
||||
|
||||
public async ValueTask PublishAsync<TNotification>(TNotification notification,
|
||||
public ValueTask PublishAsync<TNotification>(TNotification notification,
|
||||
CancellationToken cancellationToken = default)
|
||||
where TNotification :
|
||||
INotification
|
||||
@@ -26,8 +28,10 @@ public class Mediator(IServiceProvider provider) :
|
||||
|
||||
foreach (INotificationHandler<TNotification> handler in handlers)
|
||||
{
|
||||
await handler.Handle(notification, cancellationToken);
|
||||
context?.Post(async state => await handler.Handle(notification, cancellationToken), null);
|
||||
}
|
||||
|
||||
return ValueTask.CompletedTask;
|
||||
}
|
||||
|
||||
public ValueTask<TResponse> SendAsync<TResponse>(IRequest<TResponse> request,
|
||||
|
||||
Reference in New Issue
Block a user