Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
Expand All @@ -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;
}

/// <summary>
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
/// Leave browser path blank to use Chrome.
/// </summary>
public static void NewBrowserWindow(this string url, string browserPath = "")
{
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with getting the default browser from user, which could be any browser right, do we know if it will support opening in new window?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works on firefox and chromium-based browsers, and there is a fix for IE a few lines later.... I think this covers pretty much every browser.


var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
Expand Down Expand Up @@ -44,7 +70,9 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
/// </summary>
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))
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/ReportWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Flow.Launcher/SettingWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion Flow.Launcher/ViewModel/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =>
Expand Down