Skip to content

Commit f721f29

Browse files
committed
Merge pull request #3616 from Flow-Launcher/force_web_url
Add New API to Force Web Url
1 parent 81f79e2 commit f721f29

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
@@ -306,13 +306,28 @@ public interface IPublicAPI
306306
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null);
307307

308308
/// <summary>
309-
/// Opens the URL with the given Uri object.
309+
/// Opens the URL using the browser with the given Uri object, even if the URL is a local file.
310+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
311+
/// </summary>
312+
public void OpenWebUrl(Uri url, bool? inPrivate = null);
313+
314+
/// <summary>
315+
/// Opens the URL using the browser with the given string, even if the URL is a local file.
316+
/// The browser and mode used is based on what's configured in Flow's default browser settings.
317+
/// Non-C# plugins should use this method.
318+
/// </summary>
319+
public void OpenWebUrl(string url, bool? inPrivate = null);
320+
321+
/// <summary>
322+
/// Opens the URL with the given Uri object in browser if scheme is Http or Https.
323+
/// If the URL is a local file, it will instead be opened with the default application for that file type.
310324
/// The browser and mode used is based on what's configured in Flow's default browser settings.
311325
/// </summary>
312326
public void OpenUrl(Uri url, bool? inPrivate = null);
313327

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

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,9 @@ public void OpenDirectory(string directoryPath, string fileNameOrFilePath = null
389389
}
390390
}
391391

392-
393-
private void OpenUri(Uri uri, bool? inPrivate = null)
392+
private void OpenUri(Uri uri, bool? inPrivate = null, bool forceBrowser = false)
394393
{
395-
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
394+
if (forceBrowser || uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
396395
{
397396
var browserInfo = _settings.CustomBrowser;
398397

@@ -433,6 +432,16 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
433432
}
434433
}
435434

435+
public void OpenWebUrl(string url, bool? inPrivate = null)
436+
{
437+
OpenUri(new Uri(url), inPrivate, true);
438+
}
439+
440+
public void OpenWebUrl(Uri url, bool? inPrivate = null)
441+
{
442+
OpenUri(url, inPrivate, true);
443+
}
444+
436445
public void OpenUrl(string url, bool? inPrivate = null)
437446
{
438447
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)