From 96cf9fe36a02326162520a02cfea26a428ad22a6 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 31 Jan 2022 21:36:13 +1100 Subject: [PATCH 1/2] fix application URI logic when opening via WebSearch plugin --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 5 ++-- Flow.Launcher/PublicAPIInstance.cs | 23 ++++++++----------- .../Flow.Launcher.Plugin.WebSearch/Main.cs | 5 ++-- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 986710ab8cb..3bef9c1369d 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -228,12 +228,13 @@ public interface IPublicAPI public void OpenDirectory(string DirectoryPath, string FileName = null); /// - /// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings. + /// Opens the URL. The browser and mode used is based on what's configured in Flow's default browser settings. + /// Also supports application URIs e.g. obsidian://search-query-example /// public void OpenUrl(string url, bool? inPrivate = null); /// - /// Opens the application URI. + /// Opens the application URI, e.g. obsidian://search-query-example /// public void OpenAppUri(string appUri); } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index e3b7de31d5a..894709b06f4 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -209,7 +209,7 @@ public void OpenDirectory(string DirectoryPath, string FileName = null) explorer.Start(); } - public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false) + private void OpenUri(string url, bool? inPrivate = null) { var uri = new Uri(url); if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) @@ -230,18 +230,7 @@ public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false) return; } - if (isAppUri) - { - Process.Start(new ProcessStartInfo() - { - FileName = url, - UseShellExecute = true - })?.Dispose(); - - return; - } - - throw new InvalidOperationException("URI scheme not specified or supported "); + OpenAppUri(url); } public void OpenUrl(string url, bool? inPrivate = null) @@ -251,7 +240,13 @@ public void OpenUrl(string url, bool? inPrivate = null) public void OpenAppUri(string appUri) { - OpenUri(appUri, isAppUri: true); + Process.Start(new ProcessStartInfo() + { + FileName = appUri, + UseShellExecute = true + })?.Dispose(); + + return; } public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; diff --git a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs index 2ed41213008..b136e3b8b46 100644 --- a/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.WebSearch/Main.cs @@ -49,9 +49,10 @@ public async Task> QueryAsync(Query query, CancellationToken token) var title = keyword; string subtitle = _context.API.GetTranslation("flowlauncher_plugin_websearch_search") + " " + searchSource.Title; - //Action Keyword match apear on top + // Action Keyword match apear on top var score = searchSource.ActionKeyword == SearchSourceGlobalPluginWildCardSign ? scoreStandard : scoreStandard + 1; + // This populates the associated action keyword search entry if (string.IsNullOrEmpty(keyword)) { var result = new Result @@ -61,6 +62,7 @@ public async Task> QueryAsync(Query query, CancellationToken token) IcoPath = searchSource.IconPath, Score = score }; + results.Add(result); } else @@ -93,7 +95,6 @@ public async Task> QueryAsync(Query query, CancellationToken token) if (token.IsCancellationRequested) return null; - } return results; From 95ef8bb4589dcf5d7136d5751b6629c78ffb5047 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Fri, 4 Feb 2022 08:26:42 +1100 Subject: [PATCH 2/2] add overload for using Uri object --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 19 +++++++++-- Flow.Launcher/PublicAPIInstance.cs | 33 ++++++++++++------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 3bef9c1369d..69057820ef8 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -228,13 +228,26 @@ public interface IPublicAPI public void OpenDirectory(string DirectoryPath, string FileName = null); /// - /// Opens the URL. The browser and mode used is based on what's configured in Flow's default browser settings. - /// Also supports application URIs e.g. obsidian://search-query-example + /// 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. + /// + public void OpenUrl(Uri url, bool? inPrivate = null); + + /// + /// Opens the URL with the given string. + /// The browser and mode used is based on what's configured in Flow's default browser settings. + /// Non-C# plugins should use this method. /// public void OpenUrl(string url, bool? inPrivate = null); /// - /// Opens the application URI, e.g. obsidian://search-query-example + /// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example + /// + public void OpenAppUri(Uri appUri); + + /// + /// Opens the application URI with the given string, e.g. obsidian://search-query-example + /// Non-C# plugins should use this method /// public void OpenAppUri(string appUri); } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 894709b06f4..81f7a238965 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -209,9 +209,8 @@ public void OpenDirectory(string DirectoryPath, string FileName = null) explorer.Start(); } - private void OpenUri(string url, bool? inPrivate = null) + private void OpenUri(Uri uri, bool? inPrivate = null) { - var uri = new Uri(url); if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) { var browserInfo = _settingsVM.Settings.CustomBrowser; @@ -220,33 +219,43 @@ private void OpenUri(string url, bool? inPrivate = null) if (browserInfo.OpenInTab) { - url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); } else { - url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); } + } + else + { + Process.Start(new ProcessStartInfo() + { + FileName = uri.AbsoluteUri, + UseShellExecute = true + })?.Dispose(); return; } - - OpenAppUri(url); } public void OpenUrl(string url, bool? inPrivate = null) + { + OpenUri(new Uri(url), inPrivate); + } + + public void OpenUrl(Uri url, bool? inPrivate = null) { OpenUri(url, inPrivate); } public void OpenAppUri(string appUri) { - Process.Start(new ProcessStartInfo() - { - FileName = appUri, - UseShellExecute = true - })?.Dispose(); + OpenUri(new Uri(appUri)); + } - return; + public void OpenAppUri(Uri appUri) + { + OpenUri(appUri); } public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;