Skip to content

Commit c773727

Browse files
committed
Req
1 parent 0d0172d commit c773727

File tree

8 files changed

+70
-13
lines changed

8 files changed

+70
-13
lines changed

src/Files.App.CsWin32/ComPtr`1.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ public void Attach(T* other)
5050
return ptr;
5151
}
5252

53+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
54+
public readonly HRESULT CopyTo(T** ptr)
55+
{
56+
InternalAddRef();
57+
*ptr = _ptr;
58+
59+
return HRESULT.S_OK;
60+
}
61+
5362
[MethodImpl(MethodImplOptions.AggressiveInlining)]
5463
public readonly T* Get()
5564
{
@@ -80,6 +89,14 @@ public readonly HRESULT CoCreateInstance(Guid* rclsid, IUnknown* pUnkOuter = nul
8089
return PInvoke.CoCreateInstance(rclsid, pUnkOuter, dwClsContext, (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in T.Guid)), (void**)this.GetAddressOf());
8190
}
8291

92+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
93+
private readonly void InternalAddRef()
94+
{
95+
T* ptr = _ptr;
96+
if (ptr != null)
97+
_ = ((IUnknown*)ptr)->AddRef();
98+
}
99+
83100
// Disposer
84101

85102
[MethodImpl(MethodImplOptions.AggressiveInlining)]

src/Files.App.CsWin32/ManualGuids.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,5 +128,8 @@ public static unsafe partial class FOLDERID
128128
{
129129
[GuidRVAGen.Guid("B7534046-3ECB-4C18-BE4E-64CD4CB7D6AC")]
130130
public static partial Guid* FOLDERID_RecycleBinFolder { get; }
131+
132+
[GuidRVAGen.Guid("AE50C081-EBD2-438A-8655-8A092E34987A")]
133+
public static partial Guid* FOLDERID_Recent { get; }
131134
}
132135
}

src/Files.App.CsWin32/NativeMethods.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,3 +270,10 @@ HCRYPTMSG
270270
CERT_QUERY_ENCODING_TYPE
271271
CertGetNameString
272272
IObjectCollection
273+
SHCNE_ID
274+
SHChangeNotifyRegister
275+
SHChangeNotifyDeregister
276+
HWND_MESSAGE
277+
SHChangeNotification_Lock
278+
SHChangeNotification_Unlock
279+
SHGetKnownFolderPath

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/Files.App/App.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,5 +318,10 @@ private static void LastOpenedFlyout_Closed(object? sender, object e)
318318
if (_LastOpenedFlyout == commandBarFlyout)
319319
_LastOpenedFlyout = null;
320320
}
321+
322+
~App()
323+
{
324+
JumpListManager.Default.Dispose();
325+
}
321326
}
322327
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,11 @@ await Task.WhenAll(
123123

124124
FileTagsHelper.UpdateTagsDb();
125125

126-
_ = STATask.Run(() => { JumpListManager.SyncWithExplorerJumpList(50); });
126+
_ = STATask.Run(() =>
127+
{
128+
JumpListManager.Default.SyncWithExplorerJumpList(50);
129+
JumpListManager.Default.WatchExplorerJumpListChanges();
130+
});
127131

128132
static Task OptionalTaskAsync(Task task, bool condition)
129133
{

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@
518518
<data name="PropertiesDriveFileSystem.Text" xml:space="preserve">
519519
<value>File system:</value>
520520
</data>
521+
<data name="JumpListRecentGroupHeader" xml:space="preserve">
522+
<value>Recent</value>
523+
</data>
521524
<data name="TabStripDragAndDropUIOverrideCaption" xml:space="preserve">
522525
<value>Move tab here</value>
523526
</data>
@@ -4319,7 +4322,4 @@
43194322
<data name="FailedToOpenLogFile" xml:space="preserve">
43204323
<value>Unable to open the log file</value>
43214324
</data>
4322-
<data name="Recent" xml:space="preserve">
4323-
<value>Recent</value>
4324-
</data>
43254325
</root>

src/Files.App/ViewModels/Settings/GeneralViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private void AddDateTimeOptions()
146146

147147
private void InitStartupSettingsRecentFoldersFlyout()
148148
{
149-
var recentsItem = new MenuFlyoutSubItemViewModel(Strings.Recent.GetLocalizedResource());
149+
var recentsItem = new MenuFlyoutSubItemViewModel(Strings.JumpListRecentGroupHeader.GetLocalizedResource());
150150
recentsItem.Items.Add(new MenuFlyoutItemViewModel(Strings.Home.GetLocalizedResource())
151151
{
152152
Command = AddPageCommand,

0 commit comments

Comments
 (0)