Error handling, better path remembrance
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using FileTime.App.Core.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
@@ -6,18 +7,30 @@ public class LifecycleService
|
||||
{
|
||||
private readonly IEnumerable<IExitHandler> _exitHandlers;
|
||||
private readonly IEnumerable<IStartupHandler> _startupHandlers;
|
||||
private readonly ILogger<LifecycleService> _logger;
|
||||
|
||||
public LifecycleService(IEnumerable<IStartupHandler> startupHandlers, IEnumerable<IExitHandler> exitHandlers)
|
||||
public LifecycleService(
|
||||
IEnumerable<IStartupHandler> startupHandlers,
|
||||
IEnumerable<IExitHandler> exitHandlers,
|
||||
ILogger<LifecycleService> logger)
|
||||
{
|
||||
_exitHandlers = exitHandlers;
|
||||
_startupHandlers = startupHandlers;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public async Task InitStartupHandlersAsync()
|
||||
{
|
||||
foreach (var startupHandler in _startupHandlers)
|
||||
{
|
||||
await startupHandler.InitAsync();
|
||||
try
|
||||
{
|
||||
await startupHandler.InitAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while running startup handler {handler}", startupHandler?.GetType().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +38,14 @@ public class LifecycleService
|
||||
{
|
||||
foreach (var exitHandler in _exitHandlers)
|
||||
{
|
||||
await exitHandler.ExitAsync();
|
||||
try
|
||||
{
|
||||
await exitHandler.ExitAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while running exit handler {handler}", exitHandler?.GetType().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,17 +49,7 @@ public partial class MainWindowViewModel : IMainWindowViewModelBase
|
||||
|
||||
Title = "FileTime " + versionString;
|
||||
|
||||
//TODO: refactor
|
||||
/*if (AppState.Tabs.Count == 0)
|
||||
{
|
||||
var tab = _serviceProvider.GetInitableResolver<IContainer>(_localContentProvider)
|
||||
.GetRequiredService<ITab>();
|
||||
var tabViewModel = _serviceProvider.GetInitableResolver(tab, 1).GetRequiredService<ITabViewModel>();
|
||||
|
||||
_appState.AddTab(tabViewModel);
|
||||
}*/
|
||||
|
||||
_lifecycleService.InitStartupHandlersAsync().Wait();
|
||||
Task.Run(async () => await _lifecycleService.InitStartupHandlersAsync()).Wait();
|
||||
}
|
||||
|
||||
public void ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
|
||||
|
||||
Reference in New Issue
Block a user