diff --git a/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs new file mode 100644 index 000000000..24584115d --- /dev/null +++ b/Flow.Launcher.Infrastructure/UserSettings/CustomBrowserViewModel.cs @@ -0,0 +1,33 @@ +using Flow.Launcher.Plugin; +using System.Text.Json.Serialization; + +namespace Flow.Launcher.Infrastructure.UserSettings +{ + public class CustomBrowserViewModel : BaseModel + { + public string Name { get; set; } + public string Path { get; set; } + public string PrivateArg { get; set; } + public bool EnablePrivate { get; set; } + public bool OpenInTab { get; set; } = true; + [JsonIgnore] + public bool OpenInNewWindow => !OpenInTab; + public bool Editable { get; set; } = true; + + public CustomBrowserViewModel Copy() + { + return new CustomBrowserViewModel + { + Name = Name, + Path = Path, + OpenInTab = OpenInTab, + PrivateArg = PrivateArg, + EnablePrivate = EnablePrivate, + Editable = Editable + }; + } + } +} + + + diff --git a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs index 6bf9c2ff0..8ecd6dc4b 100644 --- a/Flow.Launcher.Infrastructure/UserSettings/Settings.cs +++ b/Flow.Launcher.Infrastructure/UserSettings/Settings.cs @@ -39,6 +39,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings public string ResultFontWeight { get; set; } public string ResultFontStretch { get; set; } public bool UseGlyphIcons { get; set; } = true; + public bool UseAnimation { get; set; } = true; + public bool UseSound { get; set; } = true; public bool FirstLaunch { get; set; } = true; public int CustomExplorerIndex { get; set; } = 0; @@ -84,8 +86,52 @@ namespace Flow.Launcher.Infrastructure.UserSettings } }; - public bool UseAnimation { get; set; } = true; - public bool UseSound { get; set; } = true; + public int CustomBrowserIndex { get; set; } = 0; + + [JsonIgnore] + public CustomBrowserViewModel CustomBrowser + { + get => CustomBrowserList[CustomBrowserIndex]; + set => CustomBrowserList[CustomBrowserIndex] = value; + } + + public List CustomBrowserList { get; set; } = new() + { + new() + { + Name = "Default", + Path = "*", + PrivateArg = "", + EnablePrivate = false, + Editable = false + }, + new() + { + Name = "Google Chrome", + Path = "chrome", + PrivateArg = "-incognito", + EnablePrivate = false, + Editable = false + }, + new() + { + Name = "Mozilla Firefox", + Path = "firefox", + PrivateArg = "-private", + EnablePrivate = false, + Editable = false + } + , + new() + { + Name = "MS Edge", + Path = "msedge", + PrivateArg = "-inPrivate", + EnablePrivate = false, + Editable = false + } + }; + /// /// when false Alphabet static service will always return empty results diff --git a/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj b/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj index c808052b0..7ce2fc8fd 100644 --- a/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj +++ b/Flow.Launcher.Plugin/Flow.Launcher.Plugin.csproj @@ -14,10 +14,10 @@ - 2.0.0 - 2.0.0 - 2.0.0 - 2.0.0 + 2.1.0 + 2.1.0 + 2.1.0 + 2.1.0 Flow.Launcher.Plugin Flow-Launcher MIT diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index d1444d5db..133ad25a5 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -226,5 +226,10 @@ namespace Flow.Launcher.Plugin /// Directory Path to open /// Extra FileName Info public void OpenDirectory(string DirectoryPath, string FileName = null); + + /// + /// Opens the url. The browser and mode used is based on what's configured in Flow's default browser settings. + /// + public void OpenUrl(string url, bool? inPrivate = null); } } diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 95d057707..6c4ac8ebf 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -35,18 +35,21 @@ 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 OpenInBrowserWindow(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "") { browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; var browserExecutableName = browserPath? - .Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.None) - .Last(); + .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; + var browserArguements = (browserExecutableName == "iexplore.exe" ? "" : "--new-window ") + (inPrivate ? $"{privateArg} " : "") + url; var psi = new ProcessStartInfo { @@ -61,24 +64,36 @@ namespace Flow.Launcher.Plugin.SharedCommands } catch (System.ComponentModel.Win32Exception) { - Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true }); + Process.Start(new ProcessStartInfo + { + FileName = url, UseShellExecute = true + }); } } + [Obsolete("This is provided for backwards compatibility after 1.9.0 release, e.g. GitHub plugin. Use the new method instead")] + public static void NewBrowserWindow(this string url, string browserPath = "") + { + OpenInBrowserWindow(url, browserPath); + } + /// /// 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 OpenInBrowserTab(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "") { browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; - var psi = new ProcessStartInfo() { UseShellExecute = true }; + var psi = new ProcessStartInfo() + { + UseShellExecute = true + }; try { if (!string.IsNullOrEmpty(browserPath)) { psi.FileName = browserPath; - psi.Arguments = url; + psi.Arguments = (inPrivate ? $"{privateArg} " : "") + url; } else { @@ -90,8 +105,17 @@ namespace Flow.Launcher.Plugin.SharedCommands // This error may be thrown if browser path is incorrect catch (System.ComponentModel.Win32Exception) { - Process.Start(new ProcessStartInfo { FileName = url, UseShellExecute = true }); + Process.Start(new ProcessStartInfo + { + FileName = url, UseShellExecute = true + }); } } + + [Obsolete("This is provided for backwards compatibility after 1.9.0 release, e.g. GitHub plugin. Use the new method instead")] + public static void NewTabInBrowser(this string url, string browserPath = "") + { + OpenInBrowserTab(url, browserPath); + } } -} +} \ No newline at end of file diff --git a/Flow.Launcher/Languages/en.xaml b/Flow.Launcher/Languages/en.xaml index 0c6bb05c6..e11cbd5cb 100644 --- a/Flow.Launcher/Languages/en.xaml +++ b/Flow.Launcher/Languages/en.xaml @@ -38,6 +38,8 @@ Disable Flow Launcher activation when a full screen application is active (Recommended for games). Default File Manager Select the file manager to use when opening the folder. + Default Web Browser + Setting for New Tab, New Window, Private Mode. Python Directory Auto Update Select @@ -164,6 +166,16 @@ Arg For Folder Arg For File + + Default Web Browser + The default setting follows the OS default browser setting. If specified separately, flow uses that browser. + Browser + Browser Name + Browser Path + New Window + New Tab + Priviate Mode + Change Priority Greater the number, the higher the result will be ranked. Try setting it as 5. If you want the results to be lower than any other plugin's, provide a negative number diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 6713929d6..5b490bede 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -114,7 +114,7 @@ namespace Flow.Launcher var startInfo = ShellCommand.SetProcessStartInfo(filename, arguments: args, createNoWindow: true); ShellCommand.Execute(startInfo); } - + public void CopyToClipboard(string text) { Clipboard.SetDataObject(text); @@ -196,7 +196,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 { @@ -209,6 +209,23 @@ namespace Flow.Launcher explorer.Start(); } + public void OpenUrl(string url, bool? inPrivate = null) + { + var browserInfo = _settingsVM.Settings.CustomBrowser; + + var path = browserInfo.Path == "*" ? "" : browserInfo.Path; + + if (browserInfo.OpenInTab) + { + url.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + } + else + { + url.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + } + + } + public event FlowLauncherGlobalKeyboardEventHandler GlobalKeyboardEvent; private readonly List> _globalKeyboardHandlers = new(); diff --git a/Flow.Launcher/SelectBrowserWindow.xaml b/Flow.Launcher/SelectBrowserWindow.xaml new file mode 100644 index 000000000..3f0793c53 --- /dev/null +++ b/Flow.Launcher/SelectBrowserWindow.xaml @@ -0,0 +1,264 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + New Tab + New Window + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml index 1ee02fa43..6762ca345 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Views/SettingsControl.xaml @@ -10,71 +10,12 @@ mc:Ignorable="d"> - - - - - - - - - - - - -