Tab restore

This commit is contained in:
2022-05-24 17:02:36 +02:00
parent dcff003c28
commit 8167909781
16 changed files with 339 additions and 11 deletions

View File

@@ -35,13 +35,14 @@ public static class Startup
serviceCollection.TryAddSingleton<IDefaultModeKeyInputHandler, DefaultModeKeyInputHandler>();
serviceCollection.TryAddSingleton<IKeyboardConfigurationService, KeyboardConfigurationService>();
serviceCollection.TryAddSingleton<IRapidTravelModeKeyInputHandler, RapidTravelModeKeyInputHandler>();
serviceCollection.TryAddSingleton<IStartupHandler, RootDriveInfoService>();
serviceCollection.TryAddSingleton<LifecycleService>();
serviceCollection.TryAddSingleton<IIconProvider, MaterialIconProvider>();
serviceCollection.TryAddSingleton<IModalService, ModalService>();
serviceCollection.TryAddSingleton<IDialogService, DialogService>();
serviceCollection.TryAddSingleton<IInputInterface>(s => s.GetRequiredService<IDialogService>());
return serviceCollection;
return serviceCollection
.AddSingleton<IStartupHandler, RootDriveInfoService>();
}
internal static IServiceCollection RegisterLogging(this IServiceCollection serviceCollection)

View File

@@ -5,13 +5,23 @@ namespace FileTime.GuiApp.Services;
public class LifecycleService
{
private readonly IEnumerable<IExitHandler> _exitHandlers;
private readonly IEnumerable<IStartupHandler> _startupHandlers;
public LifecycleService(IEnumerable<IStartupHandler> startupHandlers, IEnumerable<IExitHandler> exitHandlers)
{
_exitHandlers = exitHandlers;
_startupHandlers = startupHandlers;
}
public async Task Exit()
public async Task InitStartupHandlersAsync()
{
foreach (var startupHandler in _startupHandlers)
{
await startupHandler.InitAsync();
}
}
public async Task ExitAsync()
{
foreach (var exitHandler in _exitHandlers)
{

View File

@@ -38,7 +38,7 @@ public class RootDriveInfoService : IStartupHandler
{
var containerPath = localContentProvider.GetNativePath(i.Path).Path;
var drivePath = d.Name.TrimEnd(Path.DirectorySeparatorChar);
return containerPath == drivePath
return containerPath == drivePath
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && containerPath == "/" && d.Name == "/");
})))
.Filter(t => t.Drive is not null);
@@ -68,4 +68,6 @@ public class RootDriveInfoService : IStartupHandler
_rootDrives.AddRange(drives);
}
}
public Task InitAsync() => Task.CompletedTask;
}

View File

@@ -50,14 +50,16 @@ public partial class MainWindowViewModel : IMainWindowViewModelBase
Title = "FileTime " + versionString;
//TODO: refactor
if (AppState.Tabs.Count == 0)
/*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();
}
public void ProcessKeyDown(Key key, KeyModifiers keyModifiers, Action<bool> setHandled)
@@ -72,4 +74,9 @@ public partial class MainWindowViewModel : IMainWindowViewModelBase
await UserCommandHandlerService.HandleCommandAsync(
new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, resolvedContainer)));
}
public async Task OnExit()
{
await _lifecycleService.ExitAsync();
}
}

View File

@@ -22,6 +22,7 @@
Icon="/Assets/filetime.ico"
InputElement.KeyDown="OnKeyDown"
Opened="OnWindowOpened"
Closed="OnWindowClosed"
TransparencyLevelHint="Blur"
mc:Ignorable="d">

View File

@@ -82,7 +82,7 @@ public partial class MainWindow : Window
&& sender is StyledElement control)
{
FullName? path = null;
if (control.DataContext is IHaveFullPath { Path: { } } hasFullPath)
if (control.DataContext is IHaveFullPath {Path: { }} hasFullPath)
{
path = hasFullPath.Path;
}
@@ -108,4 +108,10 @@ public partial class MainWindow : Window
e.Handled = true;
}
}
private void OnWindowClosed(object? sender, EventArgs e)
{
var vm = ViewModel;
Task.Run(() => vm?.OnExit()).Wait();
}
}