Skip to content

Commit 566b7d3

Browse files
authored
Merge pull request #3616 from Flow-Launcher/force_web_url
Add New API to Force Web Url
2 parents 1415df2 + eb7a892 commit 566b7d3

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,13 +336,28 @@ public interface IPublicAPI
336336
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null);
337337

338338
/// <summary>
339-
/// Opens the URL with the given Uri object.
339+
/// Opens the URL using the browser with the given Uri object, even if the URL is a local file.
340+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
341+
/// </summary>
342+
public void OpenWebUrl(Uri url, bool? inPrivate = null);
343+
344+
/// <summary>
345+
/// Opens the URL using the browser with the given string, even if the URL is a local file.
346+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
347+
/// Non-C# plugins should use this method.
348+
/// </summary>
349+
public void OpenWebUrl(string url, bool? inPrivate = null);
350+
351+
/// <summary>
352+
/// Opens the URL with the given Uri object in browser if scheme is Http or Https.
353+
/// If the URL is a local file, it will instead be opened with the default application for that file type.
340354
/// The browser and mode used is based on what's configured in Flow's default browser settings.
341355
/// </summary>
342356
public void OpenUrl(Uri url, bool? inPrivate = null);
343357

344358
/// <summary>
345-
/// Opens the URL with the given string.
359+
/// Opens the URL with the given string in browser if scheme is Http or Https.
360+
/// If the URL is a local file, it will instead be opened with the default application for that file type.
346361
/// The browser and mode used is based on what's configured in Flow's default browser settings.
347362
/// Non-C# plugins should use this method.
348363
/// </summary>

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -400,10 +400,9 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
400400
}
401401
}
402402

403-
404-
private void OpenUri(Uri uri, bool? inPrivate = null)
403+
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
405404
{
406-
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
405+
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
407406
{
408407
var browserInfo = _settings.CustomBrowser;
409408

@@ -444,6 +443,16 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
444443
}
445444
}
446445

446+
public void OpenWebUrl(string url, bool? inPrivate = null)
447+
{
448+
OpenUri(new Uri(url), inPrivate, true);
449+
}
450+
451+
public void OpenWebUrl(Uri url, bool? inPrivate = null)
452+
{
453+
OpenUri(url, inPrivate, true);
454+
}
455+
447456
public void OpenUrl(string url, bool? inPrivate = null)
448457
{
449458
OpenUri(new Uri(url), inPrivate);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
7171
Score = score,
7272
Action = c =>
7373
{
74-
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
74+
_context.API.OpenWebUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
7575

7676
return true;
7777
},
@@ -135,7 +135,7 @@ private async Task<IEnumerable<Result>> SuggestionsAsync(string keyword, string
135135
ActionKeywordAssigned = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? string.Empty : searchSource.ActionKeyword,
136136
Action = c =>
137137
{
138-
_context.API.OpenUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
138+
_context.API.OpenWebUrl(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
139139

140140
return true;
141141
},

0 commit comments

Comments
 (0)