diff --git a/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj b/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj index 98ed9f5..2071b13 100644 --- a/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj +++ b/Hyperbar.UI.Windows/Hyperbar.UI.Windows.csproj @@ -7,11 +7,7 @@ true enable enable - true - - - diff --git a/Hyperbar.Widget.Contextual.Windows/Hyperbar.Widget.Contextual.csproj b/Hyperbar.Widget.Contextual.Windows/Hyperbar.Widget.Contextual.Windows.csproj similarity index 100% rename from Hyperbar.Widget.Contextual.Windows/Hyperbar.Widget.Contextual.csproj rename to Hyperbar.Widget.Contextual.Windows/Hyperbar.Widget.Contextual.Windows.csproj diff --git a/Hyperbar.Widget.Primary.Windows/Hyperbar.Widget.Primary.csproj b/Hyperbar.Widget.Primary.Windows/Hyperbar.Widget.Primary.Windows.csproj similarity index 100% rename from Hyperbar.Widget.Primary.Windows/Hyperbar.Widget.Primary.csproj rename to Hyperbar.Widget.Primary.Windows/Hyperbar.Widget.Primary.Windows.csproj diff --git a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj new file mode 100644 index 0000000..0a53ed6 --- /dev/null +++ b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj @@ -0,0 +1,17 @@ + + + net8.0-windows10.0.19041.0 + 10.0.17763.0 + win10-x86;win10-x64;win10-arm64 + true + enable + enable + + + + + + + + + \ No newline at end of file diff --git a/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs b/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs new file mode 100644 index 0000000..301253e --- /dev/null +++ b/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs @@ -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 }); + } +} \ No newline at end of file diff --git a/Hyperbar.Widget/IServiceCollectionExtensions.cs b/Hyperbar.Widget/IServiceCollectionExtensions.cs index 573b119..9e2df37 100644 --- a/Hyperbar.Widget/IServiceCollectionExtensions.cs +++ b/Hyperbar.Widget/IServiceCollectionExtensions.cs @@ -7,12 +7,12 @@ public static class IServiceCollectionExtensions { public static IServiceCollection AddWidget(this IServiceCollection services) { - services.AddTransient(); + services.AddTransient(); services.AddTransient, WidgetFactory>(); - services.AddHandler(); - services.AddHandler(); - services.AddHandler(); + services.AddHandler(); + services.AddHandler(); + services.AddHandler(); services.AddHandler(); return services; diff --git a/Hyperbar.Widget/IWidgetAssembly.cs b/Hyperbar.Widget/IWidgetAssembly.cs new file mode 100644 index 0000000..b7cf300 --- /dev/null +++ b/Hyperbar.Widget/IWidgetAssembly.cs @@ -0,0 +1,8 @@ +using System.Reflection; + +namespace Hyperbar.Widget; + +public interface IWidgetAssembly +{ + public Assembly Assembly { get; } +} diff --git a/Hyperbar.Widget/IWidgetResourceInitialization.cs b/Hyperbar.Widget/IWidgetResourceInitialization.cs deleted file mode 100644 index 79b78aa..0000000 --- a/Hyperbar.Widget/IWidgetResourceInitialization.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Hyperbar.Widget; - -public interface IWidgetResourceInitialization : - IInitializer -{ - -} diff --git a/Hyperbar.Widget/WidgetAssembly.cs b/Hyperbar.Widget/WidgetAssembly.cs index ac2138a..5b7eb7d 100644 --- a/Hyperbar.Widget/WidgetAssembly.cs +++ b/Hyperbar.Widget/WidgetAssembly.cs @@ -2,5 +2,4 @@ namespace Hyperbar.Widget; -public record WidgetAssembly(Assembly? Assembly = default) : - INotification; \ No newline at end of file +public record WidgetAssembly(Assembly Assembly) : IWidgetAssembly; diff --git a/Hyperbar.Widget/WidgetAssemblyHandler.cs b/Hyperbar.Widget/WidgetAssemblyHandler.cs deleted file mode 100644 index cf3d230..0000000 --- a/Hyperbar.Widget/WidgetAssemblyHandler.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Reflection; - -namespace Hyperbar.Widget; - -public class WidgetAssemblyHandler(IMediator mediator, - IFactory factory) : - INotificationHandler> -{ - public Task Handle(Created 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(widget), - cancellationToken); - } - } - - return Task.CompletedTask; - } -} diff --git a/Hyperbar.Widget/WidgetExtension.cs b/Hyperbar.Widget/WidgetExtension.cs new file mode 100644 index 0000000..1d62dad --- /dev/null +++ b/Hyperbar.Widget/WidgetExtension.cs @@ -0,0 +1,4 @@ +using System.Reflection; +namespace Hyperbar.Widget; + +public record WidgetExtension(IWidget Widget, IWidgetAssembly Assembly); \ No newline at end of file diff --git a/Hyperbar.Widget/WidgetEnumerator.cs b/Hyperbar.Widget/WidgetExtensionEnumerator.cs similarity index 69% rename from Hyperbar.Widget/WidgetEnumerator.cs rename to Hyperbar.Widget/WidgetExtensionEnumerator.cs index 2f7b2a5..7f5162c 100644 --- a/Hyperbar.Widget/WidgetEnumerator.cs +++ b/Hyperbar.Widget/WidgetExtensionEnumerator.cs @@ -4,12 +4,12 @@ using System.Runtime.Loader; namespace Hyperbar.Widget; -public class WidgetEnumerator(IFactory factory, +public class WidgetExtensionEnumerator(IFactory factory, IHostEnvironment hostEnvironment, IMediator mediator) : - INotificationHandler> + INotificationHandler> { - public Task Handle(Enumerate notification, + public Task Handle(Enumerate notification, CancellationToken cancellationToken) { string extensionsDirectory = Path.Combine(hostEnvironment.ContentRootPath, "Extensions"); @@ -25,12 +25,12 @@ public class WidgetEnumerator(IFactory 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(widget), - cancellationToken); + await mediator.PublishAsync(new Created(new WidgetExtension(widget, + new WidgetAssembly(assembly))), cancellationToken); } } }); diff --git a/Hyperbar.Widget/WidgetHandler.cs b/Hyperbar.Widget/WidgetExtensionHandler.cs similarity index 61% rename from Hyperbar.Widget/WidgetHandler.cs rename to Hyperbar.Widget/WidgetExtensionHandler.cs index 26c75fa..5a6eb1a 100644 --- a/Hyperbar.Widget/WidgetHandler.cs +++ b/Hyperbar.Widget/WidgetExtensionHandler.cs @@ -2,20 +2,21 @@ namespace Hyperbar.Widget; -public class WidgetHandler(IProxyServiceCollection typedServices, +public class WidgetExtensionHandler(IProxyServiceCollection typedServices, IServiceProvider provider, IMediator mediator) : - INotificationHandler> + INotificationHandler> { - public async Task Handle(Created notification, + public async Task Handle(Created 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>()); args.AddRange(typedServices.Services); }); diff --git a/Hyperbar.Widget/WidgetExtensionInitializer.cs b/Hyperbar.Widget/WidgetExtensionInitializer.cs new file mode 100644 index 0000000..87954d5 --- /dev/null +++ b/Hyperbar.Widget/WidgetExtensionInitializer.cs @@ -0,0 +1,8 @@ +namespace Hyperbar.Widget; + +public class WidgetExtensionInitializer(IMediator mediator) : + IInitializer +{ + public async Task InitializeAsync() => + await mediator.PublishAsync>(); +} \ No newline at end of file diff --git a/Hyperbar.Widget/WidgetManager.cs b/Hyperbar.Widget/WidgetManager.cs deleted file mode 100644 index 37d6029..0000000 --- a/Hyperbar.Widget/WidgetManager.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Hyperbar.Widget; - -public class WidgetInitializer(IMediator mediator) : - IInitializer -{ - public Task InitializeAsync() - { - mediator.PublishAsync>(); - return Task.CompletedTask; - } -} \ No newline at end of file diff --git a/Hyperbar.sln b/Hyperbar.sln index 99ac9a9..5a714a4 100644 --- a/Hyperbar.sln +++ b/Hyperbar.sln @@ -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