Skip to content

Commit

Permalink
Fix opening web/url/bookmarks in new window and tab
Browse files Browse the repository at this point in the history
Functionality broken after the upgrade
  • Loading branch information
jjw24 committed Apr 17, 2020
1 parent eb1844b commit 98758f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Plugins/Wox.Plugin.WebSearch/SettingsControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SelectedItem="{Binding Settings.SelectedSuggestion}"
IsEnabled="{Binding ElementName=EnableSuggestion, Path=IsChecked}" Margin="10,3,10,10" />
<!-- Not sure why binding IsEnabled directly to Settings.EnableWebSaerchSuggestion is not working -->
<Label Content="Open search in:" Margin="40 3 0 8"/>
<Label Content="Open search in:" Margin="30 3 0 8"/>
<RadioButton Name="NewWindowBrowser" GroupName="OpenSearchBehaviour" Content="New window" Click="OnNewBrowserWindowClick" Margin="10" />
<RadioButton Name="NewTabInBrowser" GroupName="OpenSearchBehaviour" Content="New tab" Click="OnNewTabClick" Margin="10" />
</StackPanel>
Expand Down
32 changes: 19 additions & 13 deletions Wox.Plugin/SharedCommands/SearchWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class SearchWeb
/// 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)
public static void NewBrowserWindow(this string url, string browserPath = "")
{
var browserExecutableName = browserPath?
.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None)
Expand All @@ -22,41 +22,47 @@ public static void NewBrowserWindow(this string url, string 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;

var psi = new ProcessStartInfo
{
FileName = browser,
Arguments = browserArguements,
UseShellExecute = true
};

try
{
Process.Start(browser, browserArguements);
Process.Start(psi);
}
catch (System.ComponentModel.Win32Exception)
{
var psi = new ProcessStartInfo
{
FileName = url,
UseShellExecute = true
};
Process.Start(psi);
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
}
}

/// <summary>
/// Opens search as a tab in the default browser chosen in Windows settings.
/// </summary>
public static void NewTabInBrowser(this string url, string browserPath)
public static void NewTabInBrowser(this string url, string browserPath = "")
{
var psi = new ProcessStartInfo() { UseShellExecute = true};
try
{
if (!string.IsNullOrEmpty(browserPath))
{
Process.Start(browserPath, url);
psi.FileName = browserPath;
psi.Arguments = url;
}
else
{
Process.Start(url);
psi.FileName = url;
}

Process.Start(psi);
}
// This error may be thrown for Process.Start(browserPath, url)
// This error may be thrown if browser path is incorrect
catch (System.ComponentModel.Win32Exception)
{
Process.Start(url);
Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true });
}
}
}
Expand Down

0 comments on commit 98758f6

Please sign in to comment.