using System.Windows;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Moli.Desktop.Configuration;
using Moli.Desktop.Host;
using Moli.Desktop.Management;
using Moli.Desktop.Runtime;
using Moli.Desktop.Tray;
namespace Moli.Desktop;
/// Application entry point and composition root.
public partial class App : System.Windows.Application
{
private IHost? _host;
protected override async void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
_host = DesktopHostBuilder.Create(e.Args).Build();
await _host.StartAsync();
await _host.Services.GetRequiredService().InstallAsync();
await _host.Services.GetRequiredService().StartAsync();
await _host.Services.GetRequiredService().StartAsync();
var settings = await _host.Services.GetRequiredService().LoadAppSettingsAsync();
if (!settings.Startup.StartMinimized)
{
_host.Services.GetRequiredService().Show();
}
}
protected override async void OnExit(ExitEventArgs e)
{
if (_host is not null)
{
await _host.Services.GetRequiredService().StopAsync();
await _host.Services.GetRequiredService().ShutdownAsync();
await _host.StopAsync(TimeSpan.FromSeconds(5));
_host.Dispose();
}
base.OnExit(e);
}
}