Added messaging pipeline

This commit is contained in:
TheXamlGuy
2024-01-06 13:57:18 +00:00
parent 4a27534e39
commit 53537aa4c7
60 changed files with 609 additions and 141 deletions
+12 -11
View File
@@ -1,10 +1,10 @@
using Hyperbar.Windows.Controls;
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
using Hyperbar.Widget.Contextual;
using Hyperbar.Windows.Primary;
namespace Hyperbar.Windows;
@@ -28,29 +28,30 @@ public partial class App :
})
.ConfigureServices((context, services) =>
{
services.AddSingleton<IServiceFactory>(provider =>
new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)));
services.AddHostedService<AppService>();
services.AddTransient<IInitializer, AppInitializer>();
services.AddTransient<DesktopFlyout>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
services.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
services.AddTransient<DesktopFlyout>();
services.AddContentTemplate<CommandViewModel, CommandView>();
//services.AddCommand<ContextualCommandWidgetBuilder>("");
//services.AddWidget<PrimaryCommandWidgetBuilder>("");
services.AddWidget<ContextualWidgetBuilder>();
services.AddWidget<PrimaryWidgetBuilder>();
services.AddTransient(provider =>
{
static IEnumerable<IWidgetViewModel> Resolve(IServiceProvider services)
{
foreach (IWidgetContext commandContext in services.GetServices<IWidgetContext>())
foreach (IWidgetContext widgetContext in services.GetServices<IWidgetContext>())
{
if (commandContext.ServiceProvider.GetService<IWidgetViewModel>() is
IWidgetViewModel commandViewModel)
if (widgetContext.ServiceProvider.GetService<IWidgetViewModel>() is
IWidgetViewModel viewModel)
{
yield return commandViewModel;
yield return viewModel;
}
}
}
+8
View File
@@ -14,6 +14,9 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="Views\WidgetButtonView.xaml" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
@@ -38,6 +41,11 @@
<ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Widget.Primary.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="Views\WidgetButtonView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
@@ -1,7 +1,5 @@
using Hyperbar.Windows.Controls;
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
namespace Hyperbar.Windows;
@@ -1,14 +1,11 @@
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace Hyperbar.Windows
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddWidget<TCommandBuilder>(this IServiceCollection services,
string key)
public static IServiceCollection AddWidget<TCommandBuilder>(this IServiceCollection services)
where TCommandBuilder :
IWidgetBuilder, new()
{
@@ -16,6 +13,12 @@ namespace Hyperbar.Windows
IHost? host = new HostBuilder()
.ConfigureServices(isolatedServices =>
{
isolatedServices.AddSingleton<IServiceFactory>(provider =>
new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)));
isolatedServices.AddTransient<IWidgetView, WidgetView>();
isolatedServices.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
isolatedServices.AddTransient<ITemplateFactory, TemplateFactory>();
isolatedServices.AddTransient<ITemplateGeneratorFactory, TemplateGeneratorFactory>();
@@ -1,10 +1,6 @@
using Hyperbar.Templates;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Hyperbar.Windows;
@@ -1,5 +1,4 @@
using Hyperbar.Templates;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Windows;
+6 -9
View File
@@ -1,18 +1,15 @@
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using System.Collections.Generic;
namespace Hyperbar.Windows;
namespace Hyperbar.Windows;
public partial class CommandViewModel :
ObservableCollectionViewModel,
ObservableCollectionViewModel<IWidgetViewModel>,
ITemplatedViewModel
{
public CommandViewModel(ITemplateFactory templateFactory,
IEnumerable<IWidgetViewModel> commands)
public CommandViewModel(ITemplateFactory templateFactory,
IServiceFactory serviceFactory,
IEnumerable<IWidgetViewModel> widgets) : base(serviceFactory)
{
TemplateFactory = templateFactory;
AddRange(commands);
AddRange(widgets);
}
public ITemplateFactory TemplateFactory { get; }
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<UserControl
x:Class="Hyperbar.Windows.WidgetButtonView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<UserControl.Resources>
<SolidColorBrush x:Key="ButtonBackground" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrush" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPointerOver" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushPressed" Color="Transparent" />
<SolidColorBrush x:Key="ButtonBorderBrushDisabled" Color="Transparent" />
<x:Double x:Key="ButtonWidth">32</x:Double>
<x:Double x:Key="ButtonHeight">32</x:Double>
</UserControl.Resources>
<Button
Width="{StaticResource ButtonWidth}"
Height="{StaticResource ButtonHeight}"
Command="{Binding Click}"
Content="{Binding Icon}" />
</UserControl>
@@ -0,0 +1,9 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Windows;
public sealed partial class WidgetButtonView :
UserControl
{
public WidgetButtonView() => InitializeComponent();
}
+7 -1
View File
@@ -3,5 +3,11 @@
x:Class="Hyperbar.Windows.WidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid />
<ItemsControl ItemTemplateSelector="{Binding TemplateFactory}" ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Spacing="8" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</UserControl>