diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index b23da730e..95d057707 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -1,3 +1,4 @@ +using Microsoft.Win32; using System; using System.Diagnostics; using System.IO; @@ -7,12 +8,37 @@ namespace Flow.Launcher.Plugin.SharedCommands { public static class SearchWeb { + private static string GetDefaultBrowserPath() + { + string name = string.Empty; + try + { + using var regDefault = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice", false); + var stringDefault = regDefault.GetValue("ProgId"); + + using var regKey = Registry.ClassesRoot.OpenSubKey(stringDefault + "\\shell\\open\\command", false); + name = regKey.GetValue(null).ToString().ToLower().Replace("\"", ""); + + if (!name.EndsWith("exe")) + name = name.Substring(0, name.LastIndexOf(".exe") + 4); + + } + catch + { + return string.Empty; + } + + return name; + } + /// /// Opens search in a new browser. If no browser path is passed in then Chrome is used. /// Leave browser path blank to use Chrome. /// public static void NewBrowserWindow(this string url, string browserPath = "") { + browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; + var browserExecutableName = browserPath? .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) .Last(); @@ -44,7 +70,9 @@ namespace Flow.Launcher.Plugin.SharedCommands /// public static void NewTabInBrowser(this string url, string browserPath = "") { - var psi = new ProcessStartInfo() { UseShellExecute = true}; + browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; + + var psi = new ProcessStartInfo() { UseShellExecute = true }; try { if (!string.IsNullOrEmpty(browserPath)) diff --git a/Flow.Launcher/ReportWindow.xaml.cs b/Flow.Launcher/ReportWindow.xaml.cs index b4e0414ab..7318fe4cd 100644 --- a/Flow.Launcher/ReportWindow.xaml.cs +++ b/Flow.Launcher/ReportWindow.xaml.cs @@ -52,8 +52,8 @@ namespace Flow.Launcher var link = new Hyperlink { IsEnabled = true }; link.Inlines.Add(url); link.NavigateUri = new Uri(url); - link.RequestNavigate += (s, e) => SearchWeb.NewBrowserWindow(e.Uri.ToString()); - link.Click += (s, e) => SearchWeb.NewBrowserWindow(url); + link.RequestNavigate += (s, e) => SearchWeb.NewTabInBrowser(e.Uri.ToString()); + link.Click += (s, e) => SearchWeb.NewTabInBrowser(url); paragraph.Inlines.Add(textBeforeUrl); paragraph.Inlines.Add(link); diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index c38ed4d22..e5583da33 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -229,7 +229,7 @@ namespace Flow.Launcher var uri = new Uri(website); if (Uri.CheckSchemeName(uri.Scheme)) { - SearchWeb.NewBrowserWindow(website); + SearchWeb.NewTabInBrowser(website); } } } @@ -263,7 +263,7 @@ namespace Flow.Launcher private void OnRequestNavigate(object sender, RequestNavigateEventArgs e) { - SearchWeb.NewBrowserWindow(e.Uri.AbsoluteUri); + SearchWeb.NewTabInBrowser(e.Uri.AbsoluteUri); e.Handled = true; } diff --git a/Flow.Launcher/ViewModel/MainViewModel.cs b/Flow.Launcher/ViewModel/MainViewModel.cs index 1f8e72b8c..3d3792c54 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -160,7 +160,7 @@ namespace Flow.Launcher.ViewModel StartHelpCommand = new RelayCommand(_ => { - SearchWeb.NewBrowserWindow("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/"); + SearchWeb.NewTabInBrowser("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/"); }); OpenResultCommand = new RelayCommand(index =>