Contaienr size scan WIP

This commit is contained in:
2023-08-02 08:25:19 +02:00
parent c95be170ed
commit 1713973c3a
35 changed files with 760 additions and 125 deletions

View File

@@ -0,0 +1,26 @@
using FileTime.App.Core.ViewModels.ItemPreview;
using FileTime.Core.Models;
using InitableService;
namespace FileTime.App.Core.Services;
public class ElementPreviewProvider : IItemPreviewProvider
{
private readonly IServiceProvider _serviceProvider;
public ElementPreviewProvider(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public bool CanHandle(IItem item) => item is IElement;
public async Task<IItemPreviewViewModel> CreatePreviewAsync(IItem item)
{
if (item is not IElement element) throw new NotSupportedException();
return await _serviceProvider
.GetAsyncInitableResolver(element)
.GetRequiredServiceAsync<ElementPreviewViewModel>();
}
}

View File

@@ -9,14 +9,21 @@ namespace FileTime.App.Core.Services;
public class ItemPreviewService : IItemPreviewService
{
private readonly IServiceProvider _serviceProvider;
private readonly IEnumerable<IItemPreviewProvider> _itemPreviewProviders;
public IObservable<IItemPreviewViewModel?> ItemPreview { get; }
public ItemPreviewService(IAppState appState, IServiceProvider serviceProvider)
public ItemPreviewService(
IAppState appState,
IServiceProvider serviceProvider,
IEnumerable<IItemPreviewProvider> itemPreviewProviders)
{
_serviceProvider = serviceProvider;
_itemPreviewProviders = itemPreviewProviders;
ItemPreview = appState
.SelectedTab
.Select(t => t?.CurrentSelectedItem.Throttle(TimeSpan.FromMilliseconds(250)) ?? Observable.Return<IItemViewModel?>(null))
.Select(t =>
t?.CurrentSelectedItem.Throttle(TimeSpan.FromMilliseconds(250))
?? Observable.Return<IItemViewModel?>(null))
.Switch()
.Select(item =>
item == null
@@ -30,11 +37,12 @@ public class ItemPreviewService : IItemPreviewService
private async Task<IItemPreviewViewModel?> Map(IItemViewModel itemViewModel)
{
return itemViewModel.BaseItem switch
{
IElement element => await _serviceProvider.GetAsyncInitableResolver(element)
.GetRequiredServiceAsync<ElementPreviewViewModel>(),
_ => null
};
ArgumentNullException.ThrowIfNull(itemViewModel.BaseItem);
var itemPreviewProvider = _itemPreviewProviders.FirstOrDefault(p => p.CanHandle(itemViewModel.BaseItem));
return itemPreviewProvider is null
? null
: await itemPreviewProvider.CreatePreviewAsync(itemViewModel.BaseItem);
}
}

View File

@@ -18,7 +18,8 @@ public class TabPersistenceService : ITabPersistenceService
//TODO: make this a configuration maybe?
private readonly List<string> _contentProvidersNotToRestore = new()
{
"search"
"search",
"container-size-scan"
};
private record PersistenceRoot(TabStates? TabStates);

View File

@@ -1,8 +1,10 @@
using System.Diagnostics;
using DeclarativeProperty;
using FileTime.App.ContainerSizeScanner;
using FileTime.App.Core.UserCommand;
using FileTime.App.Core.ViewModels;
using FileTime.App.Search;
using FileTime.Core.Command;
using FileTime.Core.ContentAccess;
using FileTime.Core.Enums;
using FileTime.Core.Interactions;
@@ -20,6 +22,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
private readonly ITimelessContentProvider _timelessContentProvider;
private readonly IUserCommandHandlerService _userCommandHandlerService;
private readonly IContentAccessorFactory _contentAccessorFactory;
private readonly IContainerScanSnapshotProvider _containerScanSnapshotProvider;
private IDeclarativeProperty<IContainer?>? _currentLocation;
private IDeclarativeProperty<IItemViewModel?>? _currentSelectedItem;
private ITabViewModel? _currentSelectedTab;
@@ -32,7 +35,8 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
IItemNameConverterService itemNameConverterService,
ITimelessContentProvider timelessContentProvider,
IUserCommandHandlerService userCommandHandlerService,
IContentAccessorFactory contentAccessorFactory) : base(appState)
IContentAccessorFactory contentAccessorFactory,
IContainerScanSnapshotProvider containerScanSnapshotProvider) : base(appState)
{
_systemClipboardService = systemClipboardService;
_userCommunicationService = userCommunicationService;
@@ -41,6 +45,7 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
_timelessContentProvider = timelessContentProvider;
_userCommandHandlerService = userCommandHandlerService;
_contentAccessorFactory = contentAccessorFactory;
_containerScanSnapshotProvider = containerScanSnapshotProvider;
SaveCurrentLocation(l => _currentLocation = l);
SaveCurrentSelectedItem(i => _currentSelectedItem = i);
SaveSelectedTab(t => _currentSelectedTab = t);
@@ -51,10 +56,20 @@ public class ToolUserCommandHandlerService : UserCommandHandlerServiceBase
new TypeUserCommandHandler<CopyNativePathCommand>(CopyNativePath),
new TypeUserCommandHandler<CopyBase64Command>(CopyBase64),
new TypeUserCommandHandler<SearchCommand>(Search),
new TypeUserCommandHandler<ScanSizeCommand>(ScanSize),
new TypeUserCommandHandler<SortItemsCommand>(SortItems),
});
}
private async Task ScanSize()
{
if (_currentLocation?.Value is null) return;
var searchTask = _containerScanSnapshotProvider.StartSizeScan(_currentLocation.Value);
var openContainerCommand = new OpenContainerCommand(new AbsolutePath(_timelessContentProvider, searchTask.SizeContainer));
await _userCommandHandlerService.HandleCommandAsync(openContainerCommand);
}
private async Task SortItems(SortItemsCommand sortItemsCommand)
{
if (_currentSelectedTab is null) return;