forked from WalletWasabi/WalletWasabi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
143 lines (124 loc) · 4.04 KB
/
Program.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using Avalonia;
using Avalonia.Rendering;
using Avalonia.Threading;
using AvalonStudio.Shell;
using AvalonStudio.Shell.Extensibility.Platforms;
using NBitcoin;
using ReactiveUI;
using System;
using System.IO;
using System.Reactive.Concurrency;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Gui.CommandLine;
using WalletWasabi.Gui.Controls.LockScreen;
using WalletWasabi.Gui.ManagedDialogs;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Logging;
namespace WalletWasabi.Gui
{
internal class Program
{
private static StatusBarViewModel StatusBar = null;
private static Global Global;
#pragma warning disable IDE1006 // Naming Styles
private static async Task Main(string[] args)
#pragma warning restore IDE1006 // Naming Styles
{
bool runGui = false;
try
{
Global = new Global();
Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui");
AvaloniaGlobalComponent.AvaloniaInstance = Global;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
runGui = await CommandInterpreter.ExecuteCommandsAsync(Global, args);
if (!runGui)
{
return;
}
Logger.LogSoftwareStarted("Wasabi GUI");
BuildAvaloniaApp().StartShellApp("Wasabi Wallet", AppMainAsync, args);
}
catch (Exception ex)
{
Logger.LogCritical(ex);
throw;
}
finally
{
StatusBar?.Dispose();
await Global.DisposeAsync();
AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException;
if (runGui)
{
Logger.LogSoftwareStopped("Wasabi GUI");
}
}
}
private static async void AppMainAsync(string[] args)
{
(Application.Current as App).SetDataContext(Global);
AvalonStudio.Extensibility.Theme.ColorTheme.LoadTheme(AvalonStudio.Extensibility.Theme.ColorTheme.VisualStudioDark);
MainWindowViewModel.Instance = new MainWindowViewModel { Global = Global };
StatusBar = new StatusBarViewModel(Global);
MainWindowViewModel.Instance.StatusBar = StatusBar;
MainWindowViewModel.Instance.LockScreen = new LockScreenViewModel(Global);
await Global.InitializeNoWalletAsync();
StatusBar.Initialize(Global.Nodes.ConnectedNodes, Global.Synchronizer);
if (Global.Network != Network.Main)
{
MainWindowViewModel.Instance.Title += $" - {Global.Network}";
}
Dispatcher.UIThread.Post(GC.Collect);
}
private static void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
{
Logger.LogWarning(e?.Exception);
}
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Logger.LogWarning(e?.ExceptionObject as Exception);
}
private static AppBuilder BuildAvaloniaApp()
{
bool useGpuLinux = true;
var result = AppBuilder.Configure<App>();
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
result
.UseWin32()
.UseSkia();
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
if (Helpers.Utils.DetectLLVMPipeRasterizer())
{
useGpuLinux = false;
}
result.UsePlatformDetect()
.UseManagedSystemDialogs();
}
else
{
result.UsePlatformDetect()
.UseManagedSystemDialogs();
}
// TODO remove this overriding of RenderTimer when Avalonia 0.9 is released.
// fixes "Thread Leak" issue in 0.8.1 Avalonia.
var old = result.WindowingSubsystemInitializer;
result.UseWindowingSubsystem(() =>
{
old();
AvaloniaLocator.CurrentMutable.Bind<IRenderTimer>().ToConstant(new DefaultRenderTimer(60));
});
return result
.With(new Win32PlatformOptions { AllowEglInitialization = true, UseDeferredRendering = true })
.With(new X11PlatformOptions { UseGpu = useGpuLinux, WmClass = "Wasabi Wallet" })
.With(new AvaloniaNativePlatformOptions { UseDeferredRendering = true, UseGpu = true })
.With(new MacOSPlatformOptions { ShowInDock = true });
}
}
}