wired up key commands

This commit is contained in:
TheXamlGuy
2024-01-06 16:39:30 +00:00
parent a77c356389
commit 71881ad877
31 changed files with 282 additions and 82 deletions
+2 -2
View File
@@ -40,8 +40,8 @@ public partial class App :
services.AddTransient<DesktopFlyout>();
services.AddContentTemplate<CommandViewModel, CommandView>();
services.AddWidget<ContextualWidgetBuilder>();
services.AddWidget<PrimaryWidgetBuilder>();
services.AddWidgetProvider<ContextualWidgetProvider>();
services.AddWidgetProvider<PrimaryWidgetProvider>();
services.AddTransient(provider =>
{
@@ -0,0 +1,13 @@
using Hyperbar.Windows.Win32;
namespace Hyperbar.Windows;
public class KeyAcceleratorCommandHandler(IVirtualKeyboard virtualKeyboard) :
ICommandHandler<KeyAcceleratorCommand>
{
public ValueTask<Unit> Handle(KeyAcceleratorCommand command,
CancellationToken cancellationToken)
{ virtualKeyboard.Send((int)command.Key);
return default;
}
}
-1
View File
@@ -3,7 +3,6 @@
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Windows</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
@@ -1,4 +1,5 @@
using Hyperbar.Extensions;
using Hyperbar.Windows.Win32;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@@ -6,17 +7,21 @@ namespace Hyperbar.Windows
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddWidget<TCommandBuilder>(this IServiceCollection services)
where TCommandBuilder :
IWidgetBuilder, new()
public static IServiceCollection AddWidgetProvider<TWidgetProvider>(this IServiceCollection services)
where TWidgetProvider :
IWidgetProvider, new()
{
TCommandBuilder builder = new();
TWidgetProvider builder = new();
IHost? host = new HostBuilder()
.ConfigureServices(isolatedServices =>
{
isolatedServices.AddSingleton<IServiceFactory>(provider =>
new ServiceFactory((type, parameters) => ActivatorUtilities.CreateInstance(provider, type, parameters!)));
isolatedServices.AddSingleton<IVirtualKeyboard, VirtualKeyboard>();
isolatedServices.AddSingleton<IMediator, Mediator>();
isolatedServices.AddHandler<KeyAcceleratorCommandHandler>();
isolatedServices.AddTransient<IWidgetView, WidgetView>();
isolatedServices.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
@@ -1,11 +0,0 @@
namespace Hyperbar.Windows;
public class KeyAcceleratorCommandHandler :
ICommandHandler<KeyAcceleratorCommand>
{
public ValueTask<Unit> Handle(KeyAcceleratorCommand command,
CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}