diff --git a/Hyperbar.UI.Windows/TemplateGenerator.cs b/Hyperbar.UI.Windows/TemplateGenerator.cs index acd63c3..0a0b865 100644 --- a/Hyperbar.UI.Windows/TemplateGenerator.cs +++ b/Hyperbar.UI.Windows/TemplateGenerator.cs @@ -10,7 +10,7 @@ public class TemplateGenerator : DataTemplateSelector { string xamlString = @" + xmlns:ui='using:Hyperbar.UI.Windows'> "; @@ -21,7 +21,7 @@ public class TemplateGenerator : DataTemplateSelector { string xamlString = @" + xmlns:ui='using:Hyperbar.UI.Windows'> "; diff --git a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj index 0a53ed6..0692344 100644 --- a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj +++ b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj @@ -8,10 +8,43 @@ enable - - + + + + + - + + + + + + + + + + + + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + Designer + + + $(DefaultXamlRuntime) + Designer + \ No newline at end of file diff --git a/Hyperbar.Widget.Windows/IServiceCollectionExtensions.cs b/Hyperbar.Widget.Windows/IServiceCollectionExtensions.cs new file mode 100644 index 0000000..49716f1 --- /dev/null +++ b/Hyperbar.Widget.Windows/IServiceCollectionExtensions.cs @@ -0,0 +1,41 @@ +using Hyperbar.Interop.Windows; +using Hyperbar.UI.Windows; +using Microsoft.Extensions.DependencyInjection; + +namespace Hyperbar.Widget.Windows; + +public static class IServiceCollectionExtensions +{ + public static IServiceCollection AddWidgetWindows(this IServiceCollection services) + { + services.AddContentTemplate(); + + // We need to feed information to the Widgets about our Windows host, + // so the Windows host can make discussions how to display and interact with the widgets. + + services.AddTransient>(provider => + new ProxyServiceCollection(services => + { + services.AddSingleton(provider.GetRequiredService()); + services.AddTransient, + WidgetContainerFactory>(); + + services.AddTransient(); + + services.AddScoped(); + services.AddHandler(); + services.AddHandler(); + + services.AddHandler(); + + services.AddTransient(); + services.AddTransient(); + + services.AddContentTemplate(); + services.AddContentTemplate(); + services.AddContentTemplate(); + })); + + return services; + } +} \ No newline at end of file diff --git a/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs b/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs deleted file mode 100644 index 301253e..0000000 --- a/Hyperbar.Widget.Windows/IWidgetResourceInitialization.cs +++ /dev/null @@ -1,31 +0,0 @@ -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.Windows/Lifecycles/KeyAcceleratorHandler.cs b/Hyperbar.Widget.Windows/KeyAcceleratorHandler.cs similarity index 76% rename from Hyperbar.Windows/Lifecycles/KeyAcceleratorHandler.cs rename to Hyperbar.Widget.Windows/KeyAcceleratorHandler.cs index ca59f64..9421985 100644 --- a/Hyperbar.Windows/Lifecycles/KeyAcceleratorHandler.cs +++ b/Hyperbar.Widget.Windows/KeyAcceleratorHandler.cs @@ -1,8 +1,8 @@ using Hyperbar.Interop.Windows; -namespace Hyperbar.Windows; +namespace Hyperbar.Widget.Windows; -public class KeyAcceleratorHandler(IVirtualKeyboard virtualKeyboard) : +internal class KeyAcceleratorHandler(IVirtualKeyboard virtualKeyboard) : IHandler { public Task Handle(KeyAccelerator request, diff --git a/Hyperbar.Windows/Lifecycles/StartProcessHandler.cs b/Hyperbar.Widget.Windows/StartProcessHandler.cs similarity index 78% rename from Hyperbar.Windows/Lifecycles/StartProcessHandler.cs rename to Hyperbar.Widget.Windows/StartProcessHandler.cs index ab720ba..1df9bca 100644 --- a/Hyperbar.Windows/Lifecycles/StartProcessHandler.cs +++ b/Hyperbar.Widget.Windows/StartProcessHandler.cs @@ -1,8 +1,8 @@ using System.Diagnostics; -namespace Hyperbar.Windows; +namespace Hyperbar.Widget.Windows; -public class StartProcessHandler : +internal class StartProcessHandler : IHandler { public Task Handle(StartProcess request, diff --git a/Hyperbar.Windows/Views/WidgetBarView.xaml b/Hyperbar.Widget.Windows/WidgetBarView.xaml similarity index 93% rename from Hyperbar.Windows/Views/WidgetBarView.xaml rename to Hyperbar.Widget.Windows/WidgetBarView.xaml index 757766d..9b65476 100644 --- a/Hyperbar.Windows/Views/WidgetBarView.xaml +++ b/Hyperbar.Widget.Windows/WidgetBarView.xaml @@ -1,6 +1,6 @@ diff --git a/Hyperbar.Windows/Views/WidgetBarView.xaml.cs b/Hyperbar.Widget.Windows/WidgetBarView.xaml.cs similarity index 81% rename from Hyperbar.Windows/Views/WidgetBarView.xaml.cs rename to Hyperbar.Widget.Windows/WidgetBarView.xaml.cs index 8126f50..308718b 100644 --- a/Hyperbar.Windows/Views/WidgetBarView.xaml.cs +++ b/Hyperbar.Widget.Windows/WidgetBarView.xaml.cs @@ -1,6 +1,6 @@ using Microsoft.UI.Xaml.Controls; -namespace Hyperbar.Windows; +namespace Hyperbar.Widget.Windows; public sealed partial class WidgetBarView : UserControl diff --git a/Hyperbar.Windows/Views/WidgetButtonView.xaml b/Hyperbar.Widget.Windows/WidgetButtonView.xaml similarity index 95% rename from Hyperbar.Windows/Views/WidgetButtonView.xaml rename to Hyperbar.Widget.Windows/WidgetButtonView.xaml index f045a66..51a7207 100644 --- a/Hyperbar.Windows/Views/WidgetButtonView.xaml +++ b/Hyperbar.Widget.Windows/WidgetButtonView.xaml @@ -1,6 +1,6 @@ diff --git a/Hyperbar.Windows/Views/WidgetButtonView.xaml.cs b/Hyperbar.Widget.Windows/WidgetButtonView.xaml.cs similarity index 81% rename from Hyperbar.Windows/Views/WidgetButtonView.xaml.cs rename to Hyperbar.Widget.Windows/WidgetButtonView.xaml.cs index c4a005f..4104f55 100644 --- a/Hyperbar.Windows/Views/WidgetButtonView.xaml.cs +++ b/Hyperbar.Widget.Windows/WidgetButtonView.xaml.cs @@ -1,6 +1,6 @@ using Microsoft.UI.Xaml.Controls; -namespace Hyperbar.Windows; +namespace Hyperbar.Widget.Windows; public sealed partial class WidgetButtonView : UserControl diff --git a/Hyperbar.Windows/Views/WidgetContainerView.xaml b/Hyperbar.Widget.Windows/WidgetContainerView.xaml similarity index 95% rename from Hyperbar.Windows/Views/WidgetContainerView.xaml rename to Hyperbar.Widget.Windows/WidgetContainerView.xaml index a1a4049..a9202de 100644 --- a/Hyperbar.Windows/Views/WidgetContainerView.xaml +++ b/Hyperbar.Widget.Windows/WidgetContainerView.xaml @@ -1,6 +1,6 @@ diff --git a/Hyperbar.Windows/Views/WidgetSplitButtonView.xaml.cs b/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml.cs similarity index 82% rename from Hyperbar.Windows/Views/WidgetSplitButtonView.xaml.cs rename to Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml.cs index 9cf97fb..6a6137d 100644 --- a/Hyperbar.Windows/Views/WidgetSplitButtonView.xaml.cs +++ b/Hyperbar.Widget.Windows/WidgetSplitButtonView.xaml.cs @@ -1,6 +1,6 @@ using Microsoft.UI.Xaml.Controls; -namespace Hyperbar.Windows; +namespace Hyperbar.Widget.Windows; public sealed partial class WidgetSplitButtonView : UserControl diff --git a/Hyperbar.Windows/Views/WidgetView.xaml b/Hyperbar.Widget.Windows/WidgetView.xaml similarity index 96% rename from Hyperbar.Windows/Views/WidgetView.xaml rename to Hyperbar.Widget.Windows/WidgetView.xaml index 943ce13..a1874df 100644 --- a/Hyperbar.Windows/Views/WidgetView.xaml +++ b/Hyperbar.Widget.Windows/WidgetView.xaml @@ -1,6 +1,6 @@ typedServices, - IServiceProvider provider, - IMediator mediator) : + IServiceProvider provider) : INotificationHandler> { public async Task Handle(Created notification, @@ -18,14 +17,12 @@ public class WidgetExtensionHandler(IProxyServiceCollection type { args.AddSingleton(widgetExtension.Assembly); args.AddTransient(_ => provider.GetRequiredService>()); + args.AddRange(typedServices.Services); }); IWidgetHost host = builder.Build(); await host.InitializeAsync(); - - await mediator.PublishAsync(new Created(host), - cancellationToken); } } } diff --git a/Hyperbar.Widget/WidgetHost.cs b/Hyperbar.Widget/WidgetHost.cs index f5b30ec..810fad1 100644 --- a/Hyperbar.Widget/WidgetHost.cs +++ b/Hyperbar.Widget/WidgetHost.cs @@ -6,28 +6,26 @@ public class WidgetHost : INotificationHandler>, IWidgetHost { - private readonly IConfigurationInitializer configurationInitializer; - private readonly IServiceProvider services; private readonly IEnumerable initializers; private readonly IMediator mediator; private readonly IProxyService proxyMediator; + private readonly IServiceProvider services; public WidgetHost(IServiceProvider services, IMediator mediator, IEnumerable initializers, - IProxyService proxyMediator, - IConfigurationInitializer configurationInitializer) + IProxyService proxyMediator) { this.services = services; this.mediator = mediator; this.initializers = initializers; this.proxyMediator = proxyMediator; - this.configurationInitializer = configurationInitializer; mediator.Subscribe(this); } - public WidgetConfiguration Configuration => services.GetRequiredService(); + public WidgetConfiguration Configuration => + services.GetRequiredService(); public IServiceProvider Services => services; @@ -43,7 +41,13 @@ public class WidgetHost : } } - public async Task InitializeAsync() => await configurationInitializer.InitializeAsync(); + public async Task InitializeAsync() + { + foreach (IInitializer initializer in initializers) + { + await initializer.InitializeAsync(); + } + } private async Task StartAsync() { @@ -51,10 +55,5 @@ public class WidgetHost : { await mediator.PublishAsync(new Started(this)); } - - foreach (IInitializer initializer in initializers) - { - await initializer.InitializeAsync(); - } } } \ No newline at end of file diff --git a/Hyperbar.Windows/App.xaml.cs b/Hyperbar.Windows/App.xaml.cs index b8f5465..a5fa8d3 100644 --- a/Hyperbar.Windows/App.xaml.cs +++ b/Hyperbar.Windows/App.xaml.cs @@ -1,6 +1,5 @@ using CustomExtensions.WinUI; using Hyperbar.Controls.Windows; -using Hyperbar.Interop.Windows; using Hyperbar.UI.Windows; using Hyperbar.Widget; using Microsoft.Extensions.Configuration; @@ -9,6 +8,7 @@ using Microsoft.Extensions.Hosting; using Microsoft.UI.Dispatching; using Microsoft.UI.Xaml; using System.Reflection; +using Hyperbar.Widget.Windows; namespace Hyperbar.Windows; @@ -36,6 +36,8 @@ public partial class App : { services.AddDefault(); services.AddWidget(); + services.AddWidgetWindows(); + services.AddHostedService(); services.AddSingleton(new Dispatcher(DispatcherQueue.GetForCurrentThread())); @@ -50,30 +52,6 @@ public partial class App : services.AddTransient(); services.AddSingleton(); - services.AddContentTemplate(); - - services.AddTransient>(provider => - new ProxyServiceCollection(services => - { - services.AddSingleton(new Dispatcher(DispatcherQueue.GetForCurrentThread())); - - services.AddTransient, - WidgetContainerFactory>(); - - services.AddTransient(); - - services.AddScoped(); - services.AddHandler(); - services.AddHandler(); - - services.AddHandler(); - - services.AddTransient(); - - services.AddContentTemplate(); - services.AddContentTemplate(); - services.AddContentTemplate(); - })); }) .Build(); diff --git a/Hyperbar.Windows/Hyperbar.Windows.csproj b/Hyperbar.Windows/Hyperbar.Windows.csproj index 42a87db..ffc1135 100644 --- a/Hyperbar.Windows/Hyperbar.Windows.csproj +++ b/Hyperbar.Windows/Hyperbar.Windows.csproj @@ -13,11 +13,6 @@ enable true - - - - - @@ -49,6 +44,7 @@ + diff --git a/Hyperbar.Windows/Lifecycles/AppInitializer.cs b/Hyperbar.Windows/Lifecycles/AppInitializer.cs index adbd206..77ec1b8 100644 --- a/Hyperbar.Windows/Lifecycles/AppInitializer.cs +++ b/Hyperbar.Windows/Lifecycles/AppInitializer.cs @@ -1,5 +1,6 @@ using Hyperbar.Controls.Windows; using Hyperbar.Widget; +using Hyperbar.Widget.Windows; using Microsoft.Extensions.DependencyInjection; namespace Hyperbar.Windows;