Handle refresh request
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using System.Reactive.Linq;
|
||||
using FileTime.App.Core.UserCommand;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
|
||||
namespace FileTime.App.Core.Services;
|
||||
|
||||
public class ContainerRefreshHandler : IStartupHandler, IDisposable
|
||||
{
|
||||
private readonly List<IDisposable> _refreshSubscriptions = new();
|
||||
private List<FullName> _folders = new();
|
||||
|
||||
public ContainerRefreshHandler(
|
||||
ICommandScheduler commandScheduler,
|
||||
IUserCommandHandlerService userCommandHandlerService,
|
||||
IAppState appState
|
||||
)
|
||||
{
|
||||
_refreshSubscriptions.Add(
|
||||
Observable.CombineLatest(
|
||||
appState.SelectedTab.Select(t => t?.CurrentLocation.Select(l => l?.FullName) ?? Observable.Never<FullName>()).Switch(),
|
||||
appState.SelectedTab.Select(t => t?.CurrentLocation.Select(l => l?.Parent?.Path) ?? Observable.Never<FullName>()).Switch(),
|
||||
appState.SelectedTab.Select(t => t?.CurrentSelectedItem.Select(l => l?.BaseItem?.FullName) ?? Observable.Never<FullName>()).Switch(),
|
||||
(a, b, c) => new[] {a, b, c}
|
||||
).Subscribe(folders => { _folders = folders.Where(f => f is not null).Cast<FullName>().ToList(); })
|
||||
);
|
||||
|
||||
|
||||
_refreshSubscriptions.Add(
|
||||
commandScheduler.ContainerToRefresh.Subscribe(refreshRequestedIn =>
|
||||
{
|
||||
if (_folders.Contains(refreshRequestedIn))
|
||||
{
|
||||
userCommandHandlerService.HandleCommandAsync(RefreshCommand.Instance);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var refreshSubscription in _refreshSubscriptions)
|
||||
{
|
||||
refreshSubscription.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
public Task InitAsync() => Task.CompletedTask;
|
||||
}
|
||||
@@ -26,7 +26,8 @@ public static class Startup
|
||||
|
||||
return serviceCollection
|
||||
.AddCommandHandlers()
|
||||
.AddSingleton<IStartupHandler, DefaultIdentifiableCommandHandlerRegister>();
|
||||
.AddSingleton<IStartupHandler, DefaultIdentifiableCommandHandlerRegister>()
|
||||
.AddSingleton<IStartupHandler, ContainerRefreshHandler>();
|
||||
}
|
||||
|
||||
private static IServiceCollection AddCommandHandlers(this IServiceCollection serviceCollection)
|
||||
|
||||
@@ -28,6 +28,8 @@ public class CopyStrategy : ICopyStrategy
|
||||
{
|
||||
await _copy(from, to, context);
|
||||
context.CurrentProgress?.SetProgress(context.CurrentProgress.TotalCount);
|
||||
if (to.Path.GetParent() is { } parent)
|
||||
await _copyStrategyParam.RefreshContainerAsync(parent);
|
||||
}
|
||||
|
||||
public Task CreateContainerAsync(IContainer target, string name, PointInTime currentTime)
|
||||
|
||||
@@ -22,7 +22,7 @@ public class CommandScheduler : ICommandScheduler
|
||||
{
|
||||
get
|
||||
{
|
||||
bool result = true;
|
||||
var result = true;
|
||||
RunWithLock(() => result = _enableRunning);
|
||||
return result;
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class CommandScheduler : ICommandScheduler
|
||||
public CommandScheduler(ILocalCommandExecutor localExecutor)
|
||||
{
|
||||
ContainerToRefresh = _containerToRefresh.AsObservable();
|
||||
|
||||
|
||||
localExecutor.CommandFinished += LocalExecutorOnCommandFinished;
|
||||
_commandExecutors.Add(localExecutor);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public class LifecycleService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while running startup handler {handler}", startupHandler?.GetType().FullName);
|
||||
_logger.LogError(ex, "Error while running startup handler {Handler}", startupHandler?.GetType().FullName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,8 +44,19 @@ public class LifecycleService
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error while running exit handler {handler}", exitHandler?.GetType().FullName);
|
||||
_logger.LogError(ex, "Error while running exit handler {Handler}", exitHandler?.GetType().FullName);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var disposable in
|
||||
_startupHandlers
|
||||
.OfType<IDisposable>()
|
||||
.Concat(
|
||||
_exitHandlers.OfType<IDisposable>()
|
||||
)
|
||||
)
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user