diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index b23da730ecb..95d05770709 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 @@ public static void NewBrowserWindow(this string url, string browserPath = "") /// 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 b4e0414aba0..7318fe4cd25 100644 --- a/Flow.Launcher/ReportWindow.xaml.cs +++ b/Flow.Launcher/ReportWindow.xaml.cs @@ -52,8 +52,8 @@ private Paragraph Hyperlink(string textBeforeUrl, string url) 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 c38ed4d2294..e5583da338b 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -229,7 +229,7 @@ private void OnPluginNameClick(object sender, MouseButtonEventArgs e) var uri = new Uri(website); if (Uri.CheckSchemeName(uri.Scheme)) { - SearchWeb.NewBrowserWindow(website); + SearchWeb.NewTabInBrowser(website); } } } @@ -263,7 +263,7 @@ private async void OnCheckUpdates(object sender, RoutedEventArgs e) 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 f18b7402279..7a3aa9f2f7f 100644 --- a/Flow.Launcher/ViewModel/MainViewModel.cs +++ b/Flow.Launcher/ViewModel/MainViewModel.cs @@ -136,7 +136,7 @@ private void InitializeKeyCommands() 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 =>