Move initialisation of UiConfig out of MainWindow.xaml.cs
MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
using Avalonia;
-using Avalonia.Controls;
using Avalonia.Controls.Notifications;
using Avalonia.Markup.Xaml;
-using Avalonia.Media;
-using Avalonia.Native;
-using Avalonia.Threading;
using AvalonStudio.Extensibility;
-using AvalonStudio.Extensibility.Theme;
using AvalonStudio.Shell;
using AvalonStudio.Shell.Controls;
-using NBitcoin;
-using ReactiveUI;
using Splat;
using System;
using System.ComponentModel;
-using System.Composition;
-using System.IO;
using System.Linq;
using System.Reactive.Linq;
-using System.Reactive.Threading.Tasks;
-using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Gui.Dialogs;
-using WalletWasabi.Gui.Helpers;
using WalletWasabi.Gui.Tabs.WalletManager;
using WalletWasabi.Gui.ViewModels;
using WalletWasabi.Logging;
@@ -51,48 +39,16 @@ namespace WalletWasabi.Gui
};
Locator.CurrentMutable.RegisterConstant<INotificationManager>(notificationManager);
+
+ Closing += MainWindow_ClosingAsync;
}
private Global Global { get; }
private void InitializeComponent()
{
- Closing += MainWindow_ClosingAsync;
- AvaloniaXamlLoader.Load(this);
- DisplayWalletManager();
-
- var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
- var uiConfig = new UiConfig(uiConfigFilePath);
- uiConfig.LoadOrCreateDefaultFileAsync()
- .ToObservable(RxApp.TaskpoolScheduler)
- .Take(1)
- .ObserveOn(RxApp.MainThreadScheduler)
- .Subscribe(_ =>
- {
- try
- {
- Global.InitializeUiConfig(uiConfig);
- Logger.LogInfo($"{nameof(Global.UiConfig)} is successfully initialized.");
- if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
- {
- MainWindowViewModel.Instance.Width = uiConfig.Width;
- MainWindowViewModel.Instance.Height = uiConfig.Height;
- MainWindowViewModel.Instance.WindowState = uiConfig.WindowState;
- }
- else
- {
- MainWindowViewModel.Instance.WindowState = WindowState.Maximized;
- }
-
- MainWindowViewModel.Instance.LockScreen.Initialize();
- }
- catch (Exception ex)
- {
- Logger.LogError(ex);
- }
- },
- onError: ex => Logger.LogError(ex));
+ AvaloniaXamlLoader.Load(this);
}
private int _closingState;
@@ -194,22 +150,5 @@ namespace WalletWasabi.Gui
}
}
}
-
- private void DisplayWalletManager()
- {
- var walletManagerViewModel = IoC.Get<WalletManagerViewModel>();
- IoC.Get<IShell>().AddDocument(walletManagerViewModel);
-
- var isAnyDesktopWalletAvailable = Directory.Exists(Global.WalletsDir) && Directory.EnumerateFiles(Global.WalletsDir).Any();
-
- if (isAnyDesktopWalletAvailable)
- {
- walletManagerViewModel.SelectLoadWallet();
- }
- else
- {
- walletManagerViewModel.SelectGenerateWallet();
- }
- }
}
}

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
using Avalonia;
using Avalonia.Dialogs;
-using Avalonia.Rendering;
using Avalonia.Threading;
using AvalonStudio.Shell;
using AvalonStudio.Shell.Extensibility.Platforms;
using NBitcoin;
-using ReactiveUI;
using Splat;
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.ViewModels;
using WalletWasabi.Logging;
@@ -40,10 +36,12 @@ namespace WalletWasabi.Gui
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
runGui = await CommandInterpreter.ExecuteCommandsAsync(Global, args);
+
if (!runGui)
{
return;
}
+
Logger.LogSoftwareStarted("Wasabi GUI");
BuildAvaloniaApp().StartShellApp("Wasabi Wallet", AppMainAsync, args);
@@ -69,11 +67,25 @@ namespace WalletWasabi.Gui
private static async void AppMainAsync(string[] args)
{
+ try
+ {
+ var uiConfigFilePath = Path.Combine(Global.DataDir, "UiConfig.json");
+ var uiConfig = new UiConfig(uiConfigFilePath);
+ await uiConfig.LoadOrCreateDefaultFileAsync();
+
+ Global.InitializeUiConfig(uiConfig);
+ Logger.LogInfo($"{nameof(Global.UiConfig)} is successfully initialized.");
+ }
+ catch (Exception ex)
+ {
+ Logger.LogError(ex);
+
+ }
+
AvalonStudio.Extensibility.Theme.ColorTheme.LoadTheme(AvalonStudio.Extensibility.Theme.ColorTheme.VisualStudioDark);
MainWindowViewModel.Instance = new MainWindowViewModel();
StatusBar = new StatusBarViewModel();
MainWindowViewModel.Instance.StatusBar = StatusBar;
- MainWindowViewModel.Instance.LockScreen = new LockScreenViewModel();
await Global.InitializeNoWalletAsync();

MODIFY
WalletWasabi.Gui/ViewModels/MainWindowViewModel.cs
WalletWasabi.Gui/ViewModels/MainWindowViewModel.cs
@@ -3,11 +3,14 @@ using AvalonStudio.Extensibility;
using AvalonStudio.Extensibility.Dialogs;
using AvalonStudio.Shell;
using ReactiveUI;
-using System;
+using Splat;
+using System.IO;
+using System.Linq;
using System.Reactive;
+using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Gui.Controls.LockScreen;
-using WalletWasabi.Logging;
+using WalletWasabi.Gui.Tabs.WalletManager;
namespace WalletWasabi.Gui.ViewModels
{
@@ -69,6 +72,48 @@ namespace WalletWasabi.Gui.ViewModels
public MainWindowViewModel()
{
Shell = IoC.Get<IShell>();
+
+ var global = Locator.Current.GetService<Global>();
+
+ if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
+ {
+ var uiConfig = global.UiConfig;
+
+ Width = uiConfig.Width;
+ Height = uiConfig.Height;
+ WindowState = uiConfig.WindowState;
+ }
+ else
+ {
+ WindowState = WindowState.Maximized;
+ }
+
+ StatusBar = new StatusBarViewModel();
+
+ LockScreen = new LockScreenViewModel();
+
+ LockScreen.Initialize();
+
+ DisplayWalletManager();
+ }
+
+ private void DisplayWalletManager()
+ {
+ var walletManagerViewModel = IoC.Get<WalletManagerViewModel>();
+ IoC.Get<IShell>().AddDocument(walletManagerViewModel);
+
+ var global = Locator.Current.GetService<Global>();
+
+ var isAnyDesktopWalletAvailable = Directory.Exists(global.WalletsDir) && Directory.EnumerateFiles(global.WalletsDir).Any();
+
+ if (isAnyDesktopWalletAvailable)
+ {
+ walletManagerViewModel.SelectLoadWallet();
+ }
+ else
+ {
+ walletManagerViewModel.SelectGenerateWallet();
+ }
}
public IShell Shell { get; }

Move initialisation of UiConfig out of MainWindow.xaml.cs