Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Quality: Introduced IWindowsRecentItemsService #16150

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

0x5bfa
Copy link
Member

@0x5bfa 0x5bfa commented Sep 8, 2024

Resolved / Related Issues

Note

There's been a known issue with enumerating recent items, where the service enumerates pinned files as well as recent items. Because of this, if there's any, Clear All doesn't work properly. While this PR didn't introduce this issue we probably want to look into later.

Steps used to test these changes

  1. Enumerate recent items
  2. Delete one recent item
  3. Clear all recent items

@0x5bfa 0x5bfa marked this pull request as draft September 8, 2024 13:58
@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-IWindowsRecentItemsService branch 4 times, most recently from d424572 to c861720 Compare September 15, 2024 08:39
@0x5bfa 0x5bfa marked this pull request as ready for review September 15, 2024 10:46
@0x5bfa

This comment was marked as resolved.

@yaira2
Copy link
Member

yaira2 commented Sep 15, 2024

Can we use the context menu verb for that?

@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-IWindowsRecentItemsService branch from 0d0a836 to cf808bc Compare September 16, 2024 14:41
@yaira2
Copy link
Member

yaira2 commented Sep 18, 2024

It looks like folders are showing in the recent files widget

@0x5bfa

This comment was marked as resolved.

@yaira2
Copy link
Member

yaira2 commented Sep 19, 2024

Pinned files should be included

@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-IWindowsRecentItemsService branch 2 times, most recently from ddf1c68 to 24948f8 Compare September 21, 2024 03:15
@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-IWindowsRecentItemsService branch from 24948f8 to ba20eeb Compare September 28, 2024 02:31
@0x5bfa 0x5bfa force-pushed the 5bfa/CQ-IWindowsRecentItemsService branch from ba20eeb to 24f5ba6 Compare September 29, 2024 04:59
@0x5bfa

This comment was marked as outdated.

@yaira2
Copy link
Member

yaira2 commented Sep 30, 2024

There is one issue I discovered where the order of the recent items doesn't match the behavior in main.

@0x5bfa

This comment was marked as outdated.

@0x5bfa
Copy link
Member Author

0x5bfa commented Sep 30, 2024

Sorry to have forgot to mention this, I meant to.

@yaira2
Copy link
Member

yaira2 commented Sep 30, 2024

The behavior in main matches File Explorer. We shouldn't be doing our own sorting here.

@jiejasonliu
Copy link
Contributor

There was a comment that mentioned the order is already sorted so don't sort here, but tbh I don't understand why @jiejasonliu wrote so.

I only slightly remember this but I figured it would be reasonable to include why we didn't sort since we did so for the folder flow. The initial implementation read directly from Quick Access so there was no need to sort again.
It looks like we still read from Quick Access (looking at the GUID) so we can still rely on enumeration order probably.

cmi.cbSize = (uint)sizeof(CMINVOKECOMMANDINFO);
cmi.nShow = (int)SHOW_WINDOW_CMD.SW_HIDE;

// Try unpin first for pinned files
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this includes folders too? If so we should execute both unpinfromhome and removefromhome. The former doesn't work for a lot of the default Windows folders like Music & Video.

ba6624b#diff-e7c944353f705cd45acb6c334f0ce1693abda765b0217b207ef03c71c96e2143R180

Copy link
Member Author

@0x5bfa 0x5bfa Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I was confused by these. These verbs are undocumented?
Is there an unofficial documentation about this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was never able to find official docs for this outside of forums, but in my own testing it's feasible & safe to call both if you want to remove a folder. There's probably not a need to invoke these verbs for files though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I'll resolve it shortly.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jiejasonliu I just should execute both unpinfromhome and removefromhome? Not necessarily remove?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So remove is still needed to remove files (non-folders).
If we're trying to unpin folders, then I suggest executing both unpinfromhome and removefromhome.

This flow does not know whether the recent item we're handling is a file/folder right?
I'm not sure what happens if you invoke the wrong verbs for the wrong type (file vs. folder), but my guess is nothing and maybe we could fire all three if it's too difficult to distinguish what type of recent item we're handling.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flow does not know whether the recent item we're handling is a file/folder right?

Yeah, should I add IsFolder to WidgetRecentItem at least?

I'm not sure what happens if you invoke the wrong verbs for the wrong type (file vs. folder), but my guess is nothing and maybe we could fire all three if it's too difficult to distinguish what type of recent item we're handling.

I guess the invocation method would fail with E_FAIL or some HRESULT.

So remove is still needed to remove files (non-folders).

Got it. I'll add invocation code of these 3 verbs

@0x5bfa
Copy link
Member Author

0x5bfa commented Oct 1, 2024

It looks like we still read from Quick Access (looking at the GUID) so we can still rely on enumeration order probably.

Do you know IApplicationDocumentLists? This is specifically enumeration interface for frequent and recent items. Also IApplicationDestinations is provided for deleting an item and clearing all. I have to try.

@jiejasonliu
Copy link
Contributor

It looks like we still read from Quick Access (looking at the GUID) so we can still rely on enumeration order probably.

Do you know IApplicationDocumentLists? This is specifically enumeration interface for frequent and recent items. Also IApplicationDestinations is provided for deleting an item and clearing all. I have to try.

I don't, but the API seems promising. From an glance, it looks like a bunch of SHAddToRecentDocs coupled with some other (undocumented?) internals -- the ability to unpin a specific destination is interesting. I'll say that when this was first implemented, I settled on whatever worked first.

@0x5bfa
Copy link
Member Author

0x5bfa commented Oct 12, 2024

@jiejasonliu Thank you for the review.
While whether we're going to get rid of recent folders support depends on @yaira2, I took care of all.

Speaking of IApplicationDocumentLists, I confirmed this was a completely different stuff; File Explorer only adds recent 'folders'. Presumably, we still gotta to use a dedicated shell folder, as we have.

@yaira2
Copy link
Member

yaira2 commented Oct 14, 2024

@jiejasonliu Thank you for the review. While whether we're going to get rid of recent folders support depends on @yaira2, I took care of all.

Speaking of IApplicationDocumentLists, I confirmed this was a completely different stuff; File Explorer only adds recent 'folders'. Presumably, we still gotta to use a dedicated shell folder, as we have.

We should aim to match the existing functionality. Aren't recent folders used in the Quick Access widget?

@0x5bfa
Copy link
Member Author

0x5bfa commented Oct 14, 2024

It has never been used afaik.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants