private static async void AppMainAsync(string[] args) { try { AvalonStudio.Extensibility.Theme.ColorTheme.LoadTheme(AvalonStudio.Extensibility.Theme.ColorTheme.VisualStudioDark); MainWindowViewModel.Instance = new MainWindowViewModel(); await Global.InitializeNoWalletAsync(); MainWindowViewModel.Instance.Initialize(); Dispatcher.UIThread.Post(GC.Collect); } catch (Exception ex) { if (!(ex is OperationCanceledException)) { Logger.LogCritical(ex); } await Global.DisposeAsync().ConfigureAwait(false); Environment.Exit(1); } }
private static async void AppMainAsync(string[] args) { try { AvalonStudio.Extensibility.Theme.ColorTheme.LoadTheme(AvalonStudio.Extensibility.Theme.ColorTheme.VisualStudioDark); MainWindowViewModel.Instance = new MainWindowViewModel(Global.Network, Global.UiConfig, Global.WalletManager, new StatusBarViewModel(), IoC.Get <IShell>()); await Global.InitializeNoWalletAsync(); MainWindowViewModel.Instance.Initialize(Global.Nodes.ConnectedNodes, Global.Synchronizer); Dispatcher.UIThread.Post(GC.Collect); } catch (Exception ex) { if (!(ex is OperationCanceledException)) { Logger.LogCritical(ex); } await Global.DisposeAsync().ConfigureAwait(false); Environment.Exit(1); } }
#pragma warning disable IDE1006 // Naming Styles private static async Task Main(string[] args) #pragma warning restore IDE1006 // Naming Styles { Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt")); StatusBarViewModel statusBar = null; try { Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; BuildAvaloniaApp() .BeforeStarting(async builder => { MainWindowViewModel.Instance = new MainWindowViewModel(); var configFilePath = Path.Combine(Global.DataDir, "Config.json"); var config = new Config(configFilePath); await config.LoadOrCreateDefaultFileAsync(); Logger.LogInfo <Config>("Config is successfully initialized."); Global.InitializeConfig(config); if (!File.Exists(Global.IndexFilePath)) // Load the index file from working folder if we have it. { var cachedIndexFilePath = Path.Combine("Assets", Path.GetFileName(Global.IndexFilePath)); if (File.Exists(cachedIndexFilePath)) { File.Copy(cachedIndexFilePath, Global.IndexFilePath, overwrite: false); } } Global.InitializeNoWallet(); statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.Synchronizer, Global.UpdateChecker); MainWindowViewModel.Instance.StatusBar = statusBar; if (Global.Synchronizer.Network != Network.Main) { MainWindowViewModel.Instance.Title += $" - {Global.Synchronizer.Network}"; } }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance); } catch (Exception ex) { Logger.LogCritical <Program>(ex); throw; } finally { MainWindowViewModel.Instance?.Dispose(); statusBar?.Dispose(); await Global.DisposeAsync(); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; } }
#pragma warning disable IDE1006 // Naming Styles private static async Task Main(string[] args) #pragma warning restore IDE1006 // Naming Styles { StatusBarViewModel statusBar = null; try { MainWindowViewModel.Instance = new MainWindowViewModel(); BuildAvaloniaApp().AfterSetup(async builder => { try { Logger.InitializeDefaults(Path.Combine(Global.DataDir, "Logs.txt")); var configFilePath = Path.Combine(Global.DataDir, "Config.json"); var config = new Config(configFilePath); await config.LoadOrCreateDefaultFileAsync(); Logger.LogInfo <Config>("Config is successfully initialized."); Global.InitializeConfig(config); if (!File.Exists(Global.IndexFilePath)) // Load the index file from working folder if we have it. { var cachedIndexFilePath = Path.Combine("Assets", Path.GetFileName(Global.IndexFilePath)); if (File.Exists(cachedIndexFilePath)) { File.Copy(cachedIndexFilePath, Global.IndexFilePath, overwrite: false); } } Global.InitializeNoWallet(); statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.MemPoolService, Global.IndexDownloader, Global.UpdateChecker); MainWindowViewModel.Instance.StatusBar = statusBar; if (Global.IndexDownloader.Network != Network.Main) { MainWindowViewModel.Instance.Title += $" - {Global.IndexDownloader.Network}"; } } catch (Exception ex) { Logger.LogCritical <Program>(ex); } }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", new DefaultLayoutFactory(), () => MainWindowViewModel.Instance); } catch (Exception ex) { Logger.LogCritical <Program>(ex); } finally { statusBar?.Dispose(); await Global.DisposeAsync(); } }
/// Warning! In Avalonia applications Main must not be async. Otherwise application may not run on OSX. /// see https://github.com/AvaloniaUI/Avalonia/wiki/Unresolved-platform-support-issues private static void Main(string[] args) { bool runGui = false; try { Global = new Global(); Locator.CurrentMutable.RegisterConstant(Global); Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; runGui = CommandInterpreter.ExecuteCommandsAsync(Global, args).GetAwaiter().GetResult(); if (!runGui) { return; } if (Global.InitializeUiConfigAsync().GetAwaiter().GetResult()) { Logger.LogInfo($"{nameof(Global.UiConfig)} is successfully initialized."); } else { Logger.LogError($"Failed to initialize {nameof(Global.UiConfig)}."); return; } Logger.LogSoftwareStarted("Wasabi GUI"); BuildAvaloniaApp().StartShellApp("Wasabi Wallet", AppMainAsync, args); } catch (Exception ex) { Logger.LogCritical(ex); throw; } finally { MainWindowViewModel.Instance?.Dispose(); Global.DisposeAsync().GetAwaiter().GetResult(); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; if (runGui) { Logger.LogSoftwareStopped("Wasabi GUI"); } } }
#pragma warning disable IDE1006 // Naming Styles private static async Task Main(string[] args) #pragma warning restore IDE1006 // Naming Styles { StatusBarViewModel statusBar = null; try { Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui"); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException; if (!await Daemon.RunAsyncReturnTrueIfContinueWithGuiAsync(args)) { return; } BuildAvaloniaApp() .BeforeStarting(async builder => { MainWindowViewModel.Instance = new MainWindowViewModel(); await Global.InitializeNoWalletAsync(); statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.Synchronizer, Global.UpdateChecker); MainWindowViewModel.Instance.StatusBar = statusBar; if (Global.Network != Network.Main) { MainWindowViewModel.Instance.Title += $" - {Global.Network}"; } Dispatcher.UIThread.Post(() => { GC.Collect(); }); }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance); } catch (Exception ex) { Logger.LogCritical <Program>(ex); throw; } finally { statusBar?.Dispose(); await Global.DisposeAsync(); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; Logger.LogInfo($"Wasabi stopped gracefully.", Logger.InstanceGuid.ToString()); } }
#pragma warning disable IDE1006 // Naming Styles private static async Task Main(string[] args) #pragma warning restore IDE1006 // Naming Styles { StatusBarViewModel statusBar = null; try { MainWindowViewModel.Instance = new MainWindowViewModel(); BuildAvaloniaApp().AfterSetup(async builder => { try { Logger.SetFilePath(Path.Combine(Global.DataDir, "Logs.txt")); #if RELEASE Logger.SetMinimumLevel(LogLevel.Info); Logger.SetModes(LogMode.File); #else Logger.SetMinimumLevel(LogLevel.Debug); Logger.SetModes(LogMode.Debug, LogMode.Console, LogMode.File); #endif var configFilePath = Path.Combine(Global.DataDir, "Config.json"); var config = new Config(configFilePath); await config.LoadOrCreateDefaultFileAsync(); Logger.LogInfo <Config>("Config is successfully initialized."); Global.Initialize(config); statusBar = new StatusBarViewModel(Global.Nodes.ConnectedNodes, Global.MemPoolService, Global.IndexDownloader); MainWindowViewModel.Instance.StatusBar = statusBar; } catch (Exception ex) { Logger.LogCritical <Program>(ex); } }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", new DefaultLayoutFactory(), () => MainWindowViewModel.Instance); } catch (Exception ex) { Logger.LogCritical <Program>(ex); } finally { statusBar?.Dispose(); await Global.DisposeAsync(); } }
#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(); Locator.CurrentMutable.RegisterConstant(Global); Platform.BaseDirectory = Path.Combine(Global.DataDir, "Gui"); 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().ConfigureAwait(false); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; if (runGui) { Logger.LogSoftwareStopped("Wasabi GUI"); } } }
#pragma warning disable IDE1006 // Naming Styles private static async Task Main(string[] args) #pragma warning restore IDE1006 // Naming Styles { StatusBarViewModel statusBar = null; 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.LogStarting("Wasabi GUI"); BuildAvaloniaApp() .BeforeStarting(async builder => { MainWindowViewModel.Instance = new MainWindowViewModel(); MainWindowViewModel.Instance.Global = Global; statusBar = new StatusBarViewModel(Global); MainWindowViewModel.Instance.StatusBar = statusBar; await Global.InitializeNoWalletAsync(); statusBar.Initialize(Global.Nodes.ConnectedNodes, Global.Synchronizer, Global.UpdateChecker); if (Global.Network != Network.Main) { MainWindowViewModel.Instance.Title += $" - {Global.Network}"; } Dispatcher.UIThread.Post(() => { GC.Collect(); }); }).StartShellApp <AppBuilder, MainWindow>("Wasabi Wallet", null, () => MainWindowViewModel.Instance); } catch (Exception ex) { Logger.LogCritical <Program>(ex); throw; } finally { statusBar?.Dispose(); await Global.DisposeAsync(); AppDomain.CurrentDomain.UnhandledException -= CurrentDomain_UnhandledException; TaskScheduler.UnobservedTaskException -= TaskScheduler_UnobservedTaskException; if (runGui) { Logger.LogInfo($"Wasabi GUI stopped gracefully.", Logger.InstanceGuid.ToString()); } } }
private async Task ClosingAsync() { bool closeApplication = false; try { if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = true; // indicate -> do not add any more alices to the coinjoin } if (!MainWindowViewModel.Instance.CanClose) { var dialog = new CannotCloseDialogViewModel(); closeApplication = await MainWindowViewModel.Instance.ShowDialogAsync(dialog); // start the deque process with a dialog } else { closeApplication = true; } if (closeApplication) { try { if (Global.UiConfig != null) // UiConfig not yet loaded. { Global.UiConfig.WindowState = WindowState; Global.UiConfig.Width = Width; Global.UiConfig.Height = Height; await Global.UiConfig.ToFileAsync(); Logging.Logger.LogInfo <UiConfig>("UiConfig is saved."); } Hide(); var wm = IoC.Get <IShell>().Documents?.OfType <WalletManagerViewModel>().FirstOrDefault(); if (wm != null) { wm.OnClose(); Logging.Logger.LogInfo <MainWindowViewModel>($"{nameof(WalletManagerViewModel)} closed, hwi enumeration stopped."); } await Global.DisposeAsync(); } catch (Exception ex) { Logging.Logger.LogWarning <MainWindow>(ex); } Interlocked.Exchange(ref _closingState, 2); //now we can close the app Close(); // start the closing process. Will call MainWindow_ClosingAsync again! } //let's go to finally } catch (Exception ex) { Interlocked.Exchange(ref _closingState, 0); //something happened back to starting point Logging.Logger.LogWarning <MainWindow>(ex); } finally { if (!closeApplication) //we are not closing the application for some reason { Interlocked.Exchange(ref _closingState, 0); if (Global.ChaumianClient != null) { Global.ChaumianClient.IsQuitPending = false; //re-enable enqueuing coins } } } }