Merge remote-tracking branch 'upstream/dev' into RenderImprovement

This commit is contained in:
弘韬 张 2020-11-22 19:09:46 +08:00
commit 8f6f2fbf6f
4 changed files with 34 additions and 6 deletions

View file

@ -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;
}
/// <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;
var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
@ -44,7 +70,9 @@ namespace Flow.Launcher.Plugin.SharedCommands
/// </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))

View file

@ -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);

View file

@ -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;
}

View file

@ -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 =>