2019-08-21 06:30:18 +08:00
|
|
|
using System;
|
2019-08-06 19:27:54 +08:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
|
2019-08-06 19:58:46 +08:00
|
|
|
namespace Wox.Plugin.SharedCommands
|
2019-08-06 19:27:54 +08:00
|
|
|
{
|
2019-08-06 19:58:46 +08:00
|
|
|
public static class SearchWeb
|
2019-08-06 19:27:54 +08:00
|
|
|
{
|
2019-11-10 16:12:43 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Opens search in a new browser. If no browser path is passed in then Chrome is used.
|
2019-08-06 19:27:54 +08:00
|
|
|
/// Leave browser path blank to use Chrome.
|
|
|
|
/// </summary>
|
2019-11-10 17:12:45 +08:00
|
|
|
public static void NewBrowserWindow(this string url, string browserPath)
|
2019-08-06 19:27:54 +08:00
|
|
|
{
|
|
|
|
var browserExecutableName = browserPath?
|
|
|
|
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
|
|
|
|
.Last();
|
|
|
|
|
2019-11-10 17:12:45 +08:00
|
|
|
var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath;
|
2019-08-06 19:27:54 +08:00
|
|
|
|
|
|
|
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
|
2019-11-10 17:12:45 +08:00
|
|
|
var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url;
|
2019-08-06 19:27:54 +08:00
|
|
|
|
2019-11-10 17:12:45 +08:00
|
|
|
try
|
|
|
|
{
|
|
|
|
Process.Start(browser, browserArguements);
|
|
|
|
}
|
|
|
|
catch (System.ComponentModel.Win32Exception)
|
|
|
|
{
|
|
|
|
Process.Start(url);
|
|
|
|
}
|
2019-11-10 16:12:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Opens search as a tab in the default browser chosen in Windows settings.
|
|
|
|
/// </summary>
|
|
|
|
public static void NewTabInBrowser(this string url, string browserPath)
|
|
|
|
{
|
2019-08-21 06:30:18 +08:00
|
|
|
try
|
|
|
|
{
|
2019-11-10 17:15:14 +08:00
|
|
|
if (!string.IsNullOrEmpty(browserPath))
|
|
|
|
{
|
|
|
|
Process.Start(browserPath, url);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Process.Start(url);
|
|
|
|
}
|
2019-08-21 06:30:18 +08:00
|
|
|
}
|
2019-11-10 17:15:14 +08:00
|
|
|
// This error may be thrown for Process.Start(browserPath, url)
|
2019-08-21 06:30:18 +08:00
|
|
|
catch (System.ComponentModel.Win32Exception)
|
|
|
|
{
|
|
|
|
Process.Start(url);
|
|
|
|
}
|
2019-08-06 19:27:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|