@@ -19,11 +19,14 @@ namespace Files.App.Storage
1919 /// <remarks>
2020 /// See <a href="https://github.com/0x5bfa/JumpListManager/blob/HEAD/JumpListManager/JumpList.cs" />
2121 /// </remarks>
22- public unsafe static class JumpListManager
22+ public unsafe class JumpListManager : IDisposable
2323 {
24+ private static readonly Lazy < JumpListManager > _default = new ( ( ) => new JumpListManager ( ) , LazyThreadSafetyMode . ExecutionAndPublication ) ;
25+ public static JumpListManager Default => _default . Value ;
26+
2427 private readonly static string _aumid = $ "{ Package . Current . Id . FamilyName } !App";
2528
26- public static bool SyncWithExplorerJumpList ( int maxCount )
29+ public bool SyncWithExplorerJumpList ( int maxCount = 30 )
2730 {
2831 ClearAutomaticDestinations ( ) ;
2932 ClearCustomDestinations ( ) ;
@@ -44,7 +47,15 @@ public static bool SyncWithExplorerJumpList(int maxCount)
4447 return true ;
4548 }
4649
47- private static bool ClearAutomaticDestinations ( )
50+ public void WatchExplorerJumpListChanges ( )
51+ {
52+ // Get the path to the Explorer's automatic destinations file
53+ using ComHeapPtr < char > pwszRecentFolderPath = default ;
54+ PInvoke . SHGetKnownFolderPath ( FOLDERID . FOLDERID_Recent , KNOWN_FOLDER_FLAG . KF_FLAG_DONT_VERIFY | KNOWN_FOLDER_FLAG . KF_FLAG_NO_ALIAS , HANDLE . Null , ( PWSTR * ) pwszRecentFolderPath . GetAddressOf ( ) ) ;
55+ var path = $ "{ new ( pwszRecentFolderPath . Get ( ) ) } \\ AutomaticDestinations";
56+ }
57+
58+ private bool ClearAutomaticDestinations ( )
4859 {
4960 HRESULT hr = default ;
5061
@@ -66,7 +77,7 @@ private static bool ClearAutomaticDestinations()
6677 return true ;
6778 }
6879
69- private static bool ClearCustomDestinations ( )
80+ private bool ClearCustomDestinations ( )
7081 {
7182 using ComPtr < IInternalCustomDestinationList > picdl = default ;
7283 HRESULT hr = PInvoke . CoCreateInstance ( CLSID . CLSID_DestinationList , null , CLSCTX . CLSCTX_INPROC_SERVER , IID . IID_IInternalCustomDestinationList , ( void * * ) picdl . GetAddressOf ( ) ) ;
@@ -106,7 +117,7 @@ private static bool ClearCustomDestinations()
106117 return false ;
107118 }
108119
109- private static bool EnsureRecentCategoryIsVisible ( )
120+ private bool EnsureRecentCategoryIsVisible ( )
110121 {
111122 HRESULT hr = default ;
112123
@@ -124,7 +135,7 @@ private static bool EnsureRecentCategoryIsVisible()
124135 return true ;
125136 }
126137
127- private static bool GetRecentItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
138+ private bool GetRecentItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
128139 {
129140 HRESULT hr = default ;
130141
@@ -149,7 +160,7 @@ private static bool GetRecentItemsFromExplorer(int maxCount, IObjectCollection**
149160 return true ;
150161 }
151162
152- private static bool GetPinnedItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
163+ private bool GetPinnedItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
153164 {
154165 HRESULT hr = default ;
155166
@@ -174,7 +185,7 @@ private static bool GetPinnedItemsFromExplorer(int maxCount, IObjectCollection**
174185 return true ;
175186 }
176187
177- private static bool CopyToFilesAutomaticDestinations ( IObjectCollection * pRecentOC , IObjectCollection * pPinnedOC )
188+ private bool CopyToFilesAutomaticDestinations ( IObjectCollection * pRecentOC , IObjectCollection * pPinnedOC )
178189 {
179190 HRESULT hr = default ;
180191
@@ -223,5 +234,15 @@ private static bool CopyToFilesAutomaticDestinations(IObjectCollection* pRecentO
223234
224235 return true ;
225236 }
237+
238+ private void Watcher_FileChanged ( )
239+ {
240+ // Sync the jump list when the Explorer's automatic destinations file changes
241+ SyncWithExplorerJumpList ( ) ;
242+ }
243+
244+ public void Dispose ( )
245+ {
246+ }
226247 }
227248}
0 commit comments