Merge pull request #3616 from Flow-Launcher/force_web_url

Add New API to Force Web Url
This commit is contained in:
Jeremy Wu 2025-06-14 20:14:58 +10:00 committed by GitHub
commit 566b7d3f0a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 31 additions and 7 deletions

View file

@ -336,13 +336,28 @@ namespace Flow.Launcher.Plugin
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null);
/// <summary>
/// Opens the URL with the given Uri object.
/// 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);
/// <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);
/// <summary>
/// Opens the URL with the given Uri object in browser if scheme is Http or Https.
/// If the URL is a local file, it will instead be opened with the default application for that file type.
/// The browser and mode used is based on what's configured in Flow's default browser settings.
/// </summary>
public void OpenUrl(Uri url, bool? inPrivate = null);
/// <summary>
/// Opens the URL with the given string.
/// Opens the URL with the given string in browser if scheme is Http or Https.
/// If the URL is a local file, it will instead be opened with the default application for that file type.
/// 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>

View file

@ -400,10 +400,9 @@ namespace Flow.Launcher
}
}
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;
@ -444,6 +443,16 @@ namespace Flow.Launcher
}
}
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);

View file

@ -71,7 +71,7 @@ namespace Flow.Launcher.Plugin.WebSearch
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;
},
@ -135,7 +135,7 @@ namespace Flow.Launcher.Plugin.WebSearch
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;
},