blob: 3a106ab69d30473b356a5d5630e447f05695ad87 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
}
}
|