more refoctoring work

This commit is contained in:
TheXamlGuy
2024-01-20 21:58:57 +00:00
parent 3a268db79d
commit 45070dc560
42 changed files with 477 additions and 361 deletions
+32 -33
View File
@@ -1,12 +1,11 @@
using Hyperbar.Windows.Controls;
using Hyperbar.Windows.MediaController;
using Hyperbar.Windows.Primary;
using Hyperbar.Windows.UI;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using System.Reflection;
namespace Hyperbar.Windows;
@@ -19,17 +18,12 @@ public partial class App :
{
base.OnLaunched(args);
DispatcherQueueSynchronizationContext context = new(DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
IHost? host = Host.CreateDefaultBuilder()
.UseContentRoot(AppContext.BaseDirectory)
IHost? host = new HostBuilder()
.UseContentRoot(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
Assembly.GetEntryAssembly()?.GetName().Name!), true)
.ConfigureAppConfiguration(config =>
{
config.SetBasePath(AppContext.BaseDirectory);
config.AddJsonFile("Settings.json", true, true);
config.Build();
})
.ConfigureServices((context, services) =>
{
@@ -41,7 +35,7 @@ public partial class App :
services.AddSingleton<IDispatcher, Dispatcher>();
services.AddHostedService<AppService>();
services.AddConfiguration<AppConfiguration>();
services.AddConfiguration<AppConfiguration>(args => { args.Placement = DesktopBarPlacemenet.Top; });
services.AddTransient<IInitializer, AppInitializer>();
services.AddTransient<ITemplateFactory, TemplateFactory>();
@@ -52,31 +46,36 @@ public partial class App :
services.AddHandler<AppConfigurationChangedHandler>();
services.AddWidget<MediaControllerWidgetBuilder>();
services.AddWidget<PrimaryWidgetConfigurationBuilder>();
//services.AddWidget<MediaControllerWidgetBuilder>();
//services.AddWidget<PrimaryWidget>();
services.AddTransient(provider =>
{
static IEnumerable<WidgetContainerViewModel> Resolve(IServiceProvider services)
{
int index = 0;
foreach (WidgetContext widgetContext in services.GetServices<WidgetContext>())
{
if (widgetContext.ServiceProvider.GetServices<IWidgetViewModel>() is
IEnumerable<IWidgetViewModel> viewModels)
{
yield return (WidgetContainerViewModel)ActivatorUtilities.CreateInstance(widgetContext.ServiceProvider,
typeof(WidgetContainerViewModel), viewModels, index % 2 == 1);
//services.AddTransient(provider =>
//{
// static IEnumerable<WidgetContainerViewModel> Resolve(IServiceProvider services)
// {
// int index = 0;
// foreach (WidgetContext widgetContext in services.GetServices<WidgetContext>())
// {
// if (widgetContext.ServiceProvider.GetService<IWidget>() is IWidget widget)
// {
// if (widgetContext.ServiceProvider.GetServices<IWidgetViewModel>() is
// IEnumerable<IWidgetViewModel> viewModels)
// {
// yield return (WidgetContainerViewModel)ActivatorUtilities.CreateInstance(widgetContext.ServiceProvider,
// typeof(WidgetContainerViewModel), viewModels, index % 2 == 1, widget.Id);
index++;
}
}
}
// index++;
// }
// }
// }
// }
return Resolve(provider);
});
// return Resolve(provider);
//});
})
.Build();
.Build();
var d = host.Services.GetService<JsonConfigurationProvider>();
await host.RunAsync();
}
+10 -24
View File
@@ -28,6 +28,10 @@
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<PackageReference Include="CommunityToolkit.WinUI" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls" Version="7.1.2" />
<PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.231202003-experimental1" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.25936-preview" />
@@ -36,31 +40,13 @@
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Contextual\Hyperbar.Widget.Contextual.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.MediaController\Hyperbar.Windows.MediaController.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Primary\Hyperbar.Widget.Primary.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.UI\Hyperbar.Windows.UI.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
<ItemGroup>
<Page Update="Views\WidgetSplitButtonView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Views\WidgetContainerView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Update="Views\WidgetButtonView.xaml">
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Hyperbar.Windows.Controls\Hyperbar.Windows.Controls.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.Interop\Hyperbar.Windows.Interop.csproj" />
<ProjectReference Include="..\Hyperbar.Windows.UI\Hyperbar.Windows.UI.csproj" />
<ProjectReference Include="..\Hyperbar\Hyperbar.csproj" />
</ItemGroup>
</Project>
@@ -1,6 +1,6 @@
using Hyperbar.Windows.Controls;
namespace Hyperbar.Windows.Primary;
namespace Hyperbar.Windows;
public class AppConfigurationChangedHandler(DesktopBar desktopFlyout,
AppConfiguration configuration) :
@@ -9,13 +9,11 @@ namespace Hyperbar.Windows
{
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddWidget<TWidgetBuilder>(this IServiceCollection services)
where TWidgetBuilder :
IWidgetBuilder, new()
public static IServiceCollection AddWidget<TWidget>(this IServiceCollection services)
where TWidget :
IWidget,
new()
{
DispatcherQueueSynchronizationContext context = new(DispatcherQueue.GetForCurrentThread());
SynchronizationContext.SetSynchronizationContext(context);
IHost? host = new HostBuilder()
.UseContentRoot(AppContext.BaseDirectory)
.ConfigureAppConfiguration(config =>
@@ -48,8 +46,9 @@ namespace Hyperbar.Windows
isolatedServices.AddContentTemplate<WidgetButtonViewModel, WidgetButtonView>();
isolatedServices.AddContentTemplate<WidgetSplitButtonViewModel, WidgetSplitButtonView>();
TWidgetBuilder builder = new();
builder.Create(isolatedServices);
TWidget widget = new();
IWidgetBuilder builder = widget.Create();
isolatedServices.AddRange(builder.Services);
}).Build();