Skip to content

Add New API to Force Web Url #3616

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

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open

Add New API to Force Web Url #3616

wants to merge 5 commits into from

Conversation

Jack251970
Copy link
Member

Context

In WebSearch plugin, users may input url like file:///D:/search/index.html?query={q} which is regarded as files url in C# standard process. So we need to a new api to force using web brower to open it.

Resolve #3608.

Test

  • Go to the plugin settings of web search plugin.
  • Add a new search engine.
  • Set the URL to something with file:// prefix like "file:///D:/search/index.html?query={q}"
  • Search anything, for example casino. It will open "file:///D:/search/index.html?query=casino" in brower tab.

@prlabeler prlabeler bot added bug Something isn't working enhancement New feature or request labels Jun 3, 2025
@Jack251970 Jack251970 removed the enhancement New feature or request label Jun 3, 2025
@Jack251970 Jack251970 added this to the Future milestone Jun 3, 2025

This comment has been minimized.

Copy link

gitstream-cm bot commented Jun 3, 2025

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 Jun 3, 2025

📝 Walkthrough

"""

Walkthrough

Two new OpenWebUrl methods were added to the IPublicAPI interface and implemented in PublicAPIInstance, allowing URLs (including local file URLs) to be opened using the configured browser. The WebSearch plugin now uses these methods instead of OpenUrl for opening search result URLs.

Changes

File(s) Change Summary
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Added two OpenWebUrl method overloads to the IPublicAPI interface.
Flow.Launcher/PublicAPIInstance.cs Implemented OpenWebUrl methods; updated OpenUri to support forced browser usage.
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs Replaced _context.API.OpenUrl calls with _context.API.OpenWebUrl for URL opening actions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant WebSearchPlugin
    participant PublicAPIInstance
    participant Browser

    User->>WebSearchPlugin: Triggers search or suggestion action
    WebSearchPlugin->>PublicAPIInstance: OpenWebUrl(url)
    PublicAPIInstance->>Browser: Opens url in configured browser (including file://)
Loading

Assessment against linked issues

Objective Addressed Explanation
Support opening local file URLs (file://) in WebSearch plugin (#3608)

Suggested labels

Dev branch only

Suggested reviewers

  • jjw24

Poem

A bunny hops with URLs anew,
Now file links open—yes, it's true!
WebSearch leaps with browser might,
Local files launch just right.
With every click, a rabbit cheers,
For fixes swift and bug-free years!
🐇✨
"""


📜 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 c001041 and f4d6ef3.

📒 Files selected for processing (1)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Flow.Launcher/PublicAPIInstance.cs
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in this 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: 2

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 367bf2c and c001041.

📒 Files selected for processing (3)
  • Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1 hunks)
  • Flow.Launcher/PublicAPIInstance.cs (2 hunks)
  • Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)
Flow.Launcher/PublicAPIInstance.cs (2)
  • OpenWebUrl (422-425)
  • OpenWebUrl (427-430)
Flow.Launcher/PublicAPIInstance.cs (1)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (2)
  • OpenWebUrl (312-312)
  • OpenWebUrl (319-319)
🪛 GitHub Actions: Check Spelling
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

[warning] 210-210: Spell check warning: spefic is not a recognized word. (unrecognized-spelling)


[warning] 364-364: Spell check warning: requerying is not a recognized word. (unrecognized-spelling)

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

[warning] 154-154: Spell check warning: copyurl is not a recognized word. (unrecognized-spelling)

Flow.Launcher/PublicAPIInstance.cs

[warning] 52-52: Spell check warning: Ioc is not a recognized word. (unrecognized-spelling)


[warning] 150-150: Spell check warning: VSTHRD is not a recognized word. (unrecognized-spelling)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: gitStream workflow automation
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: gitStream.cm
  • GitHub Check: build
🔇 Additional comments (4)
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs (1)

308-319: LGTM! Well-designed API addition.

The new OpenWebUrl methods provide a clear and useful distinction from the existing OpenUrl methods. The documentation clearly explains that these methods will force URLs to open in the configured browser, even for local file URLs, which addresses the PR objective perfectly.

The method signatures are consistent with existing patterns and the positioning in the interface is logical.

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

74-74: Perfect adoption of the new API.

Correctly replaces OpenUrl with OpenWebUrl for opening search result URLs. This ensures that search URLs (including local file URLs) will open in the configured browser as intended.


138-138: Correct usage of OpenWebUrl for suggestions.

Properly adopts the new OpenWebUrl method for opening suggestion URLs, maintaining consistency with the search result behavior and ensuring proper browser handling.

Flow.Launcher/PublicAPIInstance.cs (1)

422-430: Implementation logic is correct despite the typo.

The implementation correctly calls OpenUri with the force browser flag set to true, which will ensure URLs open in the configured browser. The logic flow and method signatures are well-designed.

Once the typo is fixed in the OpenUri method, these implementations will work perfectly.

This comment has been minimized.

@@ -390,10 +390,9 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
}
}


private void OpenUri(Uri uri, bool? inPrivate = null)
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrower = false)
Copy link
Member

Choose a reason for hiding this comment

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

Typo brower

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

{
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
if (forceBrower || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
Copy link
Member

Choose a reason for hiding this comment

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

Typo

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

/// Opens the URL using the browser with the given Uri object, even if the URL is a local file.
/// The browser and mode used is based on what's configured in Flow's default browser settings.
/// </summary>
public void OpenWebUrl(Uri url, bool? inPrivate = null);
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need these two in the API, they seem to be the same as the two below

Copy link
Member Author

@Jack251970 Jack251970 Jun 4, 2025

Choose a reason for hiding this comment

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

Please see more information in description

Copy link
Member

Choose a reason for hiding this comment

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

Can you update OpenUri's method and it's summary with the new parameter

Copy link
Member Author

@Jack251970 Jack251970 Jun 4, 2025

Choose a reason for hiding this comment

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

I do not think this is a good idea. I prefer to add a new API function to ensure compatibility.

@jjw24 jjw24 modified the milestones: Future, 1.20.1 Jun 4, 2025
/// The browser and mode used is based on what's configured in Flow's default browser settings.
/// Non-C# plugins should use this method.
/// </summary>
public void OpenWebUrl(string url, bool? inPrivate = null);
Copy link
Member

Choose a reason for hiding this comment

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

This is the same as OpenUrl with string uri parameter, need to differentiate these two. can you mention something like 'Opens the URL using the browser with the given string, even if the URL is a local file, by setting forceBrowser to true on OpenUrl method.'

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 think I have already described this in function summaries.

Opens the URL using the browser with the given Uri object, even if the URL is a local file.

Could you please explain your meaning further?

Copy link
Member Author

@Jack251970 Jack251970 Jun 4, 2025

Choose a reason for hiding this comment

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

And I have no idea about why we need to add forceBrowser. This is the parameter of a private function which should be invisible to developers.

Copy link

github-actions bot commented Jun 4, 2025

@check-spelling-bot Report

🔴 Please review

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

❌ Errors and Warnings Count
❌ forbidden-pattern 22
⚠️ non-alpha-in-dictionary 13

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.

@Jack251970 Jack251970 requested a review from Copilot June 4, 2025 13:42
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 to force URLs (including file:// schemes) to open in the web browser rather than be treated as local files.

  • Switches WebSearch plugin from OpenUrl to OpenWebUrl for query and suggestion actions.
  • Extends PublicAPIInstance with a forceBrowser flag and two OpenWebUrl overloads.
  • Updates IPublicAPI to declare the new OpenWebUrl methods.

Reviewed Changes

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

File Description
Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs Replaced OpenUrl calls with OpenWebUrl to force use of browser.
Flow.Launcher/PublicAPIInstance.cs Added forceBrowser parameter to OpenUri and implemented OpenWebUrl overloads.
Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs Declared new OpenWebUrl methods in the public plugin interface.
Comments suppressed due to low confidence (4)

Flow.Launcher/PublicAPIInstance.cs:393

  • The new forceBrowser parameter lacks XML documentation. Consider adding a <param name="forceBrowser"> tag in the method's XML comments to explain its purpose.
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)

Flow.Launcher/PublicAPIInstance.cs:422

  • These OpenWebUrl overloads are missing XML doc comments. Add <summary> and <param> tags to document what each overload does and the meaning of inPrivate.
public void OpenWebUrl(string url, bool? inPrivate = null)

Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs:74

  • [nitpick] Consider adding a version check or fallback for OpenWebUrl in case the host API hasn't been updated yet, to avoid runtime errors in older versions.
_context.API.OpenWebUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));

Flow.Launcher/PublicAPIInstance.cs:422

  • There are no unit tests covering the new OpenWebUrl overloads. Add tests to verify that URLs (including file:// schemes) are correctly passed through to the default browser.
public void OpenWebUrl(string url, bool? inPrivate = null)

@jjw24 jjw24 added the review in progress Indicates that a review is in progress for this PR label Jun 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 min review bug Something isn't working review in progress Indicates that a review is in progress for this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: WebSearch Url Open Issue
2 participants