Rename projects to better structure it. The aim is to try and keep it not dependant on the type of UI framework it uses thus allowing us to switch to another UI framework if we need later...

This commit is contained in:
TheXamlGuy
2024-01-06 08:49:12 +00:00
parent b380f06fbf
commit 3e88950669
67 changed files with 211 additions and 196 deletions
@@ -1,13 +0,0 @@
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Desktop.Contextual;
public class ContextualCommandBuilder :
ICommandBuilder
{
public void Create(IServiceCollection services)
{
services.AddCommandTemplate<ContextualCommandViewModel, ContextualCommandView>();
}
}
@@ -1,35 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Desktop.Controls</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Desktop.Win32\Hyperbar.Desktop.Win32.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="CommandFlyout\CommandFlyoutPresenter.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
<None Update="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
</None>
</ItemGroup>
<ItemGroup>
<Page Update="CommandFlyout\CommandFlyoutPresenter.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Themes\Generic.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
</Project>
@@ -1,14 +0,0 @@
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Desktop.Primary;
public class PrimaryCommandBuilder :
ICommandBuilder
{
public void Create(IServiceCollection services)
{
services.AddCommandTemplate<PrimaryCommandViewModel, PrimaryCommandView>();
}
}
@@ -1,8 +0,0 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Desktop.Primary;
public sealed partial class PrimaryCommandView : Page
{
public PrimaryCommandView() => InitializeComponent();
}
@@ -1,17 +0,0 @@
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
namespace Hyperbar.Desktop.Primary;
public class PrimaryCommandConfiguration
{
}
public class PrimaryCommandViewModel(ITemplateFactory templateFactory) :
ICommandViewModel,
ITemplatedViewModel
{
public ITemplateFactory TemplateFactory { get; } = templateFactory;
}
@@ -0,0 +1,15 @@
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Windows.Contextual;
public class ContextualCommandWidgetBuilder :
ICommandWidgetBuilder
{
public void Create(IServiceCollection services)
{
services
.AddWritableConfiguration<ContextualCommandWidgetConfiguration>()
.AddCommandTemplate<ContextualCommandWidgetViewModel, ContextualCommandWidgetView>();
}
}
@@ -0,0 +1,5 @@
namespace Hyperbar.Windows.Contextual;
public class ContextualCommandWidgetConfiguration
{
}
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Page <Page
x:Class="Hyperbar.Desktop.Contextual.ContextualCommandView" x:Class="Hyperbar.Windows.Contextual.ContextualCommandWidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid> <Grid>
<Button Content="This is a test" Click="Button_Click"/> <Button Click="Button_Click" Content="This is a test" />
</Grid> </Grid>
</Page> </Page>
@@ -1,12 +1,12 @@
using Hyperbar.Desktop.Win32; using Hyperbar.Windows.Win32;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Windows.System; using Windows.System;
namespace Hyperbar.Desktop.Contextual; namespace Hyperbar.Windows.Contextual;
public sealed partial class ContextualCommandView : Page public sealed partial class ContextualCommandWidgetView : Page
{ {
public ContextualCommandView() => InitializeComponent(); public ContextualCommandWidgetView() => InitializeComponent();
private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e) private void Button_Click(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{ {
@@ -1,10 +1,10 @@
using Hyperbar.Lifecycles; using Hyperbar.Lifecycles;
using Hyperbar.Templates; using Hyperbar.Templates;
namespace Hyperbar.Desktop.Contextual; namespace Hyperbar.Windows.Contextual;
public class ContextualCommandViewModel(ITemplateFactory templateFactory) : public class ContextualCommandWidgetViewModel(ITemplateFactory templateFactory) :
ICommandViewModel, ICommandWidgetViewModel,
ITemplatedViewModel ITemplatedViewModel
{ {
public ITemplateFactory TemplateFactory { get; } = templateFactory; public ITemplateFactory TemplateFactory { get; } = templateFactory;
@@ -2,10 +2,12 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Desktop.Contextual</RootNamespace> <RootNamespace>Hyperbar.Windows.Contextual</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers> <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI> <UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph> <UseRidGraph>true</UseRidGraph>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
@@ -13,7 +15,7 @@
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" /> <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Hyperbar.Desktop.Win32\Hyperbar.Desktop.Win32.csproj" /> <ProjectReference Include="..\Hyperbar.Windows.Win32\Hyperbar.Windows.Win32.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" /> <ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -1,6 +1,6 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
namespace Hyperbar.Desktop.Controls; namespace Hyperbar.Windows.Controls;
public class DesktopFlyout : public class DesktopFlyout :
DependencyObject DependencyObject
@@ -1,17 +1,15 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Hyperbar.Desktop.Win32; using Hyperbar.Windows.Win32;
using Microsoft.UI.Xaml.Controls.Primitives; using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Windows.Foundation;
using Microsoft.UI.Xaml.Media;
namespace Hyperbar.Desktop.Controls; namespace Hyperbar.Windows.Controls;
internal class DesktopFlyoutHost : Window internal class DesktopFlyoutHost : Window
{ {
private readonly DesktopFlyoutPresenter presenter; private readonly DesktopFlyoutPresenter presenter;
private DesktopFlyoutPlacement placement; private DesktopFlyoutPlacement placement;
private Popup popup; private Popup? popup;
public DesktopFlyoutHost(DesktopFlyoutPresenter presenter) public DesktopFlyoutHost(DesktopFlyoutPresenter presenter)
{ {
@@ -1,4 +1,4 @@
namespace Hyperbar.Desktop.Controls; namespace Hyperbar.Windows.Controls;
public enum DesktopFlyoutPlacement public enum DesktopFlyoutPlacement
{ {
@@ -2,7 +2,7 @@
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Data; using Microsoft.UI.Xaml.Data;
namespace Hyperbar.Desktop.Controls; namespace Hyperbar.Windows.Controls;
public class DesktopFlyoutPresenter : public class DesktopFlyoutPresenter :
ContentControl ContentControl
@@ -2,7 +2,7 @@
<ResourceDictionary <ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Hyperbar.Desktop.Controls"> xmlns:controls="using:Hyperbar.Windows.Controls">
<ResourceDictionary.ThemeDictionaries> <ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default"> <ResourceDictionary x:Key="Default">
<StaticResource x:Key="CommandBarFlyoutBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" /> <StaticResource x:Key="CommandBarFlyoutBackground" ResourceKey="AcrylicInAppFillColorDefaultBrush" />
@@ -1,6 +1,6 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
namespace Hyperbar.Desktop.Controls; namespace Hyperbar.Windows.Controls;
public class DesktopFlyoutPresenterTemplateSettings : DependencyObject public class DesktopFlyoutPresenterTemplateSettings : DependencyObject
{ {
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Windows.Controls</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<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.25936-preview" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Win32\Hyperbar.Windows.Win32.csproj" />
</ItemGroup>
</Project>
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="ms-appx:///Hyperbar.Desktop.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml" /> <ResourceDictionary Source="ms-appx:///Hyperbar.Windows.Controls/DesktopFlyout/DesktopFlyoutPresenter.xaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>
@@ -2,10 +2,12 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Desktop.Primary</RootNamespace> <RootNamespace>Hyperbar.Windows.Primary</RootNamespace>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers> <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI> <UseWinUI>true</UseWinUI>
<UseRidGraph>true</UseRidGraph> <UseRidGraph>true</UseRidGraph>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<IsAotCompatible>True</IsAotCompatible> <IsAotCompatible>True</IsAotCompatible>
@@ -0,0 +1,7 @@
namespace Hyperbar.Windows.Primary;
public interface IPrimaryCommand
{
}
@@ -0,0 +1,12 @@
namespace Hyperbar.Windows.Primary;
public class KeyAcceleratorCommand :
IPrimaryCommand
{
public string? Icon { get; set; }
public string? Key { get; set; }
public string[]? Modifiers { get; set; }
}
@@ -0,0 +1,7 @@
namespace Hyperbar.Windows.Primary;
public class PrimaryCommandConfiguration : List<IPrimaryCommand>
{
}
@@ -0,0 +1,15 @@
using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection;
namespace Hyperbar.Windows.Primary;
public class PrimaryCommandWidgetBuilder :
ICommandWidgetBuilder
{
public void Create(IServiceCollection services)
{
services.AddWritableConfiguration<PrimaryCommandConfiguration>()
.AddCommandTemplate<PrimaryCommandWidgetViewModel, PrimaryCommandWidgetView>();
}
}
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Page <Page
x:Class="Hyperbar.Desktop.Primary.PrimaryCommandView" x:Class="Hyperbar.Windows.Primary.PrimaryCommandWidgetView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid> <Grid>
@@ -0,0 +1,8 @@
using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Windows.Primary;
public sealed partial class PrimaryCommandWidgetView : Page
{
public PrimaryCommandWidgetView() => InitializeComponent();
}
@@ -0,0 +1,23 @@
using Hyperbar.Lifecycles;
using Hyperbar.Templates;
using Windows.System;
namespace Hyperbar.Windows.Primary;
public class PrimaryCommandWidgetViewModel :
ICommandWidgetViewModel,
ITemplatedViewModel
{
public PrimaryCommandWidgetViewModel(ITemplateFactory templateFactory,
IWritableConfiguration<PrimaryCommandConfiguration> configuration)
{
TemplateFactory = templateFactory;
configuration.Write(args => { args.Add(new KeyAcceleratorCommand { Key = $"138" , Modifiers = [$"{VirtualKey.LeftWindows}"] }); });
configuration.Write(args => { args.Add(new KeyAcceleratorCommand { Key = $"{VirtualKey.Tab}", Modifiers = [$"{VirtualKey.LeftWindows}"] }); });
configuration.Write(args => { args.Add(new KeyAcceleratorCommand { Key = $"{VirtualKey.L}", Modifiers = [$"{VirtualKey.LeftWindows}", $"{VirtualKey.Control}"] }); });
}
public ITemplateFactory TemplateFactory { get; }
}
@@ -5,7 +5,7 @@ using Windows.Win32.Graphics.Gdi;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Windows.Win32.UI.WindowsAndMessaging; using Windows.Win32.UI.WindowsAndMessaging;
namespace Hyperbar.Desktop.Win32; namespace Hyperbar.Windows.Win32;
public static class HwndExtensions public static class HwndExtensions
{ {
@@ -4,7 +4,7 @@ using System;
using Windows.UI.Popups; using Windows.UI.Popups;
using WinRT.Interop; using WinRT.Interop;
namespace Hyperbar.Desktop.Win32; namespace Hyperbar.Windows.Win32;
public static class WindowExtensions public static class WindowExtensions
{ {
@@ -1,4 +1,4 @@
namespace Hyperbar.Desktop.Win32; namespace Hyperbar.Windows.Win32;
public enum WindowPlacement public enum WindowPlacement
{ {
@@ -1,6 +1,6 @@
using System; using System;
namespace Hyperbar.Desktop.Win32; namespace Hyperbar.Windows.Win32;
[Flags] [Flags]
public enum WindowStyle public enum WindowStyle
@@ -5,7 +5,7 @@ using Windows.System;
using Windows.Win32; using Windows.Win32;
using Windows.Win32.UI.KeyboardAndMouseInput; using Windows.Win32.UI.KeyboardAndMouseInput;
namespace Hyperbar.Desktop.Win32; namespace Hyperbar.Windows.Win32;
public class KeyInterop public class KeyInterop
{ {
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Application <Application
x:Class="Hyperbar.Desktop.App" x:Class="Hyperbar.Windows.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:desktop="using:Hyperbar.Desktop"> xmlns:desktop="using:Hyperbar.Windows">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
@@ -1,21 +1,15 @@
using Hyperbar.Desktop.Contextual; using Hyperbar.Windows.Contextual;
using Hyperbar.Desktop.Controls; using Hyperbar.Windows.Controls;
using Hyperbar.Desktop.Primary; using Hyperbar.Windows.Primary;
using Hyperbar.Lifecycles; using Hyperbar.Lifecycles;
using Hyperbar.Templates; using Hyperbar.Templates;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using System;
using System.Collections.Generic;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public class AppConfiguration
{
}
public partial class App : public partial class App :
Application Application
{ {
@@ -46,17 +40,17 @@ public partial class App :
services.AddDataTemplate<CommandViewModel, CommandView>(); services.AddDataTemplate<CommandViewModel, CommandView>();
services.AddCommand<ContextualCommandBuilder>(""); services.AddCommand<ContextualCommandWidgetBuilder>("");
services.AddCommand<PrimaryCommandBuilder>(""); services.AddCommand<PrimaryCommandWidgetBuilder>("");
services.AddTransient(provider => services.AddTransient(provider =>
{ {
static IEnumerable<ICommandViewModel> Resolve(IServiceProvider services) static IEnumerable<ICommandWidgetViewModel> Resolve(IServiceProvider services)
{ {
foreach (ICommandContext commandContext in services.GetServices<ICommandContext>()) foreach (ICommandWidgetContext commandContext in services.GetServices<ICommandWidgetContext>())
{ {
if (commandContext.ServiceProvider.GetService<ICommandViewModel>() is if (commandContext.ServiceProvider.GetService<ICommandWidgetViewModel>() is
ICommandViewModel commandViewModel) ICommandWidgetViewModel commandViewModel)
{ {
yield return commandViewModel; yield return commandViewModel;
} }
@@ -65,11 +59,9 @@ public partial class App :
return Resolve(provider); return Resolve(provider);
}); });
services.ConfigureWritableOptions<AppConfiguration>();
}) })
.Build(); .Build();
await host.RunAsync(); await host.RunAsync();
} }
} }

Before

Width:  |  Height:  |  Size: 432 B

After

Width:  |  Height:  |  Size: 432 B

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

Before

Width:  |  Height:  |  Size: 637 B

After

Width:  |  Height:  |  Size: 637 B

Before

Width:  |  Height:  |  Size: 456 B

After

Width:  |  Height:  |  Size: 456 B

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

@@ -3,7 +3,7 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework> <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>Hyperbar.Desktop</RootNamespace> <RootNamespace>Hyperbar.Windows</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest> <ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;ARM64</Platforms> <Platforms>x86;x64;ARM64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers> <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
@@ -11,6 +11,7 @@
<UseRidGraph>true</UseRidGraph> <UseRidGraph>true</UseRidGraph>
<UseWinUI>true</UseWinUI> <UseWinUI>true</UseWinUI>
<EnableMsixTooling>true</EnableMsixTooling> <EnableMsixTooling>true</EnableMsixTooling>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@@ -36,9 +37,9 @@
<ProjectCapability Include="Msix" /> <ProjectCapability Include="Msix" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Hyperbar.Desktop.Contextual\Hyperbar.Desktop.Contextual.csproj" /> <ProjectReference Include="..\Hyperbar.Windows.Contextual\Hyperbar.Windows.Contextual.csproj" />
<ProjectReference Include="..\Hyperbar.Desktop.Controls\Hyperbar.Desktop.Controls.csproj" /> <ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
<ProjectReference Include="..\Hyperbar.Desktop.Primary\Hyperbar.Desktop.Primary.csproj" /> <ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Windows.Primary.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" /> <ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup> </ItemGroup>
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'"> <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
@@ -1,9 +1,9 @@
using Hyperbar.Desktop.Controls; using Hyperbar.Windows.Controls;
using Hyperbar.Lifecycles; using Hyperbar.Lifecycles;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public class AppInitializer([FromKeyedServices(nameof(CommandViewModel))] CommandView view, public class AppInitializer([FromKeyedServices(nameof(CommandViewModel))] CommandView view,
[FromKeyedServices(nameof(CommandViewModel))] CommandViewModel viewModel, [FromKeyedServices(nameof(CommandViewModel))] CommandViewModel viewModel,
@@ -3,14 +3,14 @@ using Hyperbar.Templates;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
namespace Hyperbar.Desktop namespace Hyperbar.Windows
{ {
public static class IServiceCollectionExtensions public static class IServiceCollectionExtensions
{ {
public static IServiceCollection AddCommand<TCommandBuilder>(this IServiceCollection services, public static IServiceCollection AddCommand<TCommandBuilder>(this IServiceCollection services,
string key) string key)
where TCommandBuilder : where TCommandBuilder :
ICommandBuilder, new() ICommandWidgetBuilder, new()
{ {
TCommandBuilder builder = new(); TCommandBuilder builder = new();
IHost? host = new HostBuilder() IHost? host = new HostBuilder()
@@ -22,7 +22,7 @@ namespace Hyperbar.Desktop
builder.Create(isolatedServices); builder.Create(isolatedServices);
}).Build(); }).Build();
services.AddTransient<ICommandContext>(provider => new CommandContext(host.Services)); services.AddTransient<ICommandWidgetContext>(provider => new CommandWidgetContext(host.Services));
return services; return services;
} }
} }
@@ -15,7 +15,7 @@
<mp:PhoneIdentity PhoneProductId="24ccddba-447f-4d37-891d-523e8d820f45" PhonePublisherId="00000000-0000-0000-0000-000000000000"/> <mp:PhoneIdentity PhoneProductId="24ccddba-447f-4d37-891d-523e8d820f45" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties> <Properties>
<DisplayName>Hyperbar.Desktop</DisplayName> <DisplayName>Hyperbar.Windows</DisplayName>
<PublisherDisplayName>dan_c</PublisherDisplayName> <PublisherDisplayName>dan_c</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo> <Logo>Assets\StoreLogo.png</Logo>
</Properties> </Properties>
@@ -34,8 +34,8 @@
Executable="$targetnametoken$.exe" Executable="$targetnametoken$.exe"
EntryPoint="$targetentrypoint$"> EntryPoint="$targetentrypoint$">
<uap:VisualElements <uap:VisualElements
DisplayName="Hyperbar.Desktop" DisplayName="Hyperbar.Windows"
Description="Hyperbar.Desktop" Description="Hyperbar.Windows"
BackgroundColor="transparent" BackgroundColor="transparent"
Square150x150Logo="Assets\Square150x150Logo.png" Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"> Square44x44Logo="Assets\Square44x44Logo.png">
@@ -1,9 +1,9 @@
{ {
"profiles": { "profiles": {
"Hyperbar.Desktop (Package)": { "Hyperbar.Windows (Package)": {
"commandName": "MsixPackage" "commandName": "MsixPackage"
}, },
"Hyperbar.Desktop (Unpackaged)": { "Hyperbar.Windows (Unpackaged)": {
"commandName": "Project" "commandName": "Project"
} }
} }
@@ -1,6 +1,6 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
namespace Hyperbar.Desktop namespace Hyperbar.Windows
{ {
public interface ITemplateGeneratorFactory public interface ITemplateGeneratorFactory
@@ -6,7 +6,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public class TemplateFactory(ITemplateGeneratorFactory factory, public class TemplateFactory(ITemplateGeneratorFactory factory,
IEnumerable<IDataTemplateDescriptor> descriptors, IEnumerable<IDataTemplateDescriptor> descriptors,
@@ -2,7 +2,7 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public class TemplateGeneratorControl : public class TemplateGeneratorControl :
ContentControl ContentControl
@@ -1,7 +1,7 @@
using Microsoft.UI.Xaml; using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Markup; using Microsoft.UI.Xaml.Markup;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public class TemplateGeneratorFactory : public class TemplateGeneratorFactory :
ITemplateGeneratorFactory ITemplateGeneratorFactory
@@ -10,7 +10,7 @@ public class TemplateGeneratorFactory :
{ {
string xamlString = @" string xamlString = @"
<DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' <DataTemplate xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:desktop='using:Hyperbar.Desktop'> xmlns:desktop='using:Hyperbar.Windows'>
<desktop:TemplateGeneratorControl /> <desktop:TemplateGeneratorControl />
</DataTemplate>"; </DataTemplate>";
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<Page <Page
x:Class="Hyperbar.Desktop.CommandView" x:Class="Hyperbar.Windows.CommandView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ItemsControl ItemTemplateSelector="{Binding TemplateFactory}" ItemsSource="{Binding}"> <ItemsControl ItemTemplateSelector="{Binding TemplateFactory}" ItemsSource="{Binding}">
@@ -1,7 +1,7 @@
using Microsoft.UI.Xaml.Controls; using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input; using Microsoft.UI.Xaml.Input;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public sealed partial class CommandView : Page public sealed partial class CommandView : Page
{ {
@@ -2,20 +2,17 @@
using Hyperbar.Templates; using Hyperbar.Templates;
using System.Collections.Generic; using System.Collections.Generic;
namespace Hyperbar.Desktop; namespace Hyperbar.Windows;
public partial class CommandViewModel : public partial class CommandViewModel :
ObservableCollectionViewModel, ObservableCollectionViewModel,
ITemplatedViewModel ITemplatedViewModel
{ {
public CommandViewModel(ITemplateFactory templateFactory, public CommandViewModel(ITemplateFactory templateFactory,
IEnumerable<ICommandViewModel> commands, IEnumerable<ICommandWidgetViewModel> commands)
IWritableConfiguration<AppConfiguration> options)
{ {
TemplateFactory = templateFactory; TemplateFactory = templateFactory;
AddRange(commands); AddRange(commands);
options.Update(args => { });
} }
public ITemplateFactory TemplateFactory { get; } public ITemplateFactory TemplateFactory { get; }
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1"> <assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="Hyperbar.Desktop.app"/> <assemblyIdentity version="1.0.0.0" name="Hyperbar.Windows.app"/>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application> <application>
+5 -5
View File
@@ -3,17 +3,17 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.8.34330.188 VisualStudioVersion = 17.8.34330.188
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Desktop", "Hyperbar.Desktop\Hyperbar.Desktop.csproj", "{5C4824EE-23AB-495C-B55A-1F7C2A489698}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Windows", "Hyperbar.Windows\Hyperbar.Windows.csproj", "{5C4824EE-23AB-495C-B55A-1F7C2A489698}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Desktop.Controls", "Hyperbar.Desktop.Controls\Hyperbar.Desktop.Controls.csproj", "{48ECC6A3-94FF-405D-9DB5-46A725C1B117}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Windows.Controls", "Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj", "{48ECC6A3-94FF-405D-9DB5-46A725C1B117}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Desktop.Win32", "Hyperbar.Desktop.Win32\Hyperbar.Desktop.Win32.csproj", "{8A4BBC50-970C-4FA8-9F21-0FA63269222F}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Windows.Win32", "Hyperbar.Windows.Win32\Hyperbar.Windows.Win32.csproj", "{8A4BBC50-970C-4FA8-9F21-0FA63269222F}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar", "Hyperbar\Hyperbar.csproj", "{E5795878-C7E3-4386-86FA-33681BCF8D5B}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar", "Hyperbar\Hyperbar.csproj", "{E5795878-C7E3-4386-86FA-33681BCF8D5B}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Desktop.Contextual", "Hyperbar.Desktop.Contextual\Hyperbar.Desktop.Contextual.csproj", "{C32D4073-2A9B-4257-8895-09951FAD8E7A}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Windows.Contextual", "Hyperbar.Windows.Contextual\Hyperbar.Windows.Contextual.csproj", "{C32D4073-2A9B-4257-8895-09951FAD8E7A}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Desktop.Primary", "Hyperbar.Desktop.Primary\Hyperbar.Desktop.Primary.csproj", "{AFB8A3EB-8831-4041-AE05-3E0EF672887C}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Hyperbar.Windows.Primary", "Hyperbar.Windows.Primary\Hyperbar.Windows.Primary.csproj", "{AFB8A3EB-8831-4041-AE05-3E0EF672887C}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -23,15 +23,16 @@ public class ConfigurationWriter<TConfiguration>(string path,
private readonly JsonSerializerOptions? serializerOptions = serializerOptions ??= DefaultSerializerOptions(); private readonly JsonSerializerOptions? serializerOptions = serializerOptions ??= DefaultSerializerOptions();
public void Write(Action<TConfiguration?>? updateDelegate = null) public void Write(Action<TConfiguration> updateDelegate)
{ {
TConfiguration? updatedValue = TryGet(out TConfiguration? value) ? value : new TConfiguration(); if ((TryGet(out TConfiguration? value) ? value : new TConfiguration()) is TConfiguration updatedValue)
{
updateDelegate?.Invoke(updatedValue); updateDelegate?.Invoke(updatedValue);
Write(updatedValue); Write(updatedValue);
}
} }
public void Write(TConfiguration? value) public void Write(TConfiguration value)
{ {
if (!File.Exists(path)) if (!File.Exists(path))
{ {
@@ -81,7 +82,7 @@ public class ConfigurationWriter<TConfiguration>(string path,
stream.SetLength(stream.Position); stream.SetLength(stream.Position);
} }
private bool TryGet<T>(out T? value) private bool TryGet(out TConfiguration? value)
{ {
if (File.Exists(path)) if (File.Exists(path))
{ {
@@ -90,7 +91,7 @@ public class ConfigurationWriter<TConfiguration>(string path,
using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent); using JsonDocument jsonDocument = JsonDocument.Parse(jsonContent);
if (jsonDocument.RootElement.TryGetProperty(section, out JsonElement sectionValue)) if (jsonDocument.RootElement.TryGetProperty(section, out JsonElement sectionValue))
{ {
value = JsonSerializer.Deserialize<T>(sectionValue.ToString(), serializerOptions); value = JsonSerializer.Deserialize<TConfiguration>(sectionValue.ToString(), serializerOptions);
return true; return true;
} }
} }
@@ -5,8 +5,8 @@ namespace Hyperbar.Options
where TConfiguration : where TConfiguration :
class, new() class, new()
{ {
void Write(Action<TConfiguration?>? updateDelegate = null); void Write(Action<TConfiguration> updateDelegate);
void Write(TConfiguration? value); void Write(TConfiguration value);
} }
} }
@@ -7,6 +7,6 @@ public interface IWritableConfiguration<out TConfiguration> :
where TConfiguration : where TConfiguration :
class, new() class, new()
{ {
void Update(Action<TConfiguration?> updateAction, void Write(Action<TConfiguration> updateAction,
bool reload = true); bool reload = true);
} }
@@ -15,7 +15,7 @@ public class WritableConfiguration<TConfiguration>(IConfigurationWriter<TConfigu
public TConfiguration Get(string? name) => options.Get(name); public TConfiguration Get(string? name) => options.Get(name);
public void Update(Action<TConfiguration?> updateDelegate, public void Write(Action<TConfiguration> updateDelegate,
bool reload = true) bool reload = true)
{ {
writer.Write(updateDelegate); writer.Write(updateDelegate);
@@ -1,7 +1,6 @@
using Hyperbar.Lifecycles; using Hyperbar.Lifecycles;
using Hyperbar.Options; using Hyperbar.Options;
using Hyperbar.Templates; using Hyperbar.Templates;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders; using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@@ -11,16 +10,15 @@ using System.Text.Json;
namespace Hyperbar; namespace Hyperbar;
public static class IServiceCollectionExtensions public static class IServiceCollectionExtensions
{ {
public static IServiceCollection ConfigureWritableOptions<TConfiguration>(this IServiceCollection services, public static IServiceCollection AddWritableConfiguration<TConfiguration>(this IServiceCollection services,
string path = "Settings.json", string path = "Settings.json")
Func<JsonSerializerOptions>? defaultSerializerOptions = null)
where TConfiguration : where TConfiguration :
class, new() class, new()
{ {
return services.ConfigureWritableOptions<TConfiguration>(typeof(TConfiguration).Name, path); return services.AddWritableConfiguration<TConfiguration>(typeof(TConfiguration).Name, path);
} }
public static IServiceCollection ConfigureWritableOptions<TConfiguration>(this IServiceCollection services, public static IServiceCollection AddWritableConfiguration<TConfiguration>(this IServiceCollection services,
string section, string section,
string path = "Settings.json", string path = "Settings.json",
Action<JsonSerializerOptions>? serializerDelegate = null) Action<JsonSerializerOptions>? serializerDelegate = null)
@@ -59,16 +57,16 @@ public static class IServiceCollectionExtensions
public static IServiceCollection AddCommandTemplate<TCommand, TCommandTemplate>(this IServiceCollection services) public static IServiceCollection AddCommandTemplate<TCommand, TCommandTemplate>(this IServiceCollection services)
where TCommand : where TCommand :
ICommandViewModel ICommandWidgetViewModel
{ {
Type dataType = typeof(TCommand); Type dataType = typeof(TCommand);
Type templateType = typeof(TCommandTemplate); Type templateType = typeof(TCommandTemplate);
string key = dataType.Name; string key = dataType.Name;
services.AddTransient(typeof(ICommandViewModel), dataType); services.AddTransient(typeof(ICommandWidgetViewModel), dataType);
services.AddTransient(templateType); services.AddTransient(templateType);
services.AddKeyedTransient(typeof(ICommandViewModel), key, dataType); services.AddKeyedTransient(typeof(ICommandWidgetViewModel), key, dataType);
services.AddKeyedTransient(templateType, key); services.AddKeyedTransient(templateType, key);
services.AddTransient<IDataTemplateDescriptor>(provider => new DataTemplateDescriptor services.AddTransient<IDataTemplateDescriptor>(provider => new DataTemplateDescriptor
@@ -1,7 +1,7 @@
namespace Hyperbar.Lifecycles; namespace Hyperbar.Lifecycles;
public class CommandContext(IServiceProvider serviceProvider) : public class CommandWidgetContext(IServiceProvider serviceProvider) :
ICommandContext ICommandWidgetContext
{ {
public IServiceProvider ServiceProvider => serviceProvider; public IServiceProvider ServiceProvider => serviceProvider;
} }
@@ -2,7 +2,7 @@
namespace Hyperbar.Lifecycles; namespace Hyperbar.Lifecycles;
public interface ICommandBuilder public interface ICommandWidgetBuilder
{ {
void Create(IServiceCollection services); void Create(IServiceCollection services);
} }
@@ -1,6 +1,6 @@
namespace Hyperbar.Lifecycles; namespace Hyperbar.Lifecycles;
public interface ICommandContext public interface ICommandWidgetContext
{ {
IServiceProvider ServiceProvider { get; } IServiceProvider ServiceProvider { get; }
} }
@@ -1,6 +1,6 @@
namespace Hyperbar.Lifecycles; namespace Hyperbar.Lifecycles;
public interface ICommandViewModel public interface ICommandWidgetViewModel
{ {
} }