diff --git a/Hyperbar.UI.Windows/NavigateAction.cs b/Hyperbar.UI.Windows/NavigateAction.cs
index 1d2f2dc..b56a83a 100644
--- a/Hyperbar.UI.Windows/NavigateAction.cs
+++ b/Hyperbar.UI.Windows/NavigateAction.cs
@@ -28,7 +28,8 @@ public sealed class NavigateAction :
set => SetValue(TargetNameProperty, value);
}
- public object Execute(object sender, object parameter)
+ public object Execute(object sender,
+ object parameter)
{
if (sender is FrameworkElement frameworkElement)
{
diff --git a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj
index 1760bb5..60a862b 100644
--- a/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj
+++ b/Hyperbar.Widget.Windows/Hyperbar.Widget.Windows.csproj
@@ -7,6 +7,11 @@
enable
enable
+
+
+
+
+
@@ -18,4 +23,18 @@
+
+
+ $(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
index 2d4a81d..5286d82 100644
--- a/Hyperbar.Widget.Windows/IServiceCollectionExtensions.cs
+++ b/Hyperbar.Widget.Windows/IServiceCollectionExtensions.cs
@@ -9,9 +9,6 @@ public static class IServiceCollectionExtensions
{
public static IServiceCollection AddWidgetWindows(this IServiceCollection services)
{
- // 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((Func>)(provider =>
new ProxyServiceCollection(services =>
{
@@ -25,6 +22,11 @@ public static class IServiceCollectionExtensions
services.AddHandler();
services.AddHandler();
+ services.AddTransient();
+
+ services.AddNavigationHandler();
+ services.AddNavigationHandler();
+
services.AddHandler();
services.AddTransient();
@@ -33,6 +35,9 @@ public static class IServiceCollectionExtensions
services.AddContentTemplate();
services.AddContentTemplate();
+
+ services.AddContentTemplate();
+ services.AddContentTemplate("WidgetSettings");
})));
return services;
diff --git a/Hyperbar.Windows/WidgetSettingsNavigationView.xaml b/Hyperbar.Widget.Windows/WidgetNavigationView.xaml
similarity index 91%
rename from Hyperbar.Windows/WidgetSettingsNavigationView.xaml
rename to Hyperbar.Widget.Windows/WidgetNavigationView.xaml
index 2f15878..ce69644 100644
--- a/Hyperbar.Windows/WidgetSettingsNavigationView.xaml
+++ b/Hyperbar.Widget.Windows/WidgetNavigationView.xaml
@@ -1,12 +1,13 @@
diff --git a/Hyperbar.Widget.Windows/WidgetNavigationView.xaml.cs b/Hyperbar.Widget.Windows/WidgetNavigationView.xaml.cs
new file mode 100644
index 0000000..1f61460
--- /dev/null
+++ b/Hyperbar.Widget.Windows/WidgetNavigationView.xaml.cs
@@ -0,0 +1,13 @@
+using Microsoft.UI.Xaml.Controls;
+
+namespace Hyperbar.Widget.Windows;
+
+public partial class WidgetNavigationView :
+ NavigationViewItem
+{
+ public WidgetNavigationView() =>
+ InitializeComponent();
+
+ protected WidgetNavigationViewModel ViewModel =>
+ (WidgetNavigationViewModel)DataContext;
+}
diff --git a/Hyperbar.Widget.Windows/WidgetNavigationViewModel.cs b/Hyperbar.Widget.Windows/WidgetNavigationViewModel.cs
new file mode 100644
index 0000000..d2b774e
--- /dev/null
+++ b/Hyperbar.Widget.Windows/WidgetNavigationViewModel.cs
@@ -0,0 +1,16 @@
+using Hyperbar.UI.Windows;
+
+namespace Hyperbar.Widget.Windows;
+
+[NotificationHandler(nameof(WidgetNavigationViewModel))]
+public class WidgetNavigationViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
+ IServiceProvider serviceProvider,
+ IServiceFactory serviceFactory,
+ IPublisher publisher,
+ ISubscriber subscriber,
+ IDisposer disposer,
+ string text) :
+ NavigationViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
+{
+ public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
+}
diff --git a/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml b/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml
new file mode 100644
index 0000000..105c47b
--- /dev/null
+++ b/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
diff --git a/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml.cs b/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml.cs
new file mode 100644
index 0000000..3afc1bd
--- /dev/null
+++ b/Hyperbar.Widget.Windows/WidgetSettingsNavigationView.xaml.cs
@@ -0,0 +1,10 @@
+using Microsoft.UI.Xaml.Controls;
+
+namespace Hyperbar.Widget.Windows;
+
+public sealed partial class WidgetSettingsNavigationView :
+ NavigationViewItem
+{
+ public WidgetSettingsNavigationView() =>
+ InitializeComponent();
+}
diff --git a/Hyperbar.Windows/WidgetNavigationViewModel.cs b/Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModel.cs
similarity index 63%
rename from Hyperbar.Windows/WidgetNavigationViewModel.cs
rename to Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModel.cs
index 141d3b8..b960ca8 100644
--- a/Hyperbar.Windows/WidgetNavigationViewModel.cs
+++ b/Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModel.cs
@@ -1,8 +1,6 @@
-using Hyperbar.UI.Windows;
+namespace Hyperbar.Widget.Windows;
-namespace Hyperbar.Windows;
-
-public class WidgetNavigationViewModel(IServiceProvider serviceProvider,
+public class WidgetSettingsNavigationViewModel(IServiceProvider serviceProvider,
IServiceFactory serviceFactory,
IPublisher publisher,
ISubscriber subscriber,
diff --git a/Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModelEnumerator.cs b/Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModelEnumerator.cs
new file mode 100644
index 0000000..8bd2d14
--- /dev/null
+++ b/Hyperbar.Widget.Windows/WidgetSettingsNavigationViewModelEnumerator.cs
@@ -0,0 +1,22 @@
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Hyperbar.Widget.Windows;
+
+public class WidgetSettingsNavigationViewModelEnumerator(IPublisher publisher,
+ IWidgetHostCollection widgetHosts) :
+ INotificationHandler>
+{
+ public async Task Handle(Enumerate args,
+ CancellationToken cancellationToken = default)
+ {
+ foreach (IWidgetHost host in widgetHosts)
+ {
+ if (host.Services.GetService() is IServiceFactory serviceFactory)
+ {
+ await publisher.PublishAsync(new Create(serviceFactory
+ .Create(host.Configuration.Name)),
+ nameof(WidgetNavigationViewModel), cancellationToken);
+ }
+ }
+ }
+}
diff --git a/Hyperbar.Windows/WidgetSettingsView.xaml b/Hyperbar.Widget.Windows/WidgetSettingsView.xaml
similarity index 81%
rename from Hyperbar.Windows/WidgetSettingsView.xaml
rename to Hyperbar.Widget.Windows/WidgetSettingsView.xaml
index b2b3936..1e55049 100644
--- a/Hyperbar.Windows/WidgetSettingsView.xaml
+++ b/Hyperbar.Widget.Windows/WidgetSettingsView.xaml
@@ -1,6 +1,6 @@
diff --git a/Hyperbar.Windows/WidgetSettingsView.xaml.cs b/Hyperbar.Widget.Windows/WidgetSettingsView.xaml.cs
similarity index 88%
rename from Hyperbar.Windows/WidgetSettingsView.xaml.cs
rename to Hyperbar.Widget.Windows/WidgetSettingsView.xaml.cs
index 2d84909..11ecda5 100644
--- a/Hyperbar.Windows/WidgetSettingsView.xaml.cs
+++ b/Hyperbar.Widget.Windows/WidgetSettingsView.xaml.cs
@@ -1,6 +1,6 @@
using Microsoft.UI.Xaml.Controls;
-namespace Hyperbar.Windows;
+namespace Hyperbar.Widget.Windows;
public partial class WidgetSettingsView : UserControl
{
diff --git a/Hyperbar.Windows/WidgetSettingsViewModel.cs b/Hyperbar.Widget.Windows/WidgetSettingsViewModel.cs
similarity index 87%
rename from Hyperbar.Windows/WidgetSettingsViewModel.cs
rename to Hyperbar.Widget.Windows/WidgetSettingsViewModel.cs
index 27831ed..8ad3f88 100644
--- a/Hyperbar.Windows/WidgetSettingsViewModel.cs
+++ b/Hyperbar.Widget.Windows/WidgetSettingsViewModel.cs
@@ -1,6 +1,6 @@
using Hyperbar.UI.Windows;
-namespace Hyperbar.Windows;
+namespace Hyperbar.Widget.Windows;
public class WidgetSettingsViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
IServiceProvider serviceProvider,
@@ -10,5 +10,5 @@ public class WidgetSettingsViewModel(IViewModelTemplateSelector viewModelTemplat
IDisposer disposer) :
ObservableCollectionViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer)
{
- public IViewModelTemplateSelector ViewModelTemplateSelector { get; } = viewModelTemplateSelector;
+ public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
}
\ No newline at end of file
diff --git a/Hyperbar.Widget/WidgetBuilder.cs b/Hyperbar.Widget/WidgetBuilder.cs
index c006c72..60eda81 100644
--- a/Hyperbar.Widget/WidgetBuilder.cs
+++ b/Hyperbar.Widget/WidgetBuilder.cs
@@ -1,4 +1,5 @@
-using Microsoft.Extensions.Configuration;
+using Hyperbar.UI.Windows;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Reflection;
@@ -31,13 +32,14 @@ public class WidgetBuilder :
new ServiceFactory((type, parameters) =>
ActivatorUtilities.CreateInstance(provider, type, parameters!)));
- services.AddScoped();
- services.AddScoped();
+ services.AddSingleton();
+ services.AddSingleton();
+
services.AddTransient();
services.AddTransient();
- services.AddScoped();
- services.AddScoped();
+ services.AddTransient();
+ services.AddSingleton();
services.AddHandler();
services.AddValueChangedNotification();
+ services.AddSingleton();
+ services.AddTransient();
+
+ services.AddHandler();
});
}
diff --git a/Hyperbar.Widget/WidgetExtensionHandler.cs b/Hyperbar.Widget/WidgetExtensionHandler.cs
index a06be42..41d7f8c 100644
--- a/Hyperbar.Widget/WidgetExtensionHandler.cs
+++ b/Hyperbar.Widget/WidgetExtensionHandler.cs
@@ -17,6 +17,7 @@ public class WidgetExtensionHandler(IServiceProvider provider,
{
args.AddSingleton(widgetExtension.Assembly);
args.AddTransient(_ => provider.GetRequiredService>());
+ args.AddTransient(_ => provider.GetRequiredService>());
args.AddRange(typedServices.Services);
});
diff --git a/Hyperbar.Windows/App.xaml.cs b/Hyperbar.Windows/App.xaml.cs
index b8f32c9..de43f5e 100644
--- a/Hyperbar.Windows/App.xaml.cs
+++ b/Hyperbar.Windows/App.xaml.cs
@@ -38,9 +38,8 @@ public partial class App :
services.AddSingleton((IDispatcher)new Dispatcher(DispatcherQueue.GetForCurrentThread()));
- services.AddTransient();
- services.AddSingleton();
- services.AddTransient();
+ services.AddNavigationHandler();
+ services.AddNavigationHandler();
services.AddTransient();
@@ -53,9 +52,6 @@ public partial class App :
args.Placement = DesktopApplicationBarPlacemenet.Top;
});
- services.AddNavigationHandler();
- services.AddNavigationHandler();
-
services.AddSingleton();
services.AddContentTemplate();
services.AddContentTemplate();
@@ -65,12 +61,9 @@ public partial class App :
services.AddContentTemplate("Settings");
services.AddContentTemplate();
- services.AddContentTemplate();
services.AddContentTemplate();
- services.AddContentTemplate("WidgetSettings");
-
- services.AddHandler();
+ services.AddHandler();
services.AddTransient();
})
.Build();
diff --git a/Hyperbar.Windows/Hyperbar.Windows.csproj b/Hyperbar.Windows/Hyperbar.Windows.csproj
index e51a161..c43ebcc 100644
--- a/Hyperbar.Windows/Hyperbar.Windows.csproj
+++ b/Hyperbar.Windows/Hyperbar.Windows.csproj
@@ -20,9 +20,6 @@
-
-
-
@@ -59,26 +56,11 @@
-
-
- MSBuild:Compile
-
-
-
-
- MSBuild:Compile
-
-
MSBuild:Compile
-
-
- MSBuild:Compile
-
-
MSBuild:Compile
diff --git a/Hyperbar.Windows/SettingsView.xaml b/Hyperbar.Windows/SettingsView.xaml
index 32b3afb..7ff7ec5 100644
--- a/Hyperbar.Windows/SettingsView.xaml
+++ b/Hyperbar.Windows/SettingsView.xaml
@@ -2,9 +2,7 @@
+ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
diff --git a/Hyperbar.Windows/SettingsViewModel.cs b/Hyperbar.Windows/SettingsViewModel.cs
index 3d32c21..af2348e 100644
--- a/Hyperbar.Windows/SettingsViewModel.cs
+++ b/Hyperbar.Windows/SettingsViewModel.cs
@@ -1,4 +1,5 @@
using Hyperbar.UI.Windows;
+using Hyperbar.Widget.Windows;
namespace Hyperbar.Windows;
@@ -15,7 +16,7 @@ public partial class SettingsViewModel :
ViewModelTemplateSelector = viewModelTemplateSelector;
Add("General");
- Add("Widgets");
+ Add("Widgets");
}
public IViewModelTemplateSelector ViewModelTemplateSelector { get; }
diff --git a/Hyperbar.Windows/WidgetNavigationView.xaml b/Hyperbar.Windows/WidgetNavigationView.xaml
deleted file mode 100644
index 284720a..0000000
--- a/Hyperbar.Windows/WidgetNavigationView.xaml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
diff --git a/Hyperbar.Windows/WidgetNavigationView.xaml.cs b/Hyperbar.Windows/WidgetNavigationView.xaml.cs
deleted file mode 100644
index da1c735..0000000
--- a/Hyperbar.Windows/WidgetNavigationView.xaml.cs
+++ /dev/null
@@ -1,11 +0,0 @@
-using Microsoft.UI.Xaml.Controls;
-
-
-namespace Hyperbar.Windows;
-
-public sealed partial class WidgetNavigationView :
- NavigationViewItem
-{
- public WidgetNavigationView() =>
- InitializeComponent();
-}
diff --git a/Hyperbar.Windows/WidgetNavigationViewModelEnumerator.cs b/Hyperbar.Windows/WidgetNavigationViewModelEnumerator.cs
deleted file mode 100644
index caf83c1..0000000
--- a/Hyperbar.Windows/WidgetNavigationViewModelEnumerator.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System.Security.Policy;
-
-namespace Hyperbar.Windows;
-
-public class WidgetNavigationViewModelEnumerator(IServiceFactory serviceFactory,
- IPublisher publisher) :
- INotificationHandler>
-{
- public async Task Handle(Enumerate args,
- CancellationToken cancellationToken = default)
- {
- await publisher.PublishAsync(new Create(serviceFactory
- .Create("fo")), nameof(WidgetSettingsNavigationViewModel), cancellationToken);
- }
-}
diff --git a/Hyperbar.Windows/WidgetSettingsNavigationView.xaml.cs b/Hyperbar.Windows/WidgetSettingsNavigationView.xaml.cs
deleted file mode 100644
index fcda239..0000000
--- a/Hyperbar.Windows/WidgetSettingsNavigationView.xaml.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-using Microsoft.UI.Xaml.Controls;
-
-namespace Hyperbar.Windows;
-
-public partial class WidgetSettingsNavigationView :
- NavigationViewItem
-{
- public WidgetSettingsNavigationView() =>
- InitializeComponent();
-
- protected WidgetSettingsNavigationViewModel ViewModel =>
- (WidgetSettingsNavigationViewModel)DataContext;
-}
diff --git a/Hyperbar.Windows/WidgetSettingsNavigationViewModel.cs b/Hyperbar.Windows/WidgetSettingsNavigationViewModel.cs
deleted file mode 100644
index fb48f77..0000000
--- a/Hyperbar.Windows/WidgetSettingsNavigationViewModel.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using Hyperbar.UI.Windows;
-
-namespace Hyperbar.Windows;
-
-[NotificationHandler(nameof(WidgetSettingsNavigationViewModel))]
-public class WidgetSettingsNavigationViewModel(IViewModelTemplateSelector viewModelTemplateSelector,
- IServiceProvider serviceProvider,
- IServiceFactory serviceFactory,
- IPublisher publisher,
- ISubscriber subscriber,
- IDisposer disposer,
- string text) :
- NavigationViewModel(serviceProvider, serviceFactory, publisher, subscriber, disposer, text)
-{
- public IViewModelTemplateSelector ViewModelTemplateSelector => viewModelTemplateSelector;
-}
diff --git a/Hyperbar/INavigationTargetProvider.cs b/Hyperbar/INavigationTargetProvider.cs
index c63d5b7..56004e1 100644
--- a/Hyperbar/INavigationTargetProvider.cs
+++ b/Hyperbar/INavigationTargetProvider.cs
@@ -3,4 +3,7 @@
public interface INavigationTargetProvider
{
object? Get(string name);
+
+ bool TryGet(string name,
+ out object? value);
}
\ No newline at end of file
diff --git a/Hyperbar/IServiceCollectionExtensions.cs b/Hyperbar/IServiceCollectionExtensions.cs
index aa524c9..512016f 100644
--- a/Hyperbar/IServiceCollectionExtensions.cs
+++ b/Hyperbar/IServiceCollectionExtensions.cs
@@ -1,4 +1,5 @@
-using Microsoft.Extensions.DependencyInjection;
+using Hyperbar.UI.Windows;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.FileProviders.Physical;
@@ -187,8 +188,14 @@ public static class IServiceCollectionExtensions
services.AddSingleton>(provider =>
new ProxyService(provider.GetRequiredService()));
+ services.AddSingleton>(provider =>
+ new ProxyService(provider.GetRequiredService()));
+
services.AddSingleton();
+ services.AddTransient();
+ services.AddSingleton();
+ services.AddTransient();
services.AddHandler();
return services;
diff --git a/Hyperbar/NavigateHandler.cs b/Hyperbar/NavigateHandler.cs
index a2e0987..c9227e1 100644
--- a/Hyperbar/NavigateHandler.cs
+++ b/Hyperbar/NavigateHandler.cs
@@ -6,7 +6,8 @@ public class NavigateHandler(IServiceProvider provider,
IPublisher publisher,
INavigationProvider navigationProvider,
IViewModelTemplateProvider viewModelTemplateProvider,
- INavigationTargetProvider navigationTargetProvider) :
+ INavigationTargetProvider navigationTargetProvider,
+ IProxyService proxyNavigationTargetProvider) :
INotificationHandler
{
public async Task Handle(Navigate args,
@@ -20,10 +21,15 @@ public class NavigateHandler(IServiceProvider provider,
provider.GetRequiredKeyedService(viewModelTemplate.ViewModelType,
viewModelTemplate.Key) is object viewModel)
{
- if ((args.TargetName is not null ?
- navigationTargetProvider.Get(args.TargetName) : view) is object target)
+ object? target = args.TargetName is not null
+ ? navigationTargetProvider.TryGet(args.TargetName, out target) || proxyNavigationTargetProvider.Proxy.TryGet(args.TargetName, out target)
+ ? target
+ : null
+ : view;
+
+ if (target is not null)
{
- if (navigationProvider.Get(target.GetType())
+ if (navigationProvider.Get(target.GetType())
is INavigation navigation)
{
Type navigateType = typeof(Navigate<>).MakeGenericType(navigation.Type);
diff --git a/Hyperbar/NavigationTargetProvider.cs b/Hyperbar/NavigationTargetProvider.cs
index e3282ca..a7c7405 100644
--- a/Hyperbar/NavigationTargetProvider.cs
+++ b/Hyperbar/NavigationTargetProvider.cs
@@ -7,4 +7,20 @@ public class NavigationTargetProvider(NavigationTargetCollection navigationTarge
{
public object? Get(string name) =>
navigationTargets.TryGetValue(name, out object? target) ? target : default;
+
+ public bool TryGet(string name,
+ out object? value)
+ {
+ if (navigationTargets.TryGetValue(name,
+ out object? target))
+ {
+ value = target;
+ return true;
+ }
+ else
+ {
+ value = null;
+ return false;
+ }
+ }
}
diff --git a/Hyperbar/Publisher.cs b/Hyperbar/Publisher.cs
index 3820401..25f9dba 100644
--- a/Hyperbar/Publisher.cs
+++ b/Hyperbar/Publisher.cs
@@ -12,16 +12,18 @@ public class Publisher(ISubscriptionManager subscriptionManager,
CancellationToken cancellationToken = default)
where TNotification :
INotification,
- new() => PublishAsync(new TNotification(), args => dispatcher.InvokeAsync(async () => await args()),
- key, cancellationToken);
+ new() => PublishAsync(new TNotification(), args =>
+ dispatcher.InvokeAsync(async () => await args()),
+ key, cancellationToken);
public Task PublishAsync(TNotification notification,
CancellationToken cancellationToken = default)
where TNotification :
INotification
{
- return PublishAsync(notification, args => dispatcher.InvokeAsync(async () => await args()),
- null, cancellationToken);
+ return PublishAsync(notification, args =>
+ dispatcher.InvokeAsync(async () => await args()),
+ null, cancellationToken);
}
public Task PublishAsync(TNotification notification,
@@ -30,8 +32,9 @@ public class Publisher(ISubscriptionManager subscriptionManager,
where TNotification :
INotification
{
- return PublishAsync(notification, args => dispatcher.InvokeAsync(async () => await args()),
- key, cancellationToken);
+ return PublishAsync(notification, args =>
+ dispatcher.InvokeAsync(async () => await args()),
+ key, cancellationToken);
}
public Task PublishAsync(object notification,
@@ -43,7 +46,8 @@ public class Publisher(ISubscriptionManager subscriptionManager,
List