Skip to content

Commit 1e64430

Browse files
committed
Notify to the pin manager
1 parent 1bddc4b commit 1e64430

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

src/Files.App.CsWin32/ManualPInvokes.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public static void PropVariantInit(PROPVARIANT* pvar)
4848
NativeMemory.Fill(pvar, (uint)(sizeof(PROPVARIANT)), 0);
4949
}
5050

51-
public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, nint dwNewLong)
51+
public static nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nIndex, nint dwNewLong)
5252
{
5353
// NOTE:
5454
// Since CsWin32 generates SetWindowLong only on x86 and SetWindowLongPtr only on x64,
@@ -65,7 +65,7 @@ public static unsafe nint SetWindowLongPtr(HWND hWnd, WINDOW_LONG_PTR_INDEX nInd
6565
static extern nint _SetWindowLongPtr(HWND hWnd, int nIndex, nint dwNewLong);
6666
}
6767

68-
[LibraryImport("Shell32.dll", EntryPoint = "SHUpdateRecycleBinIcon")]
68+
[LibraryImport("shell32.dll", EntryPoint = "SHUpdateRecycleBinIcon", SetLastError = true)]
6969
public static partial void SHUpdateRecycleBinIcon();
7070
}
7171
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public unsafe class JumpListManager : IDisposable
3131
private FileSystemWatcher? _filesADLStoreFileWatcher;
3232
private FileSystemWatcher? _filesCDLStoreFileWatcher;
3333

34-
public static event EventHandler? ExplorerJumpListChanged;
35-
public static event EventHandler? FilesJumpListChanged;
34+
public event EventHandler? ExplorerJumpListChanged;
35+
public event EventHandler? FilesJumpListChanged;
3636

3737
private JumpListManager() { }
3838

@@ -491,11 +491,13 @@ private HRESULT GetFolderIconLocation(IShellItem* psi, PWSTR* pIconFilePath, uin
491491

492492
private void ExplorerJumpListWatcher_Changed(object sender, FileSystemEventArgs e)
493493
{
494+
ExplorerJumpListChanged?.Invoke(this, EventArgs.Empty);
494495
PullJumpListFromExplorer();
495496
}
496497

497498
private void FilesJumpListWatcher_Changed(object sender, FileSystemEventArgs e)
498499
{
500+
FilesJumpListChanged?.Invoke(this, EventArgs.Empty);
499501
PushJumpListToExplorer();
500502
}
501503

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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
using Sentry;
1313
using Sentry.Protocol;
1414
using System.IO;
15-
using System.Runtime.InteropServices;
1615
using System.Text;
1716
using Windows.ApplicationModel;
18-
using Windows.Media.Playback;
1917
using Windows.Storage;
2018
using Windows.System;
2119
using Windows.Win32.Foundation;
@@ -173,6 +171,8 @@ await Task.WhenAll(
173171

174172
bool result = JumpListManager.WatchJumpListChanges(AppUserModelIdCrcHash);
175173
if (!result) App.Logger.LogWarning("Failed to watch jump list unexpectedly.");
174+
175+
JumpListManager.FilesJumpListChanged += JumpListManager_FilesJumpListChanged;
176176
}
177177
},
178178
App.Logger);
@@ -188,6 +188,13 @@ static Task OptionalTaskAsync(Task task, bool condition)
188188
generalSettingsService.PropertyChanged += GeneralSettingsService_PropertyChanged;
189189
}
190190

191+
private static void JumpListManager_FilesJumpListChanged(object? sender, EventArgs e)
192+
{
193+
var quickAccessService = Ioc.Default.GetRequiredService<IQuickAccessService>();
194+
195+
quickAccessService.NotifyPinnedItemsChanged(true);
196+
}
197+
191198
/// <summary>
192199
/// Checks application updates and download if available.
193200
/// </summary>

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ public bool IsItemPinned(string folderPath)
9090
return App.QuickAccessManager.Model.PinnedFolders.Contains(folderPath);
9191
}
9292

93+
public async Task NotifyPinnedItemsChanged(bool doUpdateQuickAccessWidget)
94+
{
95+
await App.QuickAccessManager.Model.LoadAsync();
96+
if (doUpdateQuickAccessWidget)
97+
App.QuickAccessManager.UpdateQuickAccessWidget?.Invoke(this, null!);
98+
}
99+
93100
public async Task SaveAsync(string[] items)
94101
{
95102
if (Equals(items, App.QuickAccessManager.Model.PinnedFolders.ToArray()))

0 commit comments

Comments
 (0)