-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.axaml.cs
More file actions
40 lines (33 loc) · 1.38 KB
/
Copy pathApp.axaml.cs
File metadata and controls
40 lines (33 loc) · 1.38 KB
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
using System;
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using DravusSensorPanel.Models;
using DravusSensorPanel.Services;
using DravusSensorPanel.Services.InfoExtractors;
using DravusSensorPanel.Views.Windows;
using Microsoft.Extensions.DependencyInjection;
namespace DravusSensorPanel;
public class App : Application {
public static IServiceProvider? ServiceProvider { get; private set; }
public override void Initialize() {
ServiceProvider = Startup.ConfigureServices();
AvaloniaXamlLoader.Load(this);
}
public override void OnFrameworkInitializationCompleted() {
if ( ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop ) {
desktop.MainWindow = ServiceProvider.GetRequiredService<SplashScreenWindow>();
desktop.Exit += OnExit;
}
base.OnFrameworkInitializationCompleted();
}
private void OnExit(object? sender, ControlledApplicationLifetimeExitEventArgs e) {
foreach ( InfoExtractor? infoExtractor in ServiceProvider.GetServices<InfoExtractor>() ) {
infoExtractor.Dispose();
}
foreach ( PanelItem sensorPanelItem in ServiceProvider.GetRequiredService<SensorPanelService>().SensorPanel
.Items ) {
sensorPanelItem.Dispose();
}
}
}