1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-31 01:42:02 +00:00

UI - Try to die a bit more gracefully

This commit is contained in:
RobertBeekman 2024-03-10 22:07:04 +01:00
parent 1cbf6587a1
commit d7c776323c

View File

@ -19,6 +19,7 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Threading; using Avalonia.Threading;
using ReactiveUI; using ReactiveUI;
using Serilog;
namespace Artemis.UI.Screens.Root; namespace Artemis.UI.Screens.Root;
@ -28,13 +29,15 @@ public class RootViewModel : RoutableHostScreen<RoutableScreen>, IMainWindowProv
private readonly IDebugService _debugService; private readonly IDebugService _debugService;
private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel; private readonly DefaultTitleBarViewModel _defaultTitleBarViewModel;
private readonly IClassicDesktopStyleApplicationLifetime _lifeTime; private readonly IClassicDesktopStyleApplicationLifetime _lifeTime;
private readonly ILogger _logger;
private readonly IRouter _router; private readonly IRouter _router;
private readonly ISettingsService _settingsService; private readonly ISettingsService _settingsService;
private readonly IUpdateService _updateService; private readonly IUpdateService _updateService;
private readonly IWindowService _windowService; private readonly IWindowService _windowService;
private readonly ObservableAsPropertyHelper<ViewModelBase?> _titleBarViewModel; private readonly ObservableAsPropertyHelper<ViewModelBase?> _titleBarViewModel;
public RootViewModel(IRouter router, public RootViewModel(ILogger logger,
IRouter router,
ICoreService coreService, ICoreService coreService,
ISettingsService settingsService, ISettingsService settingsService,
IRegistrationService registrationService, IRegistrationService registrationService,
@ -50,6 +53,7 @@ public class RootViewModel : RoutableHostScreen<RoutableScreen>, IMainWindowProv
WindowSizeSetting = settingsService.GetSetting<WindowSize?>("WindowSize"); WindowSizeSetting = settingsService.GetSetting<WindowSize?>("WindowSize");
SidebarViewModel = sidebarViewModel; SidebarViewModel = sidebarViewModel;
_logger = logger;
_router = router; _router = router;
_coreService = coreService; _coreService = coreService;
_settingsService = settingsService; _settingsService = settingsService;
@ -81,19 +85,27 @@ public class RootViewModel : RoutableHostScreen<RoutableScreen>, IMainWindowProv
Task.Run(() => Task.Run(() =>
{ {
// Before doing heavy lifting, initialize the update service which may prompt a restart try
// Only initialize with an update check if we're not going to show the UI {
if (_updateService.Initialize(!ShouldShowUI())) // Before doing heavy lifting, initialize the update service which may prompt a restart
return; // Only initialize with an update check if we're not going to show the UI
if (_updateService.Initialize(!ShouldShowUI()))
return;
// Workshop service goes first so it has a chance to clean up old workshop entries and introduce new ones // Workshop service goes first so it has a chance to clean up old workshop entries and introduce new ones
workshopService.Initialize(); workshopService.Initialize();
// Core is initialized now that everything is ready to go // Core is initialized now that everything is ready to go
coreService.Initialize(); coreService.Initialize();
registrationService.RegisterBuiltInDataModelDisplays(); registrationService.RegisterBuiltInDataModelDisplays();
registrationService.RegisterBuiltInDataModelInputs(); registrationService.RegisterBuiltInDataModelInputs();
registrationService.RegisterBuiltInPropertyEditors(); registrationService.RegisterBuiltInPropertyEditors();
}
catch (Exception e)
{
_logger.Fatal(e, "Error during initialization");
_windowService.ShowExceptionDialog("Fatal error occured during initialization", e);
}
}); });
} }