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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
Task<string> HttpGetStringAsync(string url, CancellationToken token = default);

/// <summary>
/// Http download the spefic url and return as stream

Check warning on line 210 in Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`spefic` is not a recognized word. (unrecognized-spelling)
/// </summary>
/// <param name="url">URL to call Http Get</param>
/// <param name="token">Cancellation Token</param>
Expand Down Expand Up @@ -305,6 +305,19 @@
/// <param name="FileNameOrFilePath">Extra FileName Info</param>
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null);

/// <summary>
/// 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.


/// <summary>
/// Opens the URL using the browser with the given string, 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.
/// 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.


/// <summary>
/// Opens the URL with the given Uri object.
/// The browser and mode used is based on what's configured in Flow's default browser settings.
Expand Down Expand Up @@ -348,7 +361,7 @@

/// <summary>
/// Reloads the query.
/// When current results are from context menu or history, it will go back to query results before requerying.

Check warning on line 364 in Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`requerying` is not a recognized word. (unrecognized-spelling)
/// </summary>
/// <param name="reselect">Choose the first result after reload if true; keep the last selected result if false. Default is true.</param>
public void ReQuery(bool reselect = true);
Expand Down
15 changes: 12 additions & 3 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

// Must use getter to avoid circular dependency
private Updater _updater;
private Updater Updater => _updater ??= Ioc.Default.GetRequiredService<Updater>();

Check warning on line 52 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`Ioc` is not a recognized word. (unrecognized-spelling)

private readonly object _saveSettingsLock = new();

Expand Down Expand Up @@ -147,7 +147,7 @@
ShellCommand.Execute(startInfo);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("Usage", "VSTHRD100:Avoid async void methods", Justification = "<Pending>")]

Check warning on line 150 in Flow.Launcher/PublicAPIInstance.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`VSTHRD` is not a recognized word. (unrecognized-spelling)
public async void CopyToClipboard(string stringToCopy, bool directCopy = false, bool showDefaultNotification = true)
{
if (string.IsNullOrEmpty(stringToCopy))
Expand Down Expand Up @@ -390,10 +390,9 @@
}
}


private void OpenUri(Uri uri, bool? inPrivate = null)
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
{
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
{
var browserInfo = _settings.CustomBrowser;

Expand All @@ -420,6 +419,16 @@
}
}

public void OpenWebUrl(string url, bool? inPrivate = null)
{
OpenUri(new Uri(url), inPrivate, true);
}

public void OpenWebUrl(Uri url, bool? inPrivate = null)
{
OpenUri(url, inPrivate, true);
}

public void OpenUrl(string url, bool? inPrivate = null)
{
OpenUri(new Uri(url), inPrivate);
Expand Down
4 changes: 2 additions & 2 deletions Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
Score = score,
Action = c =>
{
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
_context.API.OpenWebUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));

return true;
},
Expand Down Expand Up @@ -135,7 +135,7 @@
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
Action = c =>
{
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
_context.API.OpenWebUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));

return true;
},
Expand All @@ -151,7 +151,7 @@
new Result
{
Title = _context.API.GetTranslation("flowlauncher_plugin_websearch_copyurl_title"),
SubTitle = _context.API.GetTranslation("flowlauncher_plugin_websearch_copyurl_subtitle"),

Check warning on line 154 in Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs

View workflow job for this annotation

GitHub Actions / Check Spelling

`copyurl` is not a recognized word. (unrecognized-spelling)
IcoPath = "Images/copylink.png",
Action = c =>
{
Expand Down
Loading