diff options
author | Rory& <root@rory.gay> | 2024-01-24 02:31:56 +0100 |
---|---|---|
committer | Rory& <root@rory.gay> | 2024-01-24 17:05:25 +0100 |
commit | 03313562d21d5db9bf6a14ebbeab80e06c883d3a (patch) | |
tree | e000546a2ee8e6a886a7ed9fd01ad674178fb7cb /MatrixUtils.Desktop/App.axaml.cs | |
parent | Make RMU installable (diff) | |
download | MatrixUtils-03313562d21d5db9bf6a14ebbeab80e06c883d3a.tar.xz |
MRU->RMU, fixes, cleanup
Diffstat (limited to 'MatrixUtils.Desktop/App.axaml.cs')
-rw-r--r-- | MatrixUtils.Desktop/App.axaml.cs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/MatrixUtils.Desktop/App.axaml.cs b/MatrixUtils.Desktop/App.axaml.cs new file mode 100644 index 0000000..3a106ab --- /dev/null +++ b/MatrixUtils.Desktop/App.axaml.cs @@ -0,0 +1,49 @@ +using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; +using Avalonia.Markup.Xaml; +using Avalonia.Styling; +using LibMatrix.Services; +using MatrixUtils.Abstractions; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; + +namespace MatrixUtils.Desktop; + +public partial class App : Application { + public IHost host { get; set; } + + public override void OnFrameworkInitializationCompleted() { + host = Host.CreateDefaultBuilder().ConfigureServices((ctx, services) => { + services.AddSingleton<RMUDesktopConfiguration>(); + services.AddSingleton<SentryService>(); + services.AddSingleton<TieredStorageService>(x => + new TieredStorageService( + cacheStorageProvider: new FileStorageProvider(x.GetService<RMUDesktopConfiguration>()!.CacheStoragePath), + dataStorageProvider: new FileStorageProvider(x.GetService<RMUDesktopConfiguration>()!.DataStoragePath) + ) + ); + services.AddSingleton(new RoryLibMatrixConfiguration { + AppName = "MatrixUtils.Desktop" + }); + services.AddRoryLibMatrixServices(); + // foreach (var commandClass in new ClassCollector<ICommand>().ResolveFromAllAccessibleAssemblies()) { + // Console.WriteLine($"Adding command {commandClass.Name}"); + // services.AddScoped(typeof(ICommand), commandClass); + // } + services.AddSingleton<RMUStorageWrapper>(); + services.AddSingleton<MainWindow>(); + services.AddSingleton(this); + }).UseConsoleLifetime().Build(); + + if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { + var scopeFac = host.Services.GetService<IServiceScopeFactory>(); + var scope = scopeFac.CreateScope(); + desktop.MainWindow = scope.ServiceProvider.GetRequiredService<MainWindow>(); + } + + if(Environment.GetEnvironmentVariable("AVALONIA_THEME")?.Equals("dark", StringComparison.OrdinalIgnoreCase) ?? false) + RequestedThemeVariant = ThemeVariant.Dark; + + base.OnFrameworkInitializationCompleted(); + } +} \ No newline at end of file |