From f97344c994c1ceba3929109f76200bf5186aca9f Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Sun, 5 Dec 2021 01:19:16 -0600 Subject: [PATCH] Add NewTab option in viewmodel and partially implement the public api --- .../UserSettings/CustomBrowserViewModel.cs | 2 ++ Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs | 3 ++ .../SharedCommands/SearchWeb.cs | 6 ++-- Flow.Launcher/PublicAPIInstance.cs | 28 ++++++++++++++++++- Flow.Launcher/SelectBrowserWindow.xaml | 4 +-- Flow.Launcher/SelectBrowserWindow.xaml.cs | 2 +- 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs index 45cd50385..7ce1dd656 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs @@ -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() diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index 3abdaf01f..da2f9a3eb 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -197,5 +197,8 @@ namespace Flow.Launcher.Plugin /// Directory Path to open /// Extra FileName Info public void OpenDirectory(string DirectoryPath, string FileName = null); + + + public void OpenUrl(string url); } } diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 95d057707..5743181ed 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -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. /// - 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 /// /// Opens search as a tab in the default browser chosen in Windows settings. /// - 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 { diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index e90a53fc3..2b2306577 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -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 diff --git a/Flow.Launcher/SelectBrowserWindow.xaml b/Flow.Launcher/SelectBrowserWindow.xaml index 09828737e..a4ea4701a 100644 --- a/Flow.Launcher/SelectBrowserWindow.xaml +++ b/Flow.Launcher/SelectBrowserWindow.xaml @@ -121,8 +121,8 @@ HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal"> - New Tab - New Window + New Tab + New Window (Settings.CustomBrowserList.Select(x => x.Copy())); - SelectedCustomBrowserIndex = Settings.CustomExplorerIndex; + SelectedCustomBrowserIndex = Settings.CustomBrowserIndex; InitializeComponent(); }