From 32107dbece1209cea28e46616f89bdf364cf0e4b Mon Sep 17 00:00:00 2001 From: Hongtao Zhang Date: Sun, 9 Jan 2022 12:30:57 -0600 Subject: [PATCH 1/3] Support application uri --- .../SharedCommands/SearchWeb.cs | 4 +-- Flow.Launcher/PublicAPIInstance.cs | 31 ++++++++++++------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 6c4ac8ebf0a..6588132b940 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -60,7 +60,7 @@ public static void OpenInBrowserWindow(this string url, string browserPath = "", try { - Process.Start(psi); + Process.Start(psi)?.Dispose(); } catch (System.ComponentModel.Win32Exception) { @@ -100,7 +100,7 @@ public static void OpenInBrowserTab(this string url, string browserPath = "", bo psi.FileName = url; } - Process.Start(psi); + Process.Start(psi)?.Dispose(); } // This error may be thrown if browser path is incorrect catch (System.ComponentModel.Win32Exception) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 5b490bede72..20d1b8de2b7 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -211,19 +211,28 @@ public void OpenDirectory(string DirectoryPath, string FileName = null) public void OpenUrl(string url, bool? inPrivate = null) { - var browserInfo = _settingsVM.Settings.CustomBrowser; - - var path = browserInfo.Path == "*" ? "" : browserInfo.Path; - - if (browserInfo.OpenInTab) + var uri = new Uri(url); + if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) { - url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); - } - else - { - url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + var browserInfo = _settingsVM.Settings.CustomBrowser; + + var path = browserInfo.Path == "*" ? "" : browserInfo.Path; + + if (browserInfo.OpenInTab) + { + url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + } + else + { + url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + } + return; } + Process.Start(new ProcessStartInfo() + { + FileName = url, UseShellExecute = true + })?.Dispose(); } public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; @@ -254,4 +263,4 @@ private bool KListener_hookedKeyboardCallback(KeyEvent keyevent, int vkcode, Spe #endregion } -} +} \ No newline at end of file From 3188bd82c0f4bdef33f039705f8790961d784321 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 31 Jan 2022 08:34:02 +1100 Subject: [PATCH 2/3] add OpenUri to interface and change OpenUrl method to OpenUri --- Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 5 ++++ Flow.Launcher/PublicAPIInstance.cs | 26 ++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 133ad25a5cf..986710ab8cb 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -231,5 +231,10 @@ public interface IPublicAPI /// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings. /// public void OpenUrl(string url, bool? inPrivate = null); + + /// + /// Opens the application URI. + /// + public void OpenAppUri(string appUri); } } diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 20d1b8de2b7..f22eb73c091 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 OpenUrl(string url, bool? inPrivate = null) + public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false) { var uri = new Uri(url); if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) @@ -229,10 +229,28 @@ public void OpenUrl(string url, bool? inPrivate = null) return; } - Process.Start(new ProcessStartInfo() + if (isAppUri) { - FileName = url, UseShellExecute = true - })?.Dispose(); + Process.Start(new ProcessStartInfo() + { + FileName = url, + UseShellExecute = true + })?.Dispose(); + + return; + } + + throw new InvalidOperationException("URI scheme not specifiedor supported "); + } + + public void OpenUrl(string url, bool? inPrivate = null) + { + OpenUri(url, inPrivate); + } + + public void OpenAppUri(string appUri) + { + OpenUri(appUri, isAppUri: true); } public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; From ef194d00977e7a40309ca9d212f8ceab18ca2647 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Mon, 31 Jan 2022 08:37:04 +1100 Subject: [PATCH 3/3] formatting --- Flow.Launcher/PublicAPIInstance.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index f22eb73c091..e3b7de31d5a 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -226,6 +226,7 @@ public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false) { url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); } + return; } @@ -240,7 +241,7 @@ public void OpenUri(string url, bool? inPrivate = null, bool isAppUri = false) return; } - throw new InvalidOperationException("URI scheme not specifiedor supported "); + throw new InvalidOperationException("URI scheme not specified or supported "); } public void OpenUrl(string url, bool? inPrivate = null)