diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index 78ae8476bc6..aedfa0804a8 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -95,3 +95,4 @@ keyevent KListener requery vkcode +Firefox diff --git a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs index d9cf68469ec..a805dc93b38 100644 --- a/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs +++ b/Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs @@ -240,14 +240,14 @@ public interface IPublicAPI /// Opens the URL with the given Uri object. /// The browser and mode used is based on what's configured in Flow's default browser settings. /// - public void OpenUrl(Uri url, bool? inPrivate = null); - + public void OpenUrl(Uri url, bool? inPrivate = null, string additionalArgs = ""); + /// /// Opens the URL with the given string. /// The browser and mode used is based on what's configured in Flow's default browser settings. /// Non-C# plugins should use this method. /// - public void OpenUrl(string url, bool? inPrivate = null); + public void OpenUrl(string url, bool? inPrivate = null, string additionalArgs = ""); /// /// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example diff --git a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs index 6588132b940..15a8c75fad4 100644 --- a/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs +++ b/Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Microsoft.Win32; using System; using System.Diagnostics; using System.IO; @@ -35,7 +35,7 @@ private static string GetDefaultBrowserPath() /// 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 OpenInBrowserWindow(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "") + public static void OpenInBrowserWindow(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "", string additionalArgs = "") { browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; @@ -47,9 +47,10 @@ public static void OpenInBrowserWindow(this string url, string browserPath = "", .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" ? "" : "--new-window ") + (inPrivate ? $"{privateArg} " : "") + url; + var newWindowArg = browserExecutableName == "iexplore.exe" ? "" : "--new-window "; + privateArg = inPrivate && !string.IsNullOrEmpty(privateArg) ? $"{privateArg} " : ""; + var browserArguements = $"{newWindowArg}{privateArg}{additionalArgs} {url}"; var psi = new ProcessStartInfo { @@ -80,10 +81,10 @@ public static void NewBrowserWindow(this string url, string browserPath = "") /// /// Opens search as a tab in the default browser chosen in Windows settings. /// - public static void OpenInBrowserTab(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "") + public static void OpenInBrowserTab(this string url, string browserPath = "", bool inPrivate = false, string privateArg = "", string additionalArgs = "") { browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath; - + var psi = new ProcessStartInfo() { UseShellExecute = true @@ -93,7 +94,8 @@ public static void OpenInBrowserTab(this string url, string browserPath = "", bo if (!string.IsNullOrEmpty(browserPath)) { psi.FileName = browserPath; - psi.Arguments = (inPrivate ? $"{privateArg} " : "") + url; + privateArg = inPrivate && !string.IsNullOrEmpty(privateArg) ? $"{privateArg} " : ""; + psi.Arguments = $"{privateArg}{additionalArgs} {url}"; } else { @@ -118,4 +120,4 @@ public static void NewTabInBrowser(this string url, string browserPath = "") OpenInBrowserTab(url, browserPath); } } -} \ No newline at end of file +} diff --git a/Flow.Launcher/PublicAPIInstance.cs b/Flow.Launcher/PublicAPIInstance.cs index 636699ad02e..84fbbf01bcf 100644 --- a/Flow.Launcher/PublicAPIInstance.cs +++ b/Flow.Launcher/PublicAPIInstance.cs @@ -215,7 +215,7 @@ public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null explorer.Start(); } - private void OpenUri(Uri uri, bool? inPrivate = null) + private void OpenUri(Uri uri, bool? inPrivate = null, string additionalArgs = "") { if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps) { @@ -225,11 +225,11 @@ private void OpenUri(Uri uri, bool? inPrivate = null) if (browserInfo.OpenInTab) { - uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + uri.AbsoluteUri.OpenInBrowserTab(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg, additionalArgs); } else { - uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg); + uri.AbsoluteUri.OpenInBrowserWindow(path, inPrivate ?? browserInfo.EnablePrivate, browserInfo.PrivateArg, additionalArgs); } } else @@ -244,14 +244,14 @@ private void OpenUri(Uri uri, bool? inPrivate = null) } } - public void OpenUrl(string url, bool? inPrivate = null) + public void OpenUrl(string url, bool? inPrivate = null, string additionalArgs = "") { - OpenUri(new Uri(url), inPrivate); + OpenUri(new Uri(url), inPrivate, additionalArgs); } - public void OpenUrl(Uri url, bool? inPrivate = null) + public void OpenUrl(Uri url, bool? inPrivate = null, string additionalArgs = "") { - OpenUri(url, inPrivate); + OpenUri(url, inPrivate, additionalArgs); } public void OpenAppUri(string appUri) diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs index e20a476c51f..6c56935516c 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/ChromiumBookmarkLoader.cs @@ -23,7 +23,7 @@ protected List LoadBookmarks(string browserDataPath, string name) Main.RegisterBookmarkFile(bookmarkPath); - var source = name + (Path.GetFileName(profile) == "Default" ? "" : $" ({Path.GetFileName(profile)})"); + var source = name + $" ({Path.GetFileName(profile)})"; bookmarks.AddRange(LoadBookmarksFromFile(bookmarkPath, source)); } return bookmarks; diff --git a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs index d9a719272b5..8cf84891312 100644 --- a/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs +++ b/Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs @@ -48,15 +48,10 @@ public List Query(Query query) var returnList = cachedBookmarks.Select(c => new Result() { Title = c.Name, - SubTitle = c.Url, + SubTitle = !String.IsNullOrEmpty(c.Source) ? $"{c.Source}: {c.Url}" : c.Url, IcoPath = @"Images\bookmark.png", Score = BookmarkLoader.MatchProgram(c, param).Score, - Action = _ => - { - context.API.OpenUrl(c.Url); - - return true; - }, + Action = _ => ActionOpenUrl(_, c), ContextData = new BookmarkAttributes { Url = c.Url @@ -69,14 +64,10 @@ public List Query(Query query) return cachedBookmarks.Select(c => new Result() { Title = c.Name, - SubTitle = c.Url, + SubTitle = !String.IsNullOrEmpty(c.Source) ? $"{c.Source}: {c.Url}" : c.Url, IcoPath = @"Images\bookmark.png", Score = 5, - Action = _ => - { - context.API.OpenUrl(c.Url); - return true; - }, + Action = _ => ActionOpenUrl(_, c), ContextData = new BookmarkAttributes { Url = c.Url @@ -85,6 +76,24 @@ public List Query(Query query) } } + private static bool ActionOpenUrl(ActionContext _, Bookmark c) + { + string profileArg = GetProfileArg(c); + context.API.OpenUrl(c.Url, true, profileArg); + return true; + } + + private static string GetProfileArg(Bookmark c) + { + try + { + return c.Source.Split('(', ')')[1]; + } + catch (Exception e) + { + return ""; + } + } private static Channel refreshQueue = Channel.CreateBounded(1);