@@ -19,11 +19,14 @@ namespace Files.App.Storage
19
19
/// <remarks>
20
20
/// See <a href="https://github.com/0x5bfa/JumpListManager/blob/HEAD/JumpListManager/JumpList.cs" />
21
21
/// </remarks>
22
- public unsafe static class JumpListManager
22
+ public unsafe class JumpListManager : IDisposable
23
23
{
24
+ private static readonly Lazy < JumpListManager > _default = new ( ( ) => new JumpListManager ( ) , LazyThreadSafetyMode . ExecutionAndPublication ) ;
25
+ public static JumpListManager Default => _default . Value ;
26
+
24
27
private readonly static string _aumid = $ "{ Package . Current . Id . FamilyName } !App";
25
28
26
- public static bool SyncWithExplorerJumpList ( int maxCount )
29
+ public bool SyncWithExplorerJumpList ( int maxCount = 30 )
27
30
{
28
31
ClearAutomaticDestinations ( ) ;
29
32
ClearCustomDestinations ( ) ;
@@ -44,7 +47,15 @@ public static bool SyncWithExplorerJumpList(int maxCount)
44
47
return true ;
45
48
}
46
49
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 ( )
48
59
{
49
60
HRESULT hr = default ;
50
61
@@ -66,7 +77,7 @@ private static bool ClearAutomaticDestinations()
66
77
return true ;
67
78
}
68
79
69
- private static bool ClearCustomDestinations ( )
80
+ private bool ClearCustomDestinations ( )
70
81
{
71
82
using ComPtr < IInternalCustomDestinationList > picdl = default ;
72
83
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()
106
117
return false ;
107
118
}
108
119
109
- private static bool EnsureRecentCategoryIsVisible ( )
120
+ private bool EnsureRecentCategoryIsVisible ( )
110
121
{
111
122
HRESULT hr = default ;
112
123
@@ -124,7 +135,7 @@ private static bool EnsureRecentCategoryIsVisible()
124
135
return true ;
125
136
}
126
137
127
- private static bool GetRecentItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
138
+ private bool GetRecentItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
128
139
{
129
140
HRESULT hr = default ;
130
141
@@ -149,7 +160,7 @@ private static bool GetRecentItemsFromExplorer(int maxCount, IObjectCollection**
149
160
return true ;
150
161
}
151
162
152
- private static bool GetPinnedItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
163
+ private bool GetPinnedItemsFromExplorer ( int maxCount , IObjectCollection * * ppoc )
153
164
{
154
165
HRESULT hr = default ;
155
166
@@ -174,7 +185,7 @@ private static bool GetPinnedItemsFromExplorer(int maxCount, IObjectCollection**
174
185
return true ;
175
186
}
176
187
177
- private static bool CopyToFilesAutomaticDestinations ( IObjectCollection * pRecentOC , IObjectCollection * pPinnedOC )
188
+ private bool CopyToFilesAutomaticDestinations ( IObjectCollection * pRecentOC , IObjectCollection * pPinnedOC )
178
189
{
179
190
HRESULT hr = default ;
180
191
@@ -223,5 +234,15 @@ private static bool CopyToFilesAutomaticDestinations(IObjectCollection* pRecentO
223
234
224
235
return true ;
225
236
}
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
+ }
226
247
}
227
248
}
0 commit comments