inject the widget assembly into the IoC as we are going to need it further in
This commit is contained in:
@@ -7,11 +7,7 @@
|
||||
<UseRidGraph>true</UseRidGraph>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<EnableMsixTooling>true</EnableMsixTooling>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<None Remove="bin/Debug/net8.0-windows10.0.19041.0/Hyperbar.Windows.UI.pri" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
|
||||
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
|
||||
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
|
||||
<UseRidGraph>true</UseRidGraph>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
|
||||
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26031-preview" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,31 @@
|
||||
using Windows.ApplicationModel.Resources.Core;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetResourceInitialization :
|
||||
IInitializer
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class WidgetResourceInitialization :
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
//FileInfo resourcePriFileInfo = new(Path.Combine(ForeignAssemblyDir, "resources.pri"));
|
||||
//if (!resourcePriFileInfo.Exists)
|
||||
//{
|
||||
// resourcePriFileInfo = new(Path.Combine(ForeignAssemblyDir, $"{ForeignAssemblyName}.pri"));
|
||||
//}
|
||||
|
||||
//if (!resourcePriFileInfo.Exists)
|
||||
//{
|
||||
// return;
|
||||
//}
|
||||
|
||||
//StorageFile file = await StorageFile.GetFileFromPathAsync(resourcePriFileInfo.FullName);
|
||||
//ResourceManager.Current.LoadPriFiles(new[] { file });
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ public static class IServiceCollectionExtensions
|
||||
{
|
||||
public static IServiceCollection AddWidget(this IServiceCollection services)
|
||||
{
|
||||
services.AddTransient<IInitializer, WidgetInitializer>();
|
||||
services.AddTransient<IInitializer, WidgetExtensionInitializer>();
|
||||
services.AddTransient<IFactory<Type, IWidget>, WidgetFactory>();
|
||||
|
||||
services.AddHandler<WidgetEnumerator>();
|
||||
services.AddHandler<WidgetAssemblyHandler>();
|
||||
services.AddHandler<WidgetHandler>();
|
||||
services.AddHandler<WidgetExtensionEnumerator>();
|
||||
services.AddHandler<WidgetExtensionHandler>();
|
||||
services.AddHandler<WidgetExtensionHandler>();
|
||||
services.AddHandler<WidgetHostHandler>();
|
||||
|
||||
return services;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetAssembly
|
||||
{
|
||||
public Assembly Assembly { get; }
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public interface IWidgetResourceInitialization :
|
||||
IInitializer
|
||||
{
|
||||
|
||||
}
|
||||
@@ -2,5 +2,4 @@
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record WidgetAssembly(Assembly? Assembly = default) :
|
||||
INotification;
|
||||
public record WidgetAssembly(Assembly Assembly) : IWidgetAssembly;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using System.Reflection;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetAssemblyHandler(IMediator mediator,
|
||||
IFactory<Type, IWidget> factory) :
|
||||
INotificationHandler<Created<Assembly>>
|
||||
{
|
||||
public Task Handle(Created<Assembly> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (notification.Value?.GetTypes().FirstOrDefault(x => typeof(IWidget).IsAssignableFrom(x)) is Type widgetType)
|
||||
{
|
||||
if (factory.Create(widgetType) is IWidget widget)
|
||||
{
|
||||
mediator.PublishAsync(new Created<IWidget>(widget),
|
||||
cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
using System.Reflection;
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public record WidgetExtension(IWidget Widget, IWidgetAssembly Assembly);
|
||||
@@ -4,12 +4,12 @@ using System.Runtime.Loader;
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetEnumerator(IFactory<Type, IWidget> factory,
|
||||
public class WidgetExtensionEnumerator(IFactory<Type, IWidget> factory,
|
||||
IHostEnvironment hostEnvironment,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Enumerate<IWidget>>
|
||||
INotificationHandler<Enumerate<WidgetExtension>>
|
||||
{
|
||||
public Task Handle(Enumerate<IWidget> notification,
|
||||
public Task Handle(Enumerate<WidgetExtension> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
string extensionsDirectory = Path.Combine(hostEnvironment.ContentRootPath, "Extensions");
|
||||
@@ -25,12 +25,12 @@ public class WidgetEnumerator(IFactory<Type, IWidget> factory,
|
||||
Parallel.ForEach(assemblyPaths, async (string assemblyPath) =>
|
||||
{
|
||||
Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(assemblyPath);
|
||||
if (assembly.GetTypes().FirstOrDefault(x => typeof(IWidget).IsAssignableFrom(x)) is Type widgetType)
|
||||
foreach (Type widgetType in assembly.GetTypes().Where(x => typeof(IWidget).IsAssignableFrom(x)))
|
||||
{
|
||||
if (factory.Create(widgetType) is IWidget widget)
|
||||
{
|
||||
await mediator.PublishAsync(new Created<IWidget>(widget),
|
||||
cancellationToken);
|
||||
await mediator.PublishAsync(new Created<WidgetExtension>(new WidgetExtension(widget,
|
||||
new WidgetAssembly(assembly))), cancellationToken);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -2,20 +2,21 @@
|
||||
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetHandler(IProxyServiceCollection<IWidgetBuilder> typedServices,
|
||||
public class WidgetExtensionHandler(IProxyServiceCollection<IWidgetBuilder> typedServices,
|
||||
IServiceProvider provider,
|
||||
IMediator mediator) :
|
||||
INotificationHandler<Created<IWidget>>
|
||||
INotificationHandler<Created<WidgetExtension>>
|
||||
{
|
||||
public async Task Handle(Created<IWidget> notification,
|
||||
public async Task Handle(Created<WidgetExtension> notification,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if(notification.Value is IWidget widget)
|
||||
if(notification.Value is WidgetExtension widgetExtension)
|
||||
{
|
||||
IWidgetBuilder builder = widget.Create();
|
||||
IWidgetBuilder builder = widgetExtension.Widget.Create();
|
||||
|
||||
builder.ConfigureServices(args =>
|
||||
{
|
||||
args.AddSingleton(widgetExtension.Assembly);
|
||||
args.AddTransient(_ => provider.GetRequiredService<IProxyService<IMediator>>());
|
||||
args.AddRange(typedServices.Services);
|
||||
});
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetExtensionInitializer(IMediator mediator) :
|
||||
IInitializer
|
||||
{
|
||||
public async Task InitializeAsync() =>
|
||||
await mediator.PublishAsync<Enumerate<WidgetExtension>>();
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
namespace Hyperbar.Widget;
|
||||
|
||||
public class WidgetInitializer(IMediator mediator) :
|
||||
IInitializer
|
||||
{
|
||||
public Task InitializeAsync()
|
||||
{
|
||||
mediator.PublishAsync<Enumerate<IWidget>>();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
+20
-2
@@ -15,12 +15,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Interop.Windows",
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.UI.Windows", "Hyperbar.UI.Windows\Hyperbar.UI.Windows.csproj", "{97077400-7513-451E-83CB-C876D6C4E40E}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Contextual", "Hyperbar.Widget.Contextual.Windows\Hyperbar.Widget.Contextual.csproj", "{FF57BDC8-6E6D-478A-8312-D946D7ED4BAB}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Contextual.Windows", "Hyperbar.Widget.Contextual.Windows\Hyperbar.Widget.Contextual.Windows.csproj", "{FF57BDC8-6E6D-478A-8312-D946D7ED4BAB}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Primary", "Hyperbar.Widget.Primary.Windows\Hyperbar.Widget.Primary.csproj", "{4F2A7DDC-C841-45B8-A324-8A9BD949FBDF}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.Primary.Windows", "Hyperbar.Widget.Primary.Windows\Hyperbar.Widget.Primary.Windows.csproj", "{4F2A7DDC-C841-45B8-A324-8A9BD949FBDF}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Widget.MediaController.Windows", "Hyperbar.Widget.MediaController.Windows\Hyperbar.Widget.MediaController.Windows.csproj", "{ACBB1C58-1DB6-40E1-ABF1-71F2D2F0EC73}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hyperbar.Widget.Windows", "Hyperbar.Widget.Windows\Hyperbar.Widget.Windows.csproj", "{E7322176-B67F-4A22-AFDB-7430A6AD44B6}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -185,6 +187,22 @@ Global
|
||||
{ACBB1C58-1DB6-40E1-ABF1-71F2D2F0EC73}.Release|x64.Build.0 = Release|Any CPU
|
||||
{ACBB1C58-1DB6-40E1-ABF1-71F2D2F0EC73}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{ACBB1C58-1DB6-40E1-ABF1-71F2D2F0EC73}.Release|x86.Build.0 = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|ARM64.ActiveCfg = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|ARM64.Build.0 = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|ARM64.ActiveCfg = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|ARM64.Build.0 = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x64.Build.0 = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{E7322176-B67F-4A22-AFDB-7430A6AD44B6}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
Reference in New Issue
Block a user