Mini refactor

Move Process.Start to static class level
This commit is contained in:
Jeremy Wu
2019-08-04 11:42:08 +10:00
parent 977d21c929
commit cb4fde9a0b
3 changed files with 32 additions and 2 deletions

View File

@@ -0,0 +1,27 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace Wox.Plugin.WebSearch.Commands
{
internal static class SearchWeb
{
/// <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>
internal static void NewBrowserWindow(this string url, string browserPath)
{
var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
.Last();
var browser = string.IsNullOrEmpty(browserExecutableName) ? "chrome" : browserPath;
// Internet Explorer will open url in new browser window, and does not take the --new-window parameter
var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url;
Process.Start(browser, browserArguements);
}
}
}

View File

@@ -8,6 +8,7 @@ using System.Threading.Tasks;
using System.Windows.Controls;
using Wox.Infrastructure;
using Wox.Infrastructure.Storage;
using Wox.Plugin.WebSearch.Commands;
namespace Wox.Plugin.WebSearch
{
@@ -72,7 +73,8 @@ namespace Wox.Plugin.WebSearch
IcoPath = searchSource.IconPath,
Action = c =>
{
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)));
searchSource.Url.Replace("{q}", Uri.EscapeDataString(keyword)).NewBrowserWindow("");
return true;
}
};
@@ -123,7 +125,7 @@ namespace Wox.Plugin.WebSearch
IcoPath = searchSource.IconPath,
Action = c =>
{
Process.Start(searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)));
searchSource.Url.Replace("{q}", Uri.EscapeDataString(o)).NewBrowserWindow("");
return true;
}
});

View File

@@ -58,6 +58,7 @@
<Compile Include="..\..\SolutionAssemblyInfo.cs">
<Link>Properties\SolutionAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Commands\SearchWeb.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SearchSourceViewModel.cs" />
<Compile Include="SettingsViewModel.cs" />