Add NewTab option in viewmodel and partially implement the public api

This commit is contained in:
Kevin Zhang 2021-12-05 01:19:16 -06:00
parent 399c3c9752
commit f97344c994
6 changed files with 38 additions and 7 deletions

View file

@ -8,6 +8,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public string Path { get; set; }
public string PrivateArg { get; set; }
public bool EnablePrivate { get; set; }
public bool OpenInTab { get; set; } = true;
public bool OpenInNewWindow => !OpenInTab;
public bool Editable { get; set; } = true;
public CustomBrowserViewModel Copy()

View file

@ -197,5 +197,8 @@ namespace Flow.Launcher.Plugin
/// <param name="DirectoryPath">Directory Path to open</param>
/// <param name="FileName">Extra FileName Info</param>
public void OpenDirectory(string DirectoryPath, string FileName = null);
public void OpenUrl(string url);
}
}

View file

@ -35,7 +35,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
/// 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 = "", bool inPrivate = false)
{
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
@ -68,7 +68,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
/// <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 = "", bool inPrivate = false)
{
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;
@ -78,7 +78,7 @@ namespace Flow.Launcher.Plugin.SharedCommands
if (!string.IsNullOrEmpty(browserPath))
{
psi.FileName = browserPath;
psi.Arguments = url;
psi.Arguments = url + (inPrivate ? "" : "-inprivate");
}
else
{

View file

@ -182,7 +182,7 @@ namespace Flow.Launcher
public void OpenDirectory(string DirectoryPath, string FileName = null)
{
using Process explorer = new Process();
using var explorer = new Process();
var explorerInfo = _settingsVM.Settings.CustomExplorer;
explorer.StartInfo = new ProcessStartInfo
{
@ -195,6 +195,32 @@ namespace Flow.Launcher
explorer.Start();
}
public void OpenUrl(string url)
{
using var process = new Process();
var browserInfo = _settingsVM.Settings.CustomBrowser;
var path = browserInfo.Path == "Default" ? "" : browserInfo.Path;
if (browserInfo.Path == "Default")
{
if (browserInfo.OpenInTab)
SearchWeb.NewTabInBrowser(url);
else
SearchWeb.NewBrowserWindow(url);
return;
}
var browserStartInfo = new ProcessStartInfo()
{
FileName = browserInfo.Path
};
browserStartInfo.ArgumentList.Add(url);
if(browserInfo.EnablePrivate)
browserStartInfo.ArgumentList.Add(browserInfo.PrivateArg);
}
public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent;
#endregion

View file

@ -121,8 +121,8 @@
HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal">
<RadioButton GroupName="browser" IsChecked="True">New Tab</RadioButton>
<RadioButton GroupName="browser">New Window</RadioButton>
<RadioButton GroupName="browser" IsChecked="{Binding OpenInTab}">New Tab</RadioButton>
<RadioButton GroupName="browser" IsChecked="{Binding OpenInNewWindow, Mode=OneWay}">New Window</RadioButton>
</StackPanel>
<TextBlock Grid.Row="3"
Grid.Column="0"

View file

@ -44,7 +44,7 @@ namespace Flow.Launcher
{
Settings = settings;
CustomBrowsers = new ObservableCollection<CustomBrowserViewModel>(Settings.CustomBrowserList.Select(x => x.Copy()));
SelectedCustomBrowserIndex = Settings.CustomExplorerIndex;
SelectedCustomBrowserIndex = Settings.CustomBrowserIndex;
InitializeComponent();
}