-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.xaml.cs
66 lines (55 loc) · 2.11 KB
/
App.xaml.cs
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
66
using System;
using System.Threading.Tasks;
using Coder.Desktop.App.Services;
using Coder.Desktop.App.ViewModels;
using Coder.Desktop.App.Views;
using Coder.Desktop.App.Views.Pages;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Xaml;
namespace Coder.Desktop.App;
public partial class App : Application
{
private readonly IServiceProvider _services;
private bool _handleWindowClosed = true;
public App()
{
var services = new ServiceCollection();
services.AddSingleton<ICredentialManager, CredentialManager>();
services.AddSingleton<IRpcController, RpcController>();
// SignInWindow views and view models
services.AddTransient<SignInViewModel>();
services.AddTransient<SignInWindow>();
// TrayWindow views and view models
services.AddTransient<TrayWindowDisconnectedViewModel>();
services.AddTransient<TrayWindowDisconnectedPage>();
services.AddTransient<TrayWindowLoginRequiredViewModel>();
services.AddTransient<TrayWindowLoginRequiredPage>();
services.AddTransient<TrayWindowLoginRequiredViewModel>();
services.AddTransient<TrayWindowLoginRequiredPage>();
services.AddTransient<TrayWindowViewModel>();
services.AddTransient<TrayWindowMainPage>();
services.AddTransient<TrayWindow>();
_services = services.BuildServiceProvider();
InitializeComponent();
}
public async Task ExitApplication()
{
_handleWindowClosed = false;
Exit();
var rpcManager = _services.GetRequiredService<IRpcController>();
// TODO: send a StopRequest if we're connected???
await rpcManager.DisposeAsync();
Environment.Exit(0);
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var trayWindow = _services.GetRequiredService<TrayWindow>();
// Prevent the TrayWindow from closing, just hide it.
trayWindow.Closed += (sender, args) =>
{
if (!_handleWindowClosed) return;
args.Handled = true;
trayWindow.AppWindow.Hide();
};
}
}