diff --git a/DeFRaG_Helper/App.xaml.cs b/DeFRaG_Helper/App.xaml.cs index 0073489..e4ee408 100644 --- a/DeFRaG_Helper/App.xaml.cs +++ b/DeFRaG_Helper/App.xaml.cs @@ -13,20 +13,30 @@ protected override void OnStartup(StartupEventArgs e) base.OnStartup(e); // Initialize logging MessageHelper.Log("Application starting"); - LoadConfigurationAndStartAsync().ContinueWith(_ => + LoadConfigurationAndStartAsync().ContinueWith(task => { - // This ensures the continuation runs on the UI thread - Dispatcher.Invoke(() => + if (task.IsFaulted) { - // Now that configuration and resources are loaded, show the main window - MessageHelper.Log("Main window created"); - MainWindow mainWindow = new MainWindow(); - mainWindow.Show(); - }); - }); + // Log the error or show an error message to the user + MessageHelper.Log($"Error during startup: {task.Exception}"); + // Optionally, close the application if critical startup tasks fail + Dispatcher.Invoke(() => Current.Shutdown()); + } + else + { + // This ensures the continuation runs on the UI thread + Dispatcher.Invoke(() => + { + // Now that configuration and resources are loaded, show the main window + MessageHelper.Log("Main window created"); + MainWindow mainWindow = new MainWindow(); + mainWindow.Show(); + }); + } + }); StartDelayedTasks(); - } + private async void StartDelayedTasks() { // Wait for 1 minute after the application starts @@ -51,12 +61,16 @@ private async Task LoadConfigurationAndStartAsync() ApplyThemeColor(); // Create an instance of MapHistoryManager + + + await AppConfig.EnsureDatabaseExistsAsync(); + MessageHelper.Log("Database exists"); + MessageHelper.Log("Creating MapHistoryManager"); var mapHistoryManager = MapHistoryManager.GetInstance("DeFRaG_Helper"); MessageHelper.Log("MapHistoryManager created"); - await AppConfig.EnsureDatabaseExistsAsync(); - MessageHelper.Log("Database exists"); + // The main window creation and showing is moved to the continuation of this method in OnStartup } private void ApplyThemeColor() diff --git a/DeFRaG_Helper/AssemblyInfo.cs b/DeFRaG_Helper/AssemblyInfo.cs index b0ec827..22fc591 100644 --- a/DeFRaG_Helper/AssemblyInfo.cs +++ b/DeFRaG_Helper/AssemblyInfo.cs @@ -1,3 +1,4 @@ +using System.Reflection; using System.Windows; [assembly: ThemeInfo( diff --git a/DeFRaG_Helper/DeFRaG_Helper.csproj b/DeFRaG_Helper/DeFRaG_Helper.csproj index 2d3e613..166fc49 100644 --- a/DeFRaG_Helper/DeFRaG_Helper.csproj +++ b/DeFRaG_Helper/DeFRaG_Helper.csproj @@ -7,6 +7,8 @@ enable true Quake3.ico + 1.0.0 + 1.0.0 diff --git a/DeFRaG_Helper/Helpers/Downloader.cs b/DeFRaG_Helper/Helpers/Downloader.cs index 72377de..630a25f 100644 --- a/DeFRaG_Helper/Helpers/Downloader.cs +++ b/DeFRaG_Helper/Helpers/Downloader.cs @@ -7,7 +7,6 @@ namespace DeFRaG_Helper { public static class Downloader { - private static readonly HttpClient httpClient = CreateHttpClient(); private static HttpClient CreateHttpClient() diff --git a/DeFRaG_Helper/MainWindow.xaml b/DeFRaG_Helper/MainWindow.xaml index c44c9d7..8707b48 100644 --- a/DeFRaG_Helper/MainWindow.xaml +++ b/DeFRaG_Helper/MainWindow.xaml @@ -32,7 +32,7 @@ -