Reverse out common open browser call and update open browser in tab

This commit is contained in:
Jeremy Wu 2019-11-10 20:15:14 +11:00
parent 3e292d7604
commit adb2582856

View File

@ -36,22 +36,19 @@ namespace Wox.Plugin.SharedCommands
/// Opens search as a tab in the default browser chosen in Windows settings.
/// </summary>
public static void NewTabInBrowser(this string url, string browserPath)
{
var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
var selectedBrowserPath = string.IsNullOrEmpty(browserExecutableName) ? "" : browserPath;
OpenWebSearch(selectedBrowserPath, "", url);
}
private static void OpenWebSearch(string chosenBrowser, string browserArguements, string url)
{
try
{
Process.Start(chosenBrowser, browserArguements + url);
if (!string.IsNullOrEmpty(browserPath))
{
Process.Start(browserPath, url);
}
else
{
Process.Start(url);
}
}
// This error may be thrown for Process.Start(browserPath, url)
catch (System.ComponentModel.Win32Exception)
{
Process.Start(url);