Improve ImageLoader thumbnail fallbacks and refactor GetThumbnailResult#4453
Improve ImageLoader thumbnail fallbacks and refactor GetThumbnailResult#4453DavidGBrett wants to merge 15 commits into
Conversation
3626303 to
7d3b989
Compare
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughReplaces ChangesImage Thumbnail Loading Refactoring
Sequence DiagramsequenceDiagram
participant Requester as ImageLoader.LoadInternalAsync
participant Dispatcher as ImageLoader.GetThumbnailResult
participant Shell as WindowsThumbnailProvider
participant Decoder as LoadBitmapImage
participant Cache as ImageCache/FolderImage
Requester->>Dispatcher: GetThumbnailResult(path, loadFullImage)
Dispatcher->>Shell: Try shell thumbnail (directory/image/other)
Shell-->>Dispatcher: BitmapSource or failure
alt thumbnail success
Dispatcher->>Decoder: (optional) scale bitmap
Decoder-->>Dispatcher: ImageSource (frozen)
Dispatcher->>Cache: store result
Dispatcher-->>Requester: ImageResult(success)
else shell failure for directory
Dispatcher->>Cache: return FolderImage
Dispatcher-->>Requester: ImageResult(FolderImage)
else shell failure for other
Dispatcher->>Dispatcher: TryExtractAssociatedIcon(path)
alt extraction success
Dispatcher->>Cache: store result
Dispatcher-->>Requester: ImageResult(success)
else
Dispatcher->>Cache: store MissingImage
Dispatcher-->>Requester: ImageResult(MissingImage)
end
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@Flow.Launcher.Infrastructure/Image/ImageLoader.cs`:
- Around line 202-203: The directory branch drops the loadFullImage flag causing
folder previews to always use the small icon path; propagate loadFullImage into
the directory path by modifying the call to GetDirectoryThumbnailResult to
accept the loadFullImage parameter (e.g., GetDirectoryThumbnailResult(path,
loadFullImage)) and update GetDirectoryThumbnailResult to pass that flag through
to the GetThumbnail call so it requests FullIconSize when loadFullImage is true
(instead of always calling GetThumbnail(..., IconOnly)). Ensure any other
directory-returning call sites (the block covering 234-244) are updated
similarly.
- Around line 407-424: The method LoadBitmapImageScaleToFitWithin currently
calls LoadBitmapImage(path) which fully decodes the image before checking
dimensions; change it to first read only metadata using BitmapDecoder with
BitmapCreateOptions.DelayCreation and BitmapCacheOption.None to obtain
PixelWidth/PixelHeight without decoding, then if both dimensions are <= maxSize
call LoadBitmapImage(path) to load fully, otherwise call LoadBitmapImage(path,
decodePixelWidth: maxSize) or LoadBitmapImage(path, decodePixelHeight: maxSize)
as the existing widthIsLarger branch does; reference the existing
LoadBitmapImageScaleToFitWithin and LoadBitmapImage functions when making this
change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1e82a1b0-db57-4015-9fe7-2b4f8be5ef91
📒 Files selected for processing (2)
Flow.Launcher.Infrastructure/Constant.csFlow.Launcher.Infrastructure/Image/ImageLoader.cs
d36d4d6 to
00ba311
Compare
There was a problem hiding this comment.
1 issue found across 2 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="Flow.Launcher.Infrastructure/Image/ImageLoader.cs">
<violation number="1" location="Flow.Launcher.Infrastructure/Image/ImageLoader.cs:166">
P2: The second retry warning logs the wrong exception (`e.Message` instead of `e2.Message`), which misreports the actual second-failure cause.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
Re-trigger cubic
00ba311 to
38b1f0e
Compare
|
Hi @DavidGBrett, could you please update the PR description with what tests you have done so I can see if there are other testing I need to cover. |
I've mostly just been adding lines such as E.g. If I wanted to test file icon fallbacks This is definitely not ideal, though I'm not sure how the existing simple missing icon fallbacks were tested. I could do a bigger rework with dependency injection throughout to make it properly testable if you would prefer. If you mean to ask if I found scenarios where this could naturally happen in windows, then I did not, i just forced it. The user confirmed that these changes do fix their problem anyways - see second last comment in #4450 |
…ize parameter This makes it more reusable and removes the hidden dependency on FullImageSize
This makes it consistent with the missing icon fallback
- Remove ref path parameters from thumbnail helper methods. - Stop rewriting path to missing/folder icon constants in fallback paths. This eliminates hidden side effects and make helper flow easier to reason about. Mutation previously only affected rare final-error logging/cache paths, which seemed like unintended behavior there. Now we will always log the original path and cache it to the missing image instead of pointlessly caching the missing image to the missing image path.
…ary image decoding when checking if resizing is required
- Use Log.Warn instead of Log.Exception or others for the thumbnail failures - Use Log.Debug for intermediate fallback logging. - Improve log messages to consistently mention if we use a fallback icon.
…er thumbnail handlers This is not the original behavior but is consistent with the other branches, and makes sense to provide this as an option
Makes success or failure more explicit and simplifies use Also more consistent with other try-style methods for a similar purpose such as TryGetBitmapImageDimensionsFromMetadata
bca3bbd to
8448bf9
Compare
Will resolve #4450, maybe also #4403
Summary
Testing
Unfortunately adding unit tests would require further reworks - Nor do I have an ARM device available to try this on.
So to test the fallbacks I have been adding a
throw new System.Exception();to the try catch that would trigger the fallback I want to test.Summary by cubic
Refactors
ImageLoaderto make thumbnail loading reliable and consistent, while removing path-mutation side effects. Adds smarter fallbacks: non-images useTryExtractAssociatedIcon, folders use a preloaded folder icon, and images use efficient bitmap decoding.Summary of changes
GetThumbnailResultinto per-type helpers and addedCreateImageResult; images are frozen; paths are never rewritten in logs/cache.loadFullImage(SmallIconSize/FullIconSize); on failure, use preloadedFolderImage.SmallIconSizefor thumbs,FullImageSizefor previews); else useMissingImage.LoadSvgImage; on failure, useMissingImage.TryExtractAssociatedIcon; else useMissingImage.Log.Warnfor final failures andLog.Debugfor fallbacks.Constant.FolderIconand preloadedFolderImage.LoadBitmapImageScaleToFitWithin,LoadBitmapImage,TryExtractAssociatedIcon,CreateImageResult,TryGetBitmapImageDimensionsFromMetadata.Constant.ImageIconandImageLoader.Imageplaceholder.LoadFullImageand all path-mutation side effects.Release Note
Thumbnails and icons are more reliable and consistently sized, with smarter fallbacks for folders, images, and files.
Written for commit bca3bbd. Summary will update on new commits. Review in cubic