From 1ec3674d91edca928a97a4842a42fa1b8a73e726 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 18 Nov 2020 10:43:39 +0800 Subject: [PATCH 1/4] Get default browser path when the browser path is empty. --- .../SharedCommands/SearchWeb.cs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index b23da730ecb..0fdd0e21579 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -1,18 +1,45 @@ +using Microsoft.Win32; using System; using System.Diagnostics; using System.IO; using System.Linq; + namespace Flow.Launcher.Plugin.SharedCommands { public static class SearchWeb { + private static string GetDefaultBrowserPath() + { + string name = string.Empty; + try + { + var regDefault = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.htm\\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("" + (char)34, ""); + + 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 +71,10 @@ 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)) From 0e4735eabfb811ecb5b2b350901bb144419c6cf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Wed, 18 Nov 2020 22:01:36 +0800 Subject: [PATCH 2/4] Use NewTab opening for link in the setting instead of new window --- Flow.Launcher/SettingWindow.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Flow.Launcher/SettingWindow.xaml.cs b/Flow.Launcher/SettingWindow.xaml.cs index c38ed4d2294..cdb751bfedc 100644 --- a/Flow.Launcher/SettingWindow.xaml.cs +++ b/Flow.Launcher/SettingWindow.xaml.cs @@ -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; } From 0acfd02680ba5f42bcd3baff9ebbffbd16a16794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Thu, 19 Nov 2020 08:30:13 +0800 Subject: [PATCH 3/4] Use NewTabInBrowser as default in most setting hyperlink, and change the way of getting default browser --- Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs | 4 ++-- Flow.Launcher/ReportWindow.xaml.cs | 4 ++-- Flow.Launcher/SettingWindow.xaml.cs | 2 +- Flow.Launcher/ViewModel/MainViewModel.cs | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 0fdd0e21579..39cd19d91d8 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -14,11 +14,11 @@ private static string GetDefaultBrowserPath() string name = string.Empty; try { - var regDefault = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\FileExts\\.htm\\UserChoice", false); + 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("" + (char)34, ""); + name = regKey.GetValue(null).ToString().ToLower().Replace("\"", ""); if (!name.EndsWith("exe")) name = name.Substring(0, name.LastIndexOf(".exe") + 4); 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 cdb751bfedc..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); } } } 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 => From 8c151c0837a3d352f01040d6b1cff0aecf92e8f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=98=E9=9F=AC=20=E5=BC=A0?= Date: Fri, 20 Nov 2020 10:06:33 +0800 Subject: [PATCH 4/4] remove extra space --- Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 39cd19d91d8..95d05770709 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; - namespace Flow.Launcher.Plugin.SharedCommands { public static class SearchWeb @@ -73,7 +72,6 @@ public static void NewTabInBrowser(this string url, string browserPath = "") { browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; - var psi = new ProcessStartInfo() { UseShellExecute = true }; try {