Skip to content

Commit 968d8ee

Browse files
authored
Update WindowsRecentItemsService.cs
1 parent aca8a59 commit 968d8ee

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

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

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,32 @@ public unsafe bool Remove(RecentItem item)
127127
cmi.cbSize = (uint)sizeof(CMINVOKECOMMANDINFO);
128128
cmi.nShow = (int)SHOW_WINDOW_CMD.SW_HIDE;
129129

130-
// Try unpin first for pinned files
131-
fixed (byte* pVerb = Encoding.ASCII.GetBytes("unpinfromhome"))
132-
cmi.lpVerb = new(pVerb);
133-
hr = pContextMenu.Get()->InvokeCommand(cmi);
134-
135-
// Remove recent files
136-
fixed (byte* pVerb = Encoding.ASCII.GetBytes("removefromhome"))
137-
cmi.lpVerb = new(pVerb);
138-
hr = pContextMenu.Get()->InvokeCommand(cmi);
130+
// Unpin the item
131+
fixed (byte* pVerb1 = Encoding.ASCII.GetBytes("remove"),
132+
pVerb2 = Encoding.ASCII.GetBytes("unpinfromhome"),
133+
pVerb3 = Encoding.ASCII.GetBytes("removefromhome"))
134+
{
135+
// Try unpin files
136+
cmi.lpVerb = new(pVerb1);
137+
hr = pContextMenu.Get()->InvokeCommand(cmi);
138+
if (hr == HRESULT.S_OK)
139+
return;
140+
141+
// Try unpin folders
142+
cmi.lpVerb = new(pVerb2);
143+
hr = pContextMenu.Get()->InvokeCommand(cmi);
144+
if (hr == HRESULT.S_OK)
145+
return;
146+
147+
// NOTE:
148+
// There seems to be an issue with unpinfromhome where some shell folders
149+
// won't be removed via unpinfromhome verb.
150+
// Try unpin folders again
151+
cmi.lpVerb = new(pVerb3);
152+
hr = pContextMenu.Get()->InvokeCommand(cmi);
153+
if (hr == HRESULT.S_OK)
154+
return;
155+
}
139156

140157
return true;
141158
}

0 commit comments

Comments
 (0)