Places (Windows only currently)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
using System.Runtime.InteropServices;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using Syroot.Windows.IO;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class PlacesService : IStartupHandler
|
||||
{
|
||||
private readonly ILocalContentProvider _localContentProvider;
|
||||
private readonly IGuiAppState _guiAppState;
|
||||
|
||||
public PlacesService(
|
||||
ILocalContentProvider localContentProvider,
|
||||
IGuiAppState guiAppState)
|
||||
{
|
||||
_localContentProvider = localContentProvider;
|
||||
_guiAppState = guiAppState;
|
||||
}
|
||||
|
||||
public async Task InitAsync()
|
||||
{
|
||||
var places = new List<PlaceInfo>();
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
var placesFolders = new List<KnownFolder>()
|
||||
{
|
||||
KnownFolders.Profile,
|
||||
KnownFolders.Desktop,
|
||||
KnownFolders.DocumentsLocalized,
|
||||
KnownFolders.DownloadsLocalized,
|
||||
KnownFolders.Music,
|
||||
KnownFolders.Pictures,
|
||||
KnownFolders.Videos,
|
||||
};
|
||||
|
||||
foreach (var placesFolder in placesFolders)
|
||||
{
|
||||
var possibleContainer = await _localContentProvider.GetItemByNativePathAsync(new NativePath(placesFolder.Path), PointInTime.Present);
|
||||
if (possibleContainer is not IContainer container) continue;
|
||||
|
||||
|
||||
places.Add(new PlaceInfo(container, placesFolder.DisplayName));
|
||||
}
|
||||
}
|
||||
|
||||
_guiAppState.Places = places.AsReadOnly();
|
||||
}
|
||||
}
|
||||
@@ -8,23 +8,23 @@ using FileTime.Core.Models;
|
||||
using FileTime.Core.Timeline;
|
||||
using FileTime.GuiApp.ViewModels;
|
||||
using FileTime.Providers.Local;
|
||||
using IContainer = FileTime.Core.Models.IContainer;
|
||||
|
||||
namespace FileTime.GuiApp.Services;
|
||||
|
||||
public class RootDriveInfoService : IStartupHandler
|
||||
{
|
||||
private readonly SourceList<DriveInfo> _rootDrives = new();
|
||||
private readonly IObservable<IChangeSet<AbsolutePath, string>> _localContentProviderStream;
|
||||
|
||||
public RootDriveInfoService(IGuiAppState guiAppState, ILocalContentProvider localContentProvider,
|
||||
public RootDriveInfoService(
|
||||
IGuiAppState guiAppState,
|
||||
ILocalContentProvider localContentProvider,
|
||||
ITimelessContentProvider timelessContentProvider)
|
||||
{
|
||||
InitRootDrives();
|
||||
|
||||
var localContentProviderAsList = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
|
||||
localContentProviderAsList.AddOrUpdate(new AbsolutePath(timelessContentProvider, localContentProvider));
|
||||
_localContentProviderStream = localContentProviderAsList.Connect();
|
||||
var localContentProviderStream = localContentProviderAsList.Connect();
|
||||
|
||||
var rootDriveInfos = Observable.CombineLatest(
|
||||
localContentProvider.Items,
|
||||
@@ -34,7 +34,7 @@ public class RootDriveInfoService : IStartupHandler
|
||||
return items is null
|
||||
? Observable.Empty<IChangeSet<(AbsolutePath Path, DriveInfo? Drive), string>>()
|
||||
: items!
|
||||
.Or(new[] { _localContentProviderStream })
|
||||
.Or(new[] { localContentProviderStream })
|
||||
.Transform(i => (Path: i, Drive: drives.FirstOrDefault(d =>
|
||||
{
|
||||
var containerPath = localContentProvider.GetNativePath(i.Path).Path;
|
||||
|
||||
Reference in New Issue
Block a user