Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/Files.App/Services/Windows/WindowsRecentItemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using Microsoft.Extensions.Logging;
using System.Collections.Specialized;
using System.IO;
using System.Text;
using Windows.Win32;
using Windows.Win32.Foundation;
Expand Down Expand Up @@ -59,16 +60,23 @@ public IReadOnlyList<RecentItem> RecentFolders

public WindowsRecentItemsService()
{
_watcher = new()
var automaticDestinationsPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Recent), "AutomaticDestinations");

// Only create the file system watcher if the AutomaticDestinations directory exists
if (Directory.Exists(automaticDestinationsPath))
{
Path = SystemIO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Recent), "AutomaticDestinations"),
Filter = "5f7b5f1e01b83767.automaticDestinations-ms",
NotifyFilter = SystemIO.NotifyFilters.DirectoryName | SystemIO.NotifyFilters.FileName | SystemIO.NotifyFilters.LastWrite,
};

_watcher.Changed += Watcher_Changed;
_watcher.Deleted += Watcher_Changed;
_watcher.EnableRaisingEvents = true;
_watcher = new()
{
Path = automaticDestinationsPath,
Filter = "5f7b5f1e01b83767.automaticDestinations-ms",
NotifyFilter = SystemIO.NotifyFilters.DirectoryName | SystemIO.NotifyFilters.FileName | SystemIO.NotifyFilters.LastWrite,
};

_watcher.Changed += Watcher_Changed;
_watcher.Deleted += Watcher_Changed;
_watcher.EnableRaisingEvents = true;
}
// If the directory doesn't exist, _watcher remains null and the service will function without file system monitoring
}

// Methods
Expand Down
Loading