Skip to content

New API Function LoadImageAsync #3412

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

Merged
merged 12 commits into from
Apr 8, 2025
Merged

Conversation

Jack251970
Copy link
Contributor

New API Function LoadImageAsync

Expose ImageLoader.LoadAsync to api function so that all plugins can load images from local, remove or data:image url. They can enable cacheImage option to let FL cache those images to improve performance.

Unify all calls of ImageLoader.LoadAsync to API.LoadImageAsync

Improve WebSearch plugin code quality

Use api functions instead of direct project calls in this plugin.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new API function, LoadImageAsync, to centralize and standardize image loading across plugins and the core application while also improving error logging and overall code quality.

  • Replaces direct calls to ImageLoader.LoadAsync with API.LoadImageAsync.
  • Updates HTTP and logging calls to use centralized API methods.
  • Augments ImageLoader to support an optional caching flag for improved performance.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs Updated API and logging usage for Google suggestions.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs Updated API and logging usage for DuckDuckGo suggestions.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs Updated API and logging usage, with a noted error message issue.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs Updated API and logging usage for Baidu suggestions.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs Replaced ImageLoader.LoadAsync with API.LoadImageAsync for image preview.
Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs Updated preview loading to use the new API call.
Flow.Launcher/ViewModel/ResultViewModel.cs Centralized image loading via the new API function.
Flow.Launcher/ViewModel/PluginViewModel.cs Updated plugin icon loading through the API.
Flow.Launcher/ViewModel/MainViewModel.cs Switched to using the API for plugin icon retrieval.
Flow.Launcher/PublicAPIInstance.cs Added the new LoadImageAsync API method.
Flow.Launcher/Msg.xaml.cs Updated image loading in dialog views to use the API.
Flow.Launcher/MessageBoxEx.xaml.cs Replaced direct image loading with the new API call.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Extended the interface to include LoadImageAsync with detailed comment documentation.
Flow.Launcher.Infrastructure/Image/ImageLoader.cs Modified LoadAsync to include caching support.

This comment has been minimized.

Copy link

gitstream-cm bot commented Apr 2, 2025

🥷 Code experts: no user but you matched threshold 10

Jack251970 has most 👩‍💻 activity in the files.
Yusyuriv, Jack251970 have most 🧠 knowledge in the files.

See details

Flow.Launcher.Infrastructure/Image/ImageLoader.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC 4 additions & 3 deletions
NOV 12 additions & 4 deletions

Knowledge based on git-blame:
Jack251970: 3%

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB 38 additions & 28 deletions
JAN 21 additions & 3 deletions
DEC 8 additions & 73 deletions
NOV 84 additions & 1 deletions

Knowledge based on git-blame:
Jack251970: 14%

Flow.Launcher/MessageBoxEx.xaml.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN 203 additions & 0 deletions
DEC
NOV 0 additions & 192 deletions

Knowledge based on git-blame:
Jack251970: 61%

Flow.Launcher/Msg.xaml.cs

Activity based on git-commit:

Jack251970
APR
MAR 10 additions & 11 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 11%

Flow.Launcher/PublicAPIInstance.cs

Activity based on git-commit:

Jack251970
APR
MAR 21 additions & 19 deletions
FEB 28 additions & 11 deletions
JAN 45 additions & 47 deletions
DEC 25 additions & 32 deletions
NOV 16 additions & 0 deletions

Knowledge based on git-blame:
Jack251970: 21%

Flow.Launcher/ViewModel/MainViewModel.cs

Activity based on git-commit:

Jack251970
APR
MAR 695 additions & 628 deletions
FEB 63 additions & 21 deletions
JAN 17 additions & 21 deletions
DEC 59 additions & 63 deletions
NOV 39 additions & 15 deletions

Knowledge based on git-blame:
Jack251970: 29%
Yusyuriv: 3%

Flow.Launcher/ViewModel/PluginViewModel.cs

Activity based on git-commit:

Jack251970
APR
MAR 94 additions & 57 deletions
FEB 31 additions & 37 deletions
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 33%
Yusyuriv: 19%

Flow.Launcher/ViewModel/ResultViewModel.cs

Activity based on git-commit:

Jack251970
APR
MAR 47 additions & 50 deletions
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Jack251970: 15%
Yusyuriv: 1%

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Yusyuriv: 100%

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV 1 additions & 1 deletions

Knowledge based on git-blame:

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:
Yusyuriv: 100%

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs

Activity based on git-commit:

Jack251970
APR
MAR
FEB
JAN
DEC
NOV

Knowledge based on git-blame:

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

Copy link

gitstream-cm bot commented Apr 2, 2025

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

coderabbitai bot commented Apr 2, 2025

📝 Walkthrough

Walkthrough

The pull request introduces modifications to the image loading functionality and HTTP/logging mechanisms across the project. The ImageLoader.LoadAsync method is updated to include an optional cacheImage parameter, and a new LoadImageAsync method is added to the public API interface and its instance to support asynchronous image loading. Client code previously invoking ImageLoader.LoadAsync now utilizes the new API methods. Additionally, HTTP requests and exception logging in various web search plugins have been adjusted to leverage the API context methods.

Changes

File(s) Change Summary
Flow.Launcher.Infrastructure/…/ImageLoader.cs, Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs, Flow.Launcher/PublicAPIInstance.cs Updated ImageLoader.LoadAsync to include an optional cacheImage parameter. Added new API methods LoadImageAsync in the public API interface and instance to support asynchronous image loading.
Flow.Launcher/MessageBoxEx.xaml.cs, Flow.Launcher/Msg.xaml.cs, Flow.Launcher/ViewModel/MainViewModel.cs, Flow.Launcher/ViewModel/PluginViewModel.cs, Flow.Launcher/ViewModel/ResultViewModel.cs, Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs, Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs Replaced direct calls to ImageLoader.LoadAsync with calls to App.API.LoadImageAsync or Main._context.API.LoadImageAsync, changing the source of image loading in client code.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs, …/Bing.cs, …/DuckDuckGo.cs, …/Google.cs Updated HTTP request calls to use Main._context.API.HttpGetStringAsync/HttpGetStreamAsync and changed logging to use Main._context.API.LogException. Additionally, made the Bing class public.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Client
    participant API
    participant ImageLoader

    Client->>API: LoadImageAsync(path, loadFullImage, cacheImage)
    API->>ImageLoader: LoadAsync(path, loadFullImage, cacheImage)
    ImageLoader-->>API: Return ImageSource (with caching as needed)
    API-->>Client: Deliver ImageSource
Loading
sequenceDiagram
    participant SuggestionSource
    participant API
    participant HTTPService

    SuggestionSource->>API: Request HTTP data (via HttpGetStreamAsync/HttpGetStringAsync)
    API->>HTTPService: Make HTTP request
    HTTPService-->>API: Return HTTP response
    API-->>SuggestionSource: Forward response data
    alt Error Occurs
        SuggestionSource->>API: LogException(error)
    end

Possibly related PRs

Suggested labels

kind/ux

Suggested reviewers

  • taooceros

Poem

I'm a hopping rabbit in a code-filled glen,
Leaping over refactors time and again.
Images load with a skip and a bound,
HTTP calls now smoothly resound.
In the world of code, a renewed spring day,
My bunny heart cheers in a joyful display!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 46109a2 and 6af79a1.

📒 Files selected for processing (2)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (2 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • Flow.Launcher/PublicAPIInstance.cs
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

🪧 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 generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

🧹 Nitpick comments (1)
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs (1)

36-36: Fix log message to correctly reference Bing

The log message incorrectly references "baidu" instead of "Bing" which is inconsistent with the class name.

-                Main._context.API.LogException(nameof(Bing), "Can't get suggestion from baidu", e);
+                Main._context.API.LogException(nameof(Bing), "Can't get suggestion from Bing", e);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3c18a6 and 3de8005.

📒 Files selected for processing (14)
  • Flow.Launcher.Infrastructure/Image/ImageLoader.cs (2 hunks)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (2 hunks)
  • Flow.Launcher/MessageBoxEx.xaml.cs (1 hunks)
  • Flow.Launcher/Msg.xaml.cs (2 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
  • Flow.Launcher/ViewModel/MainViewModel.cs (1 hunks)
  • Flow.Launcher/ViewModel/PluginViewModel.cs (1 hunks)
  • Flow.Launcher/ViewModel/ResultViewModel.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs (1 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs (3 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs (2 hunks)
🧰 Additional context used
🧬 Code Definitions (3)
Flow.Launcher/ViewModel/MainViewModel.cs (1)
Flow.Launcher/App.xaml.cs (2)
  • App (28-343)
  • App (50-114)
Flow.Launcher.Infrastructure/Image/ImageLoader.cs (2)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
  • ValueTask (362-362)
Flow.Launcher/PublicAPIInstance.cs (1)
  • ValueTask (346-347)
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs (3)
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs (1)
  • Task (13-38)
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs (1)
  • Task (13-45)
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs (1)
  • Task (16-52)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
🔇 Additional comments (25)
Flow.Launcher/MessageBoxEx.xaml.cs (1)

159-159: API change improves consistency and plugin accessibility

The code now uses App.API.LoadImageAsync which aligns with the PR objective to unify all image loading calls through the API layer.

Flow.Launcher/ViewModel/MainViewModel.cs (1)

1171-1171: API call replacement is aligned with project changes

This change replaces direct usage of ImageLoader.LoadAsync with the new API interface method App.API.LoadImageAsync, consistent with the PR's objective to centralize image loading functionality.

Flow.Launcher/ViewModel/ResultViewModel.cs (1)

202-202: Image loading functionality unified through API layer

The implementation now properly uses App.API.LoadImageAsync instead of directly accessing ImageLoader.LoadAsync, maintaining the optional loadFullImage parameter. This change improves plugin extensibility by providing a unified API for image loading.

Flow.Launcher/ViewModel/PluginViewModel.cs (1)

48-48: Consistent API migration for plugin icon loading

The change to use App.API.LoadImageAsync is consistent with similar changes throughout the codebase, enhancing maintainability and providing a unified approach to image loading.

Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs (1)

91-91: Clean API transition for image loading!

The code now uses Main.Context.API.LoadImageAsync instead of directly calling the ImageLoader, which aligns with the PR's goal to unify image loading through the API layer.

Flow.Launcher/Msg.xaml.cs (3)

46-46: Good refactoring to use the new API

The code correctly uses the new App.API.LoadImageAsync method instead of directly calling ImageLoader.LoadAsync, aligning with the PR's goal of centralizing image loading through the API.


74-75: Appropriate API usage for image loading

The close image loading is now properly handled through the API layer rather than directly accessing the ImageLoader.


78-79: Consistent API usage throughout the method

This change maintains consistency with the other image loading operations in this method, following the same pattern.

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs (2)

19-19: Good API transition for HTTP requests

The code now uses the API context for HTTP requests instead of direct calls to the Http utility, which improves maintainability.


35-35: Consistent API usage for logging

Good practice to use the API context for logging exceptions instead of directly accessing the Log utility.

Flow.Launcher/PublicAPIInstance.cs (2)

13-13: Necessary namespace addition

The System.Windows.Media namespace is correctly added to support the ImageSource return type of the new LoadImageAsync method.


346-348: Well-implemented new API method

The new LoadImageAsync method is correctly implemented with appropriate default parameters. This is the core of the PR and enables plugins to load images from various sources with an option to control caching.

  • loadFullImage = false ensures optimization by default
  • cacheImage = true enables performance improvements by default
  • The method simply delegates to the existing ImageLoader functionality

This implementation achieves the PR's main objective of exposing image loading functionality to plugins.

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs (2)

26-26: LGTM: Great use of the API for HTTP requests

This change properly uses the centralized API interface method for HTTP requests instead of direct calls, which aligns with the PR objective of encouraging API usage in the WebSearch plugin.


37-37: LGTM: Consistent error logging via API

Good job updating the exception logging to use the API interface, maintaining a consistent approach across the codebase.

Also applies to: 42-42

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)

349-362: LGTM: Well-documented LoadImageAsync API addition

The new LoadImageAsync method is well-documented with clear XML comments explaining the parameters and their purposes. This addition successfully exposes the image loading functionality to all plugins as intended by the PR.

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs (2)

23-23: LGTM: Good usage of API for HTTP requests

This change properly utilizes the centralized API interface method for HTTP string requests, aligning with the PR's goal of improving code quality in the WebSearch plugin.


27-27: LGTM: Consistent error handling approach

Good job updating the exception logging to use the API interface consistently with other suggestion sources.

Also applies to: 42-42

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs (3)

11-11: LGTM: Appropriate visibility change

Making the Bing class public improves consistency with other suggestion source classes.


19-19: LGTM: Consistent API usage for HTTP requests

Good job utilizing the centralized API interface method for HTTP stream requests, aligning with similar changes in other suggestion sources.


41-41: LGTM: Consistent error handling

The exception logging has been properly updated to use the API interface.

Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs (2)

43-44: LGTM: Consistent error handling using API.

The change ensures consistent use of the API's ShowMsgBox method for error handling, which aligns with the best practice of using API functions instead of direct project calls.


63-63: Great API integration!

This change improves code quality by replacing a direct call to ImageLoader.LoadAsync with the new API method LoadImageAsync, perfectly aligning with the PR objective to unify all image loading functionality under the API.

Flow.Launcher.Infrastructure/Image/ImageLoader.cs (3)

280-280: Well-designed method signature enhancement.

The addition of the optional cacheImage parameter with a default value of true maintains backward compatibility while adding new functionality, allowing plugins to control whether images are cached.


296-301: Good implementation of conditional GUID caching.

The conditional saving of the GUID key based on the cacheImage parameter is well implemented, allowing for selective caching of image hash references.


303-307: Excellent implementation of conditional image caching.

The conditional updating of the image cache based on the cacheImage parameter provides precise control over caching behavior, which can significantly improve performance for plugins that don't need persistent image caching.

This comment has been minimized.

Jack251970 and others added 2 commits April 2, 2025 18:35
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@Jack251970 Jack251970 requested a review from Copilot April 2, 2025 10:35

This comment has been minimized.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request introduces a new API function, LoadImageAsync, to centralize image loading across plugins and improve consistency when handling local, remote, or data:image URLs with an optional caching mechanism. Key changes include replacing direct calls to ImageLoader.LoadAsync with API invocations, updating logging calls to use the new API, and modifying the associated interface and documentation.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs Replaces direct HTTP stream and logging calls with API-based equivalents.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs Applies similar modifications replacing direct calls with API-based calls.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs Adjusts class visibility and updates image fetching and logging to use the API.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs Refactors image fetching and logging to leverage the API and aligns logging error messages.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs Updates image loading to use the API in place of direct ImageLoader calls.
Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs Migrates image loading in the preview panel to the new API method.
Flow.Launcher/ViewModel/ResultViewModel.cs Changes image fetching to use App.API.LoadImageAsync for consistency.
Flow.Launcher/ViewModel/PluginViewModel.cs Updates plugin icon loading to use the new API method.
Flow.Launcher/ViewModel/MainViewModel.cs Refactors the logic for loading the plugin icon to use API calls.
Flow.Launcher/PublicAPIInstance.cs Adds the new LoadImageAsync API method to the PublicAPIInstance implementation.
Flow.Launcher/Msg.xaml.cs Updates image loading for UI elements to use the API in place of ImageLoader.
Flow.Launcher/MessageBoxEx.xaml.cs Refactors image fetching for message box icons to use the new API method.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Extends the interface to include the LoadImageAsync method with parameters for full image and cache.
Flow.Launcher.Infrastructure/Image/ImageLoader.cs Modifies the LoadAsync implementation to accept a cacheImage flag and adjust caching behavior.
Comments suppressed due to low confidence (2)

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs:27

  • [nitpick] Consider capitalizing 'baidu' to 'Baidu' in the error message for consistency with other plugins.
Main._context.API.LogException(nameof(Baidu), "Can't get suggestion from baidu", e);

Flow.Launcher.Infrastructure/Image/ImageLoader.cs:296

  • Review the conditional logic: when cacheImage is false, the GUID-to-key mapping is skipped—ensure this behavior is intentional.
else if (cacheImage)

This comment has been minimized.

This comment has been minimized.

@Jack251970 Jack251970 requested a review from Copilot April 2, 2025 10:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new API function, LoadImageAsync, to unify and simplify image loading across various plugins and parts of the project. Key changes include:

  • Replacing direct calls to ImageLoader.LoadAsync with API-based LoadImageAsync.
  • Updating error logging to use API.LogException.
  • Adding new API endpoints in PublicAPIInstance and IPublicAPI interfaces to support image loading from local, remote, or data URLs.

Reviewed Changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs Replaced direct HTTP calls and logging with API method calls.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/DuckDuckGo.cs Updated HTTP requests and exception logging to use the new API.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Bing.cs Changed class scope and API calls for image and suggestion loading.
Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Baidu.cs Updated HTTP and logging calls to use API methods.
Plugins/Flow.Launcher.Plugin.WebSearch/SearchSourceViewModel.cs Modified image preview loading to use API.LoadImageAsync.
Plugins/Flow.Launcher.Plugin.Explorer/Views/PreviewPanel.xaml.cs Updated image loading to utilize API instead of direct ImageLoader calls.
Flow.Launcher/ViewModel/ResultViewModel.cs Replaced image loading to use App.API.LoadImageAsync.
Flow.Launcher/ViewModel/PluginViewModel.cs Updated icon loading with new API function.
Flow.Launcher/ViewModel/MainViewModel.cs Changed image loading to use App.API.LoadImageAsync.
Flow.Launcher/PublicAPIInstance.cs Added new API method LoadImageAsync.
Flow.Launcher/Msg.xaml.cs Updated image loading calls to use App.API.LoadImageAsync.
Flow.Launcher/MessageBoxEx.xaml.cs Changed image loading to use App.API.LoadImageAsync.
Flow.Launcher/Plugin/Interfaces/IPublicAPI.cs Added LoadImageAsync method signature with caching options.
Flow.Launcher.Infrastructure/Image/ImageLoader.cs Modified LoadAsync to accept a cacheImage parameter and updated caching logic accordingly.
Comments suppressed due to low confidence (2)

Plugins/Flow.Launcher.Plugin.WebSearch/SuggestionSources/Google.cs:19

  • [nitpick] Consider using a consistent API context reference across the codebase (e.g., Main._context.API vs. Main.Context.API vs. App.API) to improve readability and maintainability.
await using var resultStream = await Main._context.API.HttpGetStreamAsync(api + Uri.EscapeDataString(query), token: token).ConfigureAwait(false);

Flow.Launcher.Infrastructure/Image/ImageLoader.cs:296

  • [nitpick] When caching is disabled (cacheImage = false), GuidToKey is not updated; if this behavior is intentional, please add a comment explaining why the mapping is skipped, to avoid confusion during maintenance.
else if (cacheImage)

This comment has been minimized.

@Jack251970 Jack251970 added the enhancement New feature or request label Apr 4, 2025

This comment has been minimized.

@Jack251970 Jack251970 requested a review from Copilot April 5, 2025 10:03
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 14 out of 14 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

Flow.Launcher.Infrastructure/Image/ImageLoader.cs:303

  • When caching is disabled (cacheImage is false), the GuidToKey mapping is not updated, which may cause inconsistencies if this mapping is subsequently used. Please verify that this behavior is intentional and consider adding tests to ensure that image identification remains correct when caching is turned off.
else if (cacheImage)

This comment has been minimized.

Copy link

github-actions bot commented Apr 5, 2025

@check-spelling-bot Report

🔴 Please review

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

❌ Errors Count
❌ forbidden-pattern 22
⚠️ 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.

@jjw24 jjw24 merged commit 75f23aa into Flow-Launcher:dev Apr 8, 2025
4 checks passed
@jjw24 jjw24 removed the 5 min review label Apr 8, 2025
@jjw24 jjw24 added this to the 1.20.0 milestone Apr 8, 2025
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.

2 participants