Skip to content

Commit df3a9a4

Browse files
authored
Use default system browser (#214)
1 parent ad234b6 commit df3a9a4

File tree

4 files changed

+34
-6
lines changed

4 files changed

+34
-6
lines changed

Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Microsoft.Win32;
12
using System;
23
using System.Diagnostics;
34
using System.IO;
@@ -7,12 +8,37 @@ namespace Flow.Launcher.Plugin.SharedCommands
78
{
89
public static class SearchWeb
910
{
11+
private static string GetDefaultBrowserPath()
12+
{
13+
string name = string.Empty;
14+
try
15+
{
16+
using var regDefault = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
17+
var stringDefault = regDefault.GetValue("ProgId");
18+
19+
using var regKey = Registry.ClassesRoot.OpenSubKey(stringDefault + "\\shell\\open\\command", false);
20+
name = regKey.GetValue(null).ToString().ToLower().Replace("\"", "");
21+
22+
if (!name.EndsWith("exe"))
23+
name = name.Substring(0, name.LastIndexOf(".exe") + 4);
24+
25+
}
26+
catch
27+
{
28+
return string.Empty;
29+
}
30+
31+
return name;
32+
}
33+
1034
/// <summary>
1135
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
1236
/// Leave browser path blank to use Chrome.
1337
/// </summary>
1438
public static void NewBrowserWindow(this string url, string browserPath = "")
1539
{
40+
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
41+
1642
var browserExecutableName = browserPath?
1743
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
1844
.Last();
@@ -44,7 +70,9 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
4470
/// </summary>
4571
public static void NewTabInBrowser(this string url, string browserPath = "")
4672
{
47-
var psi = new ProcessStartInfo() { UseShellExecute = true};
73+
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
74+
75+
var psi = new ProcessStartInfo() { UseShellExecute = true };
4876
try
4977
{
5078
if (!string.IsNullOrEmpty(browserPath))

Flow.Launcher/ReportWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ private Paragraph Hyperlink(string textBeforeUrl, string url)
5252
var link = new Hyperlink { IsEnabled = true };
5353
link.Inlines.Add(url);
5454
link.NavigateUri = new Uri(url);
55-
link.RequestNavigate += (s, e) => SearchWeb.NewBrowserWindow(e.Uri.ToString());
56-
link.Click += (s, e) => SearchWeb.NewBrowserWindow(url);
55+
link.RequestNavigate += (s, e) => SearchWeb.NewTabInBrowser(e.Uri.ToString());
56+
link.Click += (s, e) => SearchWeb.NewTabInBrowser(url);
5757

5858
paragraph.Inlines.Add(textBeforeUrl);
5959
paragraph.Inlines.Add(link);

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ private void OnPluginNameClick(object sender, MouseButtonEventArgs e)
229229
var uri = new Uri(website);
230230
if (Uri.CheckSchemeName(uri.Scheme))
231231
{
232-
SearchWeb.NewBrowserWindow(website);
232+
SearchWeb.NewTabInBrowser(website);
233233
}
234234
}
235235
}
@@ -263,7 +263,7 @@ private async void OnCheckUpdates(object sender, RoutedEventArgs e)
263263

264264
private void OnRequestNavigate(object sender, RequestNavigateEventArgs e)
265265
{
266-
SearchWeb.NewBrowserWindow(e.Uri.AbsoluteUri);
266+
SearchWeb.NewTabInBrowser(e.Uri.AbsoluteUri);
267267
e.Handled = true;
268268
}
269269

Flow.Launcher/ViewModel/MainViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private void InitializeKeyCommands()
136136

137137
StartHelpCommand = new RelayCommand(_ =>
138138
{
139-
SearchWeb.NewBrowserWindow("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/");
139+
SearchWeb.NewTabInBrowser("https://github.com/Flow-Launcher/Flow.Launcher/wiki/Flow-Launcher/");
140140
});
141141

142142
OpenResultCommand = new RelayCommand(index =>

0 commit comments

Comments
 (0)