Skip to content

Commit c57914d

Browse files
committed
Notify jump list update to the sidebar
1 parent 07e31fa commit c57914d

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

src/Files.App.Storage/Windows/Managers/JumpListManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ public unsafe class JumpListManager : IDisposable
3030

3131
private readonly Lock _updateJumpListLock = new();
3232

33-
public static event EventHandler? ExplorerJumpListChanged;
34-
public static event EventHandler? FilesJumpListChanged;
33+
public static event EventHandler? JumpListChanged;
3534

3635
private JumpListManager() { }
3736

@@ -385,6 +384,7 @@ private void ExplorerJumpListWatcher_Changed(object sender, FileSystemEventArgs
385384
{
386385
Debug.WriteLine("in: ExplorerJumpListWatcher_Changed");
387386
PullJumpListFromExplorer();
387+
JumpListChanged?.Invoke(this, EventArgs.Empty);
388388
Debug.WriteLine("out: ExplorerJumpListWatcher_Changed");
389389
}
390390
finally
@@ -406,6 +406,7 @@ private void FilesJumpListWatcher_Changed(object sender, FileSystemEventArgs e)
406406
{
407407
Debug.WriteLine("in: FilesJumpListWatcher_Changed");
408408
PushJumpListToExplorer();
409+
JumpListChanged?.Invoke(this, EventArgs.Empty);
409410
Debug.WriteLine("out: FilesJumpListWatcher_Changed");
410411
}
411412
finally

src/Files.App/Data/Contracts/IQuickAccessService.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,15 @@ public interface IQuickAccessService
5252
/// <param name="items">The array of items to save</param>
5353
/// <returns></returns>
5454
Task SaveAsync(string[] items);
55+
56+
/// <summary>
57+
/// Notifies listeners that the collection of pinned items has changed.
58+
/// </summary>
59+
/// <remarks>Call this method when the set of pinned items is modified to ensure that any UI components or
60+
/// services reflecting pinned items remain in sync. If doUpdateQuickAccessWidget is set to true, the quick access
61+
/// widget will be refreshed to display the latest pinned items.</remarks>
62+
/// <param name="doUpdateQuickAccessWidget">true to update the quick access widget after notifying the change; otherwise, false.</param>
63+
/// <returns>A task that represents the asynchronous notification operation.</returns>
64+
Task NotifyPinnedItemsChanged(bool doUpdateQuickAccessWidget);
5565
}
5666
}

src/Files.App/Helpers/Application/AppLifecycleHelper.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,11 @@ await Task.WhenAll(
170170
if (hr.Failed) App.Logger.LogWarning("Failed to synchronize jump list unexpectedly.");
171171

172172
bool result = JumpListManager.WatchJumpListChanges(AppUserModelIdCrcHash);
173-
if (!result) App.Logger.LogWarning("Failed to watch jump list unexpectedly.");
173+
if (result)
174+
{
175+
// TODO: Remove this after the sidebar refactoring (this has to be self-notified in the sidebar)
176+
JumpListManager.JumpListChanged += JumpListManager_JumpListChanged;
177+
}
174178
}
175179
},
176180
App.Logger);
@@ -455,6 +459,17 @@ public static void HandleAppUnhandledException(Exception? ex, bool showToastNoti
455459
Process.GetCurrentProcess().Kill();
456460
}
457461

462+
/// <summary>
463+
/// Handles the event that occurs when the files jump list changes, and notifies the quick access service of updates
464+
/// to pinned items.
465+
/// </summary>
466+
private static void JumpListManager_JumpListChanged(object? sender, EventArgs e)
467+
{
468+
var quickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();
469+
470+
quickAccessService.NotifyPinnedItemsChanged(true);
471+
}
472+
458473
/// <summary>
459474
/// Updates the visibility of the system tray icon
460475
/// </summary>

src/Files.App/Services/Windows/WindowsQuickAccessService.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,12 @@ public async Task SaveAsync(string[] items)
110110
Reorder = true
111111
});
112112
}
113+
114+
public async Task NotifyPinnedItemsChanged(bool doUpdateQuickAccessWidget)
115+
{
116+
await App.QuickAccessManager.Model.LoadAsync();
117+
if (doUpdateQuickAccessWidget)
118+
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, null!);
119+
}
113120
}
114121
}

0 commit comments

Comments
 (0)