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

Return data uri image as icon support #3104

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

NoPlagiarism
Copy link
Contributor

Also, bit of silly sanitizing data (accept only data:image)

Any documentation changes needed?

Copy link

github-actions bot commented Dec 2, 2024

@check-spelling-bot Report

🔴 Please review

See the 📂 files view, the 📜action log, or 📝 job summary for details.

❌ Errors Count
❌ forbidden-pattern 22
❌ ignored-expect-variant 1
⚠️ non-alpha-in-dictionary 19

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Copy link

gitstream-cm bot commented Dec 2, 2024

Be a legend 🏆 by adding a before and after screenshot of the changes you made, especially if they are around UI/UX.

Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

📝 Walkthrough

Walkthrough

The changes involve modifications to the ImageLoader.cs and Result.cs files. In ImageLoader.cs, the logic for handling data URIs in the LoadInternalAsync method has been refined to specifically check for "data:image" URIs, and a retry mechanism for thumbnail retrieval has been added. In Result.cs, the IcoPath property setter has been updated to include a condition that checks for "data:image" prefixes, allowing inline image data to be processed correctly.

Changes

File Change Summary
Flow.Launcher.Infrastructure/Image/ImageLoader.cs Refined condition in LoadInternalAsync to check for "data:image" URIs; added retry mechanism for thumbnail retrieval with error logging.
Flow.Launcher.Plugin/Result.cs Updated IcoPath property setter to include check for "data:image" prefix in addition to existing conditions.

Poem

In the meadow where images play,
A rabbit hops, brightening the day.
With data URIs now in sight,
Thumbnails load with retry might.
Hooray for paths that start with "data,"
Our images dance, oh what a beta! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (2)
Flow.Launcher.Infrastructure/Image/ImageLoader.cs (2)

Line range hint 142-147: Enhance data URI handling with validation and size limits.

The current implementation needs additional safeguards:

  1. Validate data URI format
  2. Add size limits to prevent memory issues
  3. Consider caching data URI images

Apply these improvements:

-if (path.StartsWith("data:image", StringComparison.OrdinalIgnoreCase))
+if (path.StartsWith("data:image/", StringComparison.OrdinalIgnoreCase))
 {
+    const int MaxDataUriLength = 5 * 1024 * 1024; // 5MB limit
+    if (path.Length > MaxDataUriLength)
+        throw new ArgumentException($"Data URI exceeds maximum size of {MaxDataUriLength} bytes");
+
+    // Validate data URI format
+    var parts = path.Split(',');
+    if (parts.Length != 2 || !parts[0].EndsWith(";base64", StringComparison.OrdinalIgnoreCase))
+        throw new ArgumentException("Invalid data URI format");
+
+    try
+    {
+        Convert.FromBase64String(parts[1]);
+    }
+    catch (FormatException)
+    {
+        throw new ArgumentException("Invalid base64 data in URI");
+    }
+
     var imageSource = new BitmapImage(new Uri(path));
+    if (!loadFullImage)
+    {
+        imageSource.DecodePixelHeight = SmallIconSize;
+        imageSource.DecodePixelWidth = SmallIconSize;
+    }
     imageSource.Freeze();
+    ImageCache[path, loadFullImage] = imageSource;
     return new ImageResult(imageSource, ImageType.Data);
 }

Line range hint 148-163: Well-implemented retry mechanism for thumbnail loading.

The retry logic with proper exception logging improves reliability. Consider adding a brief delay between retries for transient issues.

Consider adding a delay between retries:

 catch (System.Exception e)
 {
     try
     {
+        await Task.Delay(100); // Add brief delay before retry
         imageResult = GetThumbnailResult(ref path, loadFullImage);
     }
     catch (System.Exception e2)
     {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 14f1a5a and 0b0ead1.

📒 Files selected for processing (2)
  • Flow.Launcher.Infrastructure/Image/ImageLoader.cs (1 hunks)
  • Flow.Launcher.Plugin/Result.cs (1 hunks)
🔇 Additional comments (1)
Flow.Launcher.Infrastructure/Image/ImageLoader.cs (1)

Line range hint 142-147: Verify data URI usage across the codebase.

Let's ensure there are no existing data URI implementations that might conflict with these changes.

✅ Verification successful

Based on the results, I can now generate the final response:

Data URI implementation is properly isolated and consistent

The search results show that:

  • Data URI usage is properly contained within the image loading infrastructure
  • The new implementation aligns with existing BitmapImage usage patterns across the codebase
  • No conflicting implementations or memory-related TODOs were found for data URI handling
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing data URI usage
echo "Searching for data URI usage in code..."
rg -l "data:image" 

# Search for potential image loading implementations
echo "Searching for image loading implementations..."
ast-grep --pattern 'new BitmapImage($$$)'

# Search for potential memory/performance related issues
echo "Searching for TODO/FIXME comments related to images..."
rg -i "todo|fixme|hack" -A 3 -g "!*.md" | grep -i -E "image|icon|memory|performance"

Length of output: 2649

Flow.Launcher.Plugin/Result.cs Show resolved Hide resolved
@taooceros
Copy link
Member

Don't think we need to change doc. Nobody is using this I think.

@NoPlagiarism
Copy link
Contributor Author

Nobody is using this I think.

Kinda sad. Kinda truth

@VictoriousRaptor VictoriousRaptor added this to the 1.19.5 milestone Dec 5, 2024
@VictoriousRaptor VictoriousRaptor added the enhancement New feature or request label Dec 5, 2024
@VictoriousRaptor VictoriousRaptor merged commit 120b7c7 into Flow-Launcher:dev Dec 5, 2024
6 of 8 checks passed
@Garulf
Copy link
Member

Garulf commented Dec 5, 2024

This use to work before we added http support and async. Glad to see it back. Thank you.

Copy link

gitstream-cm bot commented Dec 5, 2024

🥷 Code experts: no user matched threshold 10

See details

To learn more about /:\ gitStream - Visit our Docs

@NoPlagiarism NoPlagiarism deleted the image_data_uri branch December 5, 2024 22:30
@coderabbitai coderabbitai bot mentioned this pull request Dec 7, 2024
@jjw24 jjw24 modified the milestones: 1.19.5, 1.20.0 Dec 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants