diff --git a/src/Files.App/Services/Windows/WindowsJumpListService.cs b/src/Files.App/Services/Windows/WindowsJumpListService.cs index 5c1c8b9d1abb..572718c619d1 100644 --- a/src/Files.App/Services/Windows/WindowsJumpListService.cs +++ b/src/Files.App/Services/Windows/WindowsJumpListService.cs @@ -79,7 +79,8 @@ public async Task RefreshPinnedFoldersAsync() { try { - App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; + if (App.QuickAccessManager.PinnedItemsWatcher is not null) + App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; if (JumpList.IsSupported()) { @@ -101,7 +102,8 @@ public async Task RefreshPinnedFoldersAsync() } finally { - SafetyExtensions.IgnoreExceptions(() => App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true); + if (App.QuickAccessManager.PinnedItemsWatcher is not null) + SafetyExtensions.IgnoreExceptions(() => App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true); } } diff --git a/src/Files.App/Services/Windows/WindowsQuickAccessService.cs b/src/Files.App/Services/Windows/WindowsQuickAccessService.cs index b060f123a4d0..5273ce93b0da 100644 --- a/src/Files.App/Services/Windows/WindowsQuickAccessService.cs +++ b/src/Files.App/Services/Windows/WindowsQuickAccessService.cs @@ -95,13 +95,15 @@ public async Task SaveAsync(string[] items) if (Equals(items, App.QuickAccessManager.Model.PinnedFolders.ToArray())) return; - App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; + if (App.QuickAccessManager.PinnedItemsWatcher is not null) + App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = false; // Unpin every item that is below this index and then pin them all in order await UnpinFromSidebarAsync([], false); await PinToSidebarAsync(items, false); - App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true; + if (App.QuickAccessManager.PinnedItemsWatcher is not null) + App.QuickAccessManager.PinnedItemsWatcher.EnableRaisingEvents = true; App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, new ModifyQuickAccessEventArgs(items, true) { diff --git a/src/Files.App/Utils/Global/QuickAccessManager.cs b/src/Files.App/Utils/Global/QuickAccessManager.cs index 5971690c42b5..6b2b1de36bd6 100644 --- a/src/Files.App/Utils/Global/QuickAccessManager.cs +++ b/src/Files.App/Utils/Global/QuickAccessManager.cs @@ -25,14 +25,27 @@ public QuickAccessManager() public void Initialize() { - PinnedItemsWatcher = new() + var automaticDestinationsPath = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Recent", "AutomaticDestinations"); + + // Only initialize FileSystemWatcher if the directory exists + // This handles cases where AppData is redirected to network locations that don't contain Windows system directories + if (Directory.Exists(automaticDestinationsPath)) { - Path = Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Microsoft", "Windows", "Recent", "AutomaticDestinations"), - Filter = "f01b4d95cf55d32a.automaticDestinations-ms", - NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName - }; - - PinnedItemsWatcher.Changed += PinnedItemsWatcher_Changed; + PinnedItemsWatcher = new() + { + Path = automaticDestinationsPath, + Filter = "f01b4d95cf55d32a.automaticDestinations-ms", + NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName + }; + + PinnedItemsWatcher.Changed += PinnedItemsWatcher_Changed; + } + else + { + // If the directory doesn't exist (e.g., redirected AppData), skip FileSystemWatcher initialization + // The app will still function, but won't receive automatic updates when pinned items change externally + PinnedItemsWatcher = null; + } } private void PinnedItemsWatcher_Changed(object sender, FileSystemEventArgs e)