more settings work
This commit is contained in:
@@ -1,17 +1,21 @@
|
|||||||
using Microsoft.UI.Xaml;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.UI.Xaml;
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
using Microsoft.UI.Xaml.Markup;
|
using Microsoft.UI.Xaml.Markup;
|
||||||
|
|
||||||
namespace Hyperbar.UI.Windows;
|
namespace Hyperbar.UI.Windows;
|
||||||
|
|
||||||
public class ViewModelTemplateSelector(IViewModelTemplateProvider descriptors) :
|
public class ViewModelTemplateSelector :
|
||||||
DataTemplateSelector,
|
DataTemplateSelector,
|
||||||
IViewModelTemplateSelector
|
IViewModelTemplateSelector
|
||||||
{
|
{
|
||||||
protected override DataTemplate SelectTemplateCore(object item)
|
protected override DataTemplate SelectTemplateCore(object item)
|
||||||
{
|
{
|
||||||
return descriptors.Get(item.GetType().Name) is Hyperbar.IViewModelTemplate descriptor
|
return item is IObservableViewModel observableViewModel && observableViewModel.ServiceProvider.GetService<IViewModelTemplateProvider>()
|
||||||
? CreateDataTemplate(descriptor)
|
is IViewModelTemplateProvider viewModelTemplateProvider
|
||||||
|
? viewModelTemplateProvider.Get(item.GetType().Name) is IViewModelTemplate viewModelTemplate
|
||||||
|
? CreateDataTemplate(viewModelTemplate)
|
||||||
|
: new DataTemplate()
|
||||||
: new DataTemplate();
|
: new DataTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,12 +23,12 @@ public class ViewModelTemplateSelector(IViewModelTemplateProvider descriptors) :
|
|||||||
DependencyObject container) =>
|
DependencyObject container) =>
|
||||||
SelectTemplateCore(item);
|
SelectTemplateCore(item);
|
||||||
|
|
||||||
private static DataTemplate CreateDataTemplate(Hyperbar.IViewModelTemplate descriptor)
|
private static DataTemplate CreateDataTemplate(IViewModelTemplate template)
|
||||||
{
|
{
|
||||||
string xamlString = @$"
|
string xamlString = @$"
|
||||||
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
|
||||||
xmlns:ui=""using:{descriptor.TemplateType.Namespace}"">
|
xmlns:ui=""using:{template.ViewType.Namespace}"">
|
||||||
<ui:{descriptor.TemplateType.Name} />
|
<ui:{template.ViewType.Name} />
|
||||||
</DataTemplate>";
|
</DataTemplate>";
|
||||||
|
|
||||||
return (DataTemplate)XamlReader.Load(xamlString);
|
return (DataTemplate)XamlReader.Load(xamlString);
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ public class MediaControllerViewModel :
|
|||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
viewModelTemplateSelector = viewModelTemplateSelector;
|
ViewModelTemplateSelector = viewModelTemplateSelector;
|
||||||
|
|
||||||
Add<MediaInformationViewModel>();
|
Add<MediaInformationViewModel>();
|
||||||
|
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerWidgetView"
|
x:Class="Hyperbar.Widget.MediaController.Windows.MediaControllerWidgetView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||||
<FlipView
|
<Button>safsfd</Button>
|
||||||
|
<!--<FlipView
|
||||||
Width="360"
|
Width="360"
|
||||||
ItemTemplateSelector="{Binding ViewModelTemplateSelector}"
|
ItemTemplateSelector="{Binding ViewModelTemplateSelector}"
|
||||||
ItemsSource="{Binding}" />
|
ItemsSource="{Binding}" />-->
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Hyperbar.Widget;
|
namespace Hyperbar.Widget.Primary.Windows;
|
||||||
|
|
||||||
namespace Hyperbar.Widget.Primary.Windows;
|
|
||||||
|
|
||||||
[NotificationHandler(nameof(PrimaryWidgetViewModel))]
|
[NotificationHandler(nameof(PrimaryWidgetViewModel))]
|
||||||
public class PrimaryWidgetViewModel(IServiceProvider serviceProvider,
|
public class PrimaryWidgetViewModel(IServiceProvider serviceProvider,
|
||||||
|
|||||||
@@ -17,9 +17,9 @@ public static class IServiceCollectionExtensions
|
|||||||
{
|
{
|
||||||
services.AddSingleton(provider.GetRequiredService<IList<IXamlMetadataProvider>>());
|
services.AddSingleton(provider.GetRequiredService<IList<IXamlMetadataProvider>>());
|
||||||
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
|
services.AddSingleton(provider.GetRequiredService<IDispatcher>());
|
||||||
|
|
||||||
services.AddTransient<IViewModelTemplateSelector, UI.Windows.ViewModelTemplateSelector>();
|
|
||||||
services.AddTransient<IViewModelTemplateProvider, ViewModelTemplateProvider>();
|
services.AddTransient<IViewModelTemplateProvider, ViewModelTemplateProvider>();
|
||||||
|
services.AddTransient<IViewModelTemplateSelector, ViewModelTemplateSelector>();
|
||||||
|
|
||||||
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
|
services.AddScoped<IVirtualKeyboard, VirtualKeyboard>();
|
||||||
services.AddHandler<KeyAcceleratorHandler>();
|
services.AddHandler<KeyAcceleratorHandler>();
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using Hyperbar.Widget;
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace Hyperbar.Widget.Windows;
|
namespace Hyperbar.Widget.Windows;
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ public static class IServiceCollectionExtensions
|
|||||||
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||||
|
|
||||||
|
services.AddSingleton<IWidgetHostCollection, WidgetHostCollection>();
|
||||||
|
|
||||||
services.AddHandler<WidgetExtensionEnumerator>();
|
services.AddHandler<WidgetExtensionEnumerator>();
|
||||||
services.AddHandler<WidgetExtensionHandler>();
|
services.AddHandler<WidgetExtensionHandler>();
|
||||||
services.AddHandler<WidgetHostHandler>();
|
services.AddHandler<WidgetHostHandler>();
|
||||||
@@ -33,7 +35,7 @@ public static class IServiceCollectionExtensions
|
|||||||
services.AddKeyedTransient(typeof(IWidgetViewModel), key, contentType);
|
services.AddKeyedTransient(typeof(IWidgetViewModel), key, contentType);
|
||||||
services.TryAddKeyedTransient(key, (provider, key) => provider.GetService<IWidgetView>()!);
|
services.TryAddKeyedTransient(key, (provider, key) => provider.GetService<IWidgetView>()!);
|
||||||
|
|
||||||
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate { ViewModelType = contentType, TemplateType = templateType, Key = key });
|
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate { ViewModelType = contentType, ViewType = templateType, Key = key });
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
@@ -56,7 +58,7 @@ public static class IServiceCollectionExtensions
|
|||||||
|
|
||||||
services.AddTransient<IViewModelTemplate>(provider =>
|
services.AddTransient<IViewModelTemplate>(provider =>
|
||||||
new ViewModelTemplate { ViewModelType = contentType,
|
new ViewModelTemplate { ViewModelType = contentType,
|
||||||
TemplateType = templateType, Key = key });
|
ViewType = templateType, Key = key });
|
||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
|
public interface IWidgetHostCollection :
|
||||||
|
IEnumerable<IWidgetHost>
|
||||||
|
{
|
||||||
|
void Add(IWidgetHost widgetHost);
|
||||||
|
}
|
||||||
@@ -26,17 +26,17 @@ public class WidgetBuilder :
|
|||||||
.ConfigureServices((context, services) =>
|
.ConfigureServices((context, services) =>
|
||||||
{
|
{
|
||||||
services.AddSingleton<IWidgetHost, WidgetHost>();
|
services.AddSingleton<IWidgetHost, WidgetHost>();
|
||||||
|
|
||||||
services.AddScoped<IServiceFactory>(provider =>
|
services.AddScoped<IServiceFactory>(provider =>
|
||||||
new ServiceFactory((type, parameters) =>
|
new ServiceFactory((type, parameters) =>
|
||||||
ActivatorUtilities.CreateInstance(provider, type, parameters!)));
|
ActivatorUtilities.CreateInstance(provider, type, parameters!)));
|
||||||
|
|
||||||
services.AddSingleton<SubscriptionCollection>();
|
services.AddScoped<SubscriptionCollection>();
|
||||||
services.AddSingleton<ISubscriptionManager, SubscriptionManager>();
|
services.AddScoped<ISubscriptionManager, SubscriptionManager>();
|
||||||
services.AddTransient<ISubscriber, Subscriber>();
|
services.AddTransient<ISubscriber, Subscriber>();
|
||||||
services.AddTransient<IPublisher, Publisher>();
|
services.AddTransient<IPublisher, Publisher>();
|
||||||
|
|
||||||
services.AddScoped<IMediator, Mediator>();
|
services.AddScoped<IMediator, Mediator>();
|
||||||
|
|
||||||
services.AddScoped<IDisposer, Disposer>();
|
services.AddScoped<IDisposer, Disposer>();
|
||||||
|
|
||||||
services.AddHandler<WidgetAvailabilityChangedHandler>();
|
services.AddHandler<WidgetAvailabilityChangedHandler>();
|
||||||
|
|||||||
@@ -7,16 +7,16 @@ public class WidgetExtensionHandler(IServiceProvider provider,
|
|||||||
IProxyServiceCollection<IWidgetBuilder> typedServices) :
|
IProxyServiceCollection<IWidgetBuilder> typedServices) :
|
||||||
INotificationHandler<Create<WidgetExtension>>
|
INotificationHandler<Create<WidgetExtension>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Create<WidgetExtension> notification,
|
public async Task Handle(Create<WidgetExtension> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if(notification.Value is WidgetExtension widgetExtension)
|
if(args.Value is WidgetExtension widgetExtension)
|
||||||
{
|
{
|
||||||
IWidgetBuilder builder = widgetExtension.Widget.Create();
|
IWidgetBuilder builder = widgetExtension.Widget.Create();
|
||||||
builder.ConfigureServices(args =>
|
builder.ConfigureServices(args =>
|
||||||
{
|
{
|
||||||
args.AddSingleton(widgetExtension.Assembly);
|
args.AddSingleton(widgetExtension.Assembly);
|
||||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IMediator>>());
|
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IPublisher>>());
|
||||||
|
|
||||||
args.AddRange(typedServices.Services);
|
args.AddRange(typedServices.Services);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,24 +3,13 @@ using Microsoft.Extensions.Hosting;
|
|||||||
|
|
||||||
namespace Hyperbar.Widget;
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
public sealed class WidgetHost :
|
public sealed class WidgetHost(IServiceProvider services,
|
||||||
|
IPublisher publisher,
|
||||||
|
IProxyService<IPublisher> proxyPublisher,
|
||||||
|
IEnumerable<IHostedService> hostedServices) :
|
||||||
IWidgetHost
|
IWidgetHost
|
||||||
{
|
{
|
||||||
private readonly IServiceProvider services;
|
private readonly IPublisher publisher = publisher;
|
||||||
private readonly IPublisher publisher;
|
|
||||||
private readonly IProxyService<IMediator> proxyMediator;
|
|
||||||
private readonly IEnumerable<IHostedService> hostedServices;
|
|
||||||
|
|
||||||
public WidgetHost(IServiceProvider services,
|
|
||||||
IPublisher publisher,
|
|
||||||
IProxyService<IMediator> proxyMediator,
|
|
||||||
IEnumerable<IHostedService> hostedServices)
|
|
||||||
{
|
|
||||||
this.services = services;
|
|
||||||
this.publisher = publisher;
|
|
||||||
this.proxyMediator = proxyMediator;
|
|
||||||
this.hostedServices = hostedServices;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WidgetConfiguration Configuration =>
|
public WidgetConfiguration Configuration =>
|
||||||
Services.GetRequiredService<WidgetConfiguration>();
|
Services.GetRequiredService<WidgetConfiguration>();
|
||||||
@@ -39,7 +28,7 @@ public sealed class WidgetHost :
|
|||||||
await service.StartAsync(cancellationToken);
|
await service.StartAsync(cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxyMediator.Proxy is IMediator mediator)
|
if (proxyPublisher.Proxy is IPublisher publisher)
|
||||||
{
|
{
|
||||||
await publisher.PublishAsync(new Started<IWidgetHost>(this),
|
await publisher.PublishAsync(new Started<IWidgetHost>(this),
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
using System.Collections;
|
||||||
|
|
||||||
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
|
public class WidgetHostCollection :
|
||||||
|
IWidgetHostCollection
|
||||||
|
|
||||||
|
{
|
||||||
|
private readonly List<IWidgetHost> hosts = [];
|
||||||
|
|
||||||
|
public void Add(IWidgetHost host)
|
||||||
|
{
|
||||||
|
hosts.Add(host);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<IWidgetHost> GetEnumerator() =>
|
||||||
|
hosts.GetEnumerator();
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator() =>
|
||||||
|
hosts.GetEnumerator();
|
||||||
|
}
|
||||||
@@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
namespace Hyperbar.Widget;
|
namespace Hyperbar.Widget;
|
||||||
|
|
||||||
public class WidgetHostHandler :
|
public class WidgetHostHandler(IWidgetHostCollection widgetHosts) :
|
||||||
INotificationHandler<Create<IWidgetHost>>
|
INotificationHandler<Create<IWidgetHost>>
|
||||||
{
|
{
|
||||||
public async Task Handle(Create<IWidgetHost> notification,
|
public async Task Handle(Create<IWidgetHost> args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (notification.Value is IWidgetHost host)
|
if (args.Value is IWidgetHost host)
|
||||||
{
|
{
|
||||||
|
widgetHosts.Add(host);
|
||||||
|
|
||||||
if (host.Services.GetServices<IInitializer>() is
|
if (host.Services.GetServices<IInitializer>() is
|
||||||
IEnumerable<IInitializer> initializations)
|
IEnumerable<IInitializer> initializations)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -43,8 +43,9 @@ public partial class App :
|
|||||||
services.AddTransient<INavigationTargetProvider, NavigationTargetProvider>();
|
services.AddTransient<INavigationTargetProvider, NavigationTargetProvider>();
|
||||||
|
|
||||||
services.AddTransient<IViewModelContentBinder, ViewModelContentBinder>();
|
services.AddTransient<IViewModelContentBinder, ViewModelContentBinder>();
|
||||||
services.AddTransient<IViewModelTemplateSelector, ViewModelTemplateSelector>();
|
|
||||||
services.AddTransient<IViewModelTemplateProvider, ViewModelTemplateProvider>();
|
services.AddTransient<IViewModelTemplateProvider, ViewModelTemplateProvider>();
|
||||||
|
services.AddTransient<IViewModelTemplateSelector, ViewModelTemplateSelector>();
|
||||||
|
|
||||||
services.AddHandler<AppConfigurationChangedHandler>();
|
services.AddHandler<AppConfigurationChangedHandler>();
|
||||||
services.AddConfiguration((AppConfiguration args) =>
|
services.AddConfiguration((AppConfiguration args) =>
|
||||||
@@ -65,8 +66,11 @@ public partial class App :
|
|||||||
|
|
||||||
services.AddContentTemplate<GeneralSettingsNavigationViewModel, GeneralSettingsNavigationView>();
|
services.AddContentTemplate<GeneralSettingsNavigationViewModel, GeneralSettingsNavigationView>();
|
||||||
services.AddContentTemplate<WidgetSettingsNavigationViewModel, WidgetSettingsNavigationView>();
|
services.AddContentTemplate<WidgetSettingsNavigationViewModel, WidgetSettingsNavigationView>();
|
||||||
|
services.AddContentTemplate<WidgetNavigationViewModel, WidgetNavigationView>();
|
||||||
|
|
||||||
services.AddContentTemplate<WidgetSettingsViewModel, WidgetSettingsView>("WidgetSettings");
|
services.AddContentTemplate<WidgetSettingsViewModel, WidgetSettingsView>("WidgetSettings");
|
||||||
|
|
||||||
|
services.AddHandler<WidgetNavigationViewModelEnumerator>();
|
||||||
services.AddTransient<IInitializer, AppInitializer>();
|
services.AddTransient<IInitializer, AppInitializer>();
|
||||||
})
|
})
|
||||||
.Build();
|
.Build();
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
<None Remove="SecondaryView.xaml" />
|
<None Remove="SecondaryView.xaml" />
|
||||||
<None Remove="SettingsButtonView.xaml" />
|
<None Remove="SettingsButtonView.xaml" />
|
||||||
<None Remove="SettingsView.xaml" />
|
<None Remove="SettingsView.xaml" />
|
||||||
|
<None Remove="WidgetNavigationView.xaml" />
|
||||||
<None Remove="WidgetSettingsNavigationView.xaml" />
|
<None Remove="WidgetSettingsNavigationView.xaml" />
|
||||||
<None Remove="WidgetSettingsView.xaml" />
|
<None Remove="WidgetSettingsView.xaml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -58,6 +59,11 @@
|
|||||||
<ProjectReference Include="..\Hyperbar.Widget\Hyperbar.Widget.csproj" />
|
<ProjectReference Include="..\Hyperbar.Widget\Hyperbar.Widget.csproj" />
|
||||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Page Update="WidgetNavigationView.xaml">
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Page Update="WidgetSettingsView.xaml">
|
<Page Update="WidgetSettingsView.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
|||||||
@@ -18,5 +18,4 @@ public partial class PrimaryViewModel(IViewModelTemplateSelector viewModelTempla
|
|||||||
private int index = index;
|
private int index = index;
|
||||||
|
|
||||||
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,9 @@
|
|||||||
<Window
|
<Window
|
||||||
x:Class="Hyperbar.Windows.SettingsView"
|
x:Class="Hyperbar.Windows.SettingsView"
|
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||||
|
xmlns:interactivity="using:Microsoft.Xaml.Interactivity">
|
||||||
<Window.SystemBackdrop>
|
<Window.SystemBackdrop>
|
||||||
<MicaBackdrop />
|
<MicaBackdrop />
|
||||||
</Window.SystemBackdrop>
|
</Window.SystemBackdrop>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<NavigationViewItem
|
||||||
|
x:Class="Hyperbar.Windows.WidgetNavigationView"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
Content="dsfsdvfsd" />
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
|
|
||||||
|
namespace Hyperbar.Windows;
|
||||||
|
|
||||||
|
public sealed partial class WidgetNavigationView :
|
||||||
|
NavigationViewItem
|
||||||
|
{
|
||||||
|
public WidgetNavigationView() =>
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace Hyperbar.Windows;
|
using Hyperbar.UI.Windows;
|
||||||
|
|
||||||
|
namespace Hyperbar.Windows;
|
||||||
|
|
||||||
public class WidgetNavigationViewModel(IServiceProvider serviceProvider,
|
public class WidgetNavigationViewModel(IServiceProvider serviceProvider,
|
||||||
IServiceFactory serviceFactory,
|
IServiceFactory serviceFactory,
|
||||||
@@ -6,6 +8,4 @@ public class WidgetNavigationViewModel(IServiceProvider serviceProvider,
|
|||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string text) :
|
string text) :
|
||||||
NavigationViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
|
NavigationViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer, text);
|
||||||
{
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
using System.Security.Policy;
|
||||||
|
|
||||||
|
namespace Hyperbar.Windows;
|
||||||
|
|
||||||
|
public class WidgetNavigationViewModelEnumerator(IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher) :
|
||||||
|
INotificationHandler<Enumerate<WidgetNavigationViewModel>>
|
||||||
|
{
|
||||||
|
public async Task Handle(Enumerate<WidgetNavigationViewModel> args,
|
||||||
|
CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
await publisher.PublishAsync(new Create<WidgetNavigationViewModel>(serviceFactory
|
||||||
|
.Create<WidgetNavigationViewModel>("fo")), nameof(WidgetSettingsNavigationViewModel), cancellationToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,10 +6,15 @@
|
|||||||
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:interactions="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:ui="using:Hyperbar.UI.Windows"
|
xmlns:ui="using:Hyperbar.UI.Windows"
|
||||||
Content="Widgets">
|
Content="Widgets"
|
||||||
|
MenuItemsSource="{Binding}"
|
||||||
|
SelectsOnInvoked="False">
|
||||||
<interactivity:Interaction.Behaviors>
|
<interactivity:Interaction.Behaviors>
|
||||||
<interactions:EventTriggerBehavior EventName="Tapped">
|
<interactions:EventTriggerBehavior EventName="Tapped">
|
||||||
<ui:NavigateAction Name="WidgetSettings" TargetName="Settings" />
|
<ui:NavigateAction Name="WidgetSettings" TargetName="Settings" />
|
||||||
</interactions:EventTriggerBehavior>
|
</interactions:EventTriggerBehavior>
|
||||||
|
<interactions:EventTriggerBehavior EventName="Loaded">
|
||||||
|
<interactions:InvokeCommandAction Command="{Binding InitializeCommand}" />
|
||||||
|
</interactions:EventTriggerBehavior>
|
||||||
</interactivity:Interaction.Behaviors>
|
</interactivity:Interaction.Behaviors>
|
||||||
</NavigationViewItem>
|
</NavigationViewItem>
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
using Hyperbar.Widget;
|
|
||||||
using Microsoft.UI.Xaml.Controls;
|
using Microsoft.UI.Xaml.Controls;
|
||||||
|
|
||||||
namespace Hyperbar.Windows;
|
namespace Hyperbar.Windows;
|
||||||
|
|||||||
@@ -1,9 +1,16 @@
|
|||||||
namespace Hyperbar.Windows;
|
using Hyperbar.UI.Windows;
|
||||||
|
|
||||||
public class WidgetSettingsNavigationViewModel(IServiceProvider serviceProvider,
|
namespace Hyperbar.Windows;
|
||||||
|
|
||||||
|
[NotificationHandler(nameof(WidgetSettingsNavigationViewModel))]
|
||||||
|
public class WidgetSettingsNavigationViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
|
||||||
|
IServiceProvider serviceProvider,
|
||||||
IServiceFactory serviceFactory,
|
IServiceFactory serviceFactory,
|
||||||
IPublisher publisher,
|
IPublisher publisher,
|
||||||
ISubscriber subscriber,
|
ISubscriber subscriber,
|
||||||
IDisposer disposer,
|
IDisposer disposer,
|
||||||
string text) :
|
string text) :
|
||||||
NavigationViewModel<WidgetNavigationViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer, text);
|
NavigationViewModel<WidgetNavigationViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
|
||||||
|
{
|
||||||
|
public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,18 +2,13 @@
|
|||||||
|
|
||||||
namespace Hyperbar.Windows;
|
namespace Hyperbar.Windows;
|
||||||
|
|
||||||
public class WidgetSettingsViewModel :
|
public class WidgetSettingsViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
|
||||||
ObservableCollectionViewModel<INavigationViewModel>
|
IServiceProvider serviceProvider,
|
||||||
|
IServiceFactory serviceFactory,
|
||||||
|
IPublisher publisher,
|
||||||
|
ISubscriber subscriber,
|
||||||
|
IDisposer disposer) :
|
||||||
|
ObservableCollectionViewModel<IObservableViewModel>(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
||||||
{
|
{
|
||||||
public WidgetSettingsViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
|
public IViewModelTemplateSelector ViewModelTemplateSelector { get; } = viewModelTemplateSelector;
|
||||||
IServiceProvider serviceProvider,
|
}
|
||||||
IServiceFactory serviceFactory,
|
|
||||||
IPublisher publisher,
|
|
||||||
ISubscriber subscriber,
|
|
||||||
IDisposer disposer) : base(serviceProvider, serviceFactory, publisher, subscriber, disposer)
|
|
||||||
{
|
|
||||||
ViewModelTemplateSelector = viewModelTemplateSelector;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IViewModelTemplateSelector ViewModelTemplateSelector { get; }
|
|
||||||
}
|
|
||||||
@@ -165,7 +165,7 @@ public static class IServiceCollectionExtensions
|
|||||||
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate
|
services.AddTransient<IViewModelTemplate>(provider => new ViewModelTemplate
|
||||||
{
|
{
|
||||||
ViewModelType = contentType,
|
ViewModelType = contentType,
|
||||||
TemplateType = templateType,
|
ViewType = templateType,
|
||||||
Key = key
|
Key = key
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -184,8 +184,8 @@ public static class IServiceCollectionExtensions
|
|||||||
|
|
||||||
services.AddSingleton<IMediator, Mediator>();
|
services.AddSingleton<IMediator, Mediator>();
|
||||||
|
|
||||||
services.AddSingleton<IProxyService<IMediator>>(provider =>
|
services.AddSingleton<IProxyService<IPublisher>>(provider =>
|
||||||
new ProxyService<IMediator>(provider.GetRequiredService<IMediator>()));
|
new ProxyService<IPublisher>(provider.GetRequiredService<IPublisher>()));
|
||||||
|
|
||||||
services.AddSingleton<IDisposer, Disposer>();
|
services.AddSingleton<IDisposer, Disposer>();
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ public interface IViewModelTemplate
|
|||||||
{
|
{
|
||||||
object Key { get; set; }
|
object Key { get; set; }
|
||||||
|
|
||||||
Type TemplateType { get; set; }
|
Type ViewType { get; set; }
|
||||||
|
|
||||||
Type ViewModelType { get; set; }
|
Type ViewModelType { get; set; }
|
||||||
}
|
}
|
||||||
@@ -12,11 +12,10 @@ public class NavigateHandler(IServiceProvider provider,
|
|||||||
public async Task Handle(Navigate args,
|
public async Task Handle(Navigate args,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (viewModelTemplateProvider.Get(args.Name)
|
if (viewModelTemplateProvider.Get(args.Name)
|
||||||
is IViewModelTemplate viewModelTemplate)
|
is IViewModelTemplate viewModelTemplate)
|
||||||
{
|
{
|
||||||
if (provider.GetRequiredKeyedService(viewModelTemplate.TemplateType,
|
if (provider.GetRequiredKeyedService(viewModelTemplate.ViewType,
|
||||||
viewModelTemplate.Key) is object view &&
|
viewModelTemplate.Key) is object view &&
|
||||||
provider.GetRequiredKeyedService(viewModelTemplate.ViewModelType,
|
provider.GetRequiredKeyedService(viewModelTemplate.ViewModelType,
|
||||||
viewModelTemplate.Key) is object viewModel)
|
viewModelTemplate.Key) is object viewModel)
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ public partial class ObservableCollectionViewModel<TViewModel> :
|
|||||||
public IDisposer Disposer { get; private set; }
|
public IDisposer Disposer { get; private set; }
|
||||||
|
|
||||||
public ICommand InitializeCommand =>
|
public ICommand InitializeCommand =>
|
||||||
new AsyncRelayCommand(CoreInitializeAsync);
|
new AsyncRelayCommand(CoreInitializeAsync);
|
||||||
|
|
||||||
bool IList.IsFixedSize => false;
|
bool IList.IsFixedSize => false;
|
||||||
|
|
||||||
|
|||||||
@@ -43,8 +43,7 @@ public class Publisher(ISubscriptionManager subscriptionManager,
|
|||||||
List<object?> handlers = provider.GetServices(typeof(INotificationHandler<>)
|
List<object?> handlers = provider.GetServices(typeof(INotificationHandler<>)
|
||||||
.MakeGenericType(notificationType)).ToList();
|
.MakeGenericType(notificationType)).ToList();
|
||||||
|
|
||||||
foreach (object? handler in subscriptionManager.GetHandlers(notificationType,
|
foreach (object? handler in subscriptionManager.GetHandlers(notificationType, key))
|
||||||
$"{key?.ToString()}:{notificationType}"))
|
|
||||||
{
|
{
|
||||||
handlers.Add(handler);
|
handlers.Add(handler);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ public class SubscriptionManager(SubscriptionCollection subscriptions) :
|
|||||||
{
|
{
|
||||||
public IEnumerable<object?> GetHandlers(Type notificationType, object key)
|
public IEnumerable<object?> GetHandlers(Type notificationType, object key)
|
||||||
{
|
{
|
||||||
|
var d = subscriptions;
|
||||||
if (subscriptions.TryGetValue($"{key?.ToString()}:{notificationType}",
|
if (subscriptions.TryGetValue($"{key?.ToString()}:{notificationType}",
|
||||||
out List<WeakReference>? subscribers))
|
out List<WeakReference>? subscribers))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ public record ViewModelTemplate :
|
|||||||
{
|
{
|
||||||
public required Type ViewModelType { get; set; }
|
public required Type ViewModelType { get; set; }
|
||||||
|
|
||||||
public required Type TemplateType { get; set; }
|
public required Type ViewType { get; set; }
|
||||||
|
|
||||||
public required object Key { get; set; }
|
public required object Key { get; set; }
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
namespace Hyperbar;
|
namespace Hyperbar;
|
||||||
|
|
||||||
public class ViewModelTemplateProvider(IEnumerable<IViewModelTemplate> viewModelTemplates) :
|
public class ViewModelTemplateProvider(IEnumerable<IViewModelTemplate> viewModelTemplates) :
|
||||||
IViewModelTemplateProvider
|
IViewModelTemplateProvider
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user