-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.xaml.cs
More file actions
65 lines (57 loc) · 1.79 KB
/
App.xaml.cs
File metadata and controls
65 lines (57 loc) · 1.79 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.UI.Xaml;
using Process_Explorer.GUI.Extensions;
using Process_Explorer.GUI.Helpers;
using System;
namespace Process_Explorer.GUI
{
public partial class App : Application
{
private IHost _host = default!;
private Window _window = default!;
public App()
{
InitializeComponent();
SetupApplication();
SetupHost();
}
private void SetupHost()
{
_host = Host.CreateDefaultBuilder()
.ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
logging.SetMinimumLevel(LogLevel.Debug);
})
.ConfigureServices((ctx, services) => services.ConfigureServices())
.Build();
}
private void SetupApplication()
{
try
{
Native.Application.SetPrivileges();
Native.Application.SetPriority();
}
catch (Exception ex)
{
ToastNotificationHelper.ShowMessage("Process Explorer Message", ex.Message);
}
}
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
await _host.StartAsync();
_window = _host.Services.GetRequiredService<MainWindow>();
_window.Activate();
_window.Closed += OnMainWindowClosed;
}
private async void OnMainWindowClosed(object? sender, WindowEventArgs e)
{
await _host.StopAsync(TimeSpan.FromSeconds(5));
_host.Dispose();
}
}
}