Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Profile support on Bookmarks for Edge browser #2101

Draft
wants to merge 3 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ keyevent
KListener
requery
vkcode
Firefox
6 changes: 3 additions & 3 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
public void OpenUrl(Uri url, bool? inPrivate = null);

public void OpenUrl(Uri url, bool? inPrivate = null, string additionalArgs = "");
/// <summary>
/// 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.
/// </summary>
public void OpenUrl(string url, bool? inPrivate = null);
public void OpenUrl(string url, bool? inPrivate = null, string additionalArgs = "");

/// <summary>
/// Opens the application URI with the given Uri object, e.g. obsidian://search-query-example
Expand Down
18 changes: 10 additions & 8 deletions Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Microsoft.Win32;
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.IO;
Expand Down Expand Up @@ -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.
/// </summary>
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;

Expand All @@ -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
{
Expand Down Expand Up @@ -80,10 +81,10 @@ public static void NewBrowserWindow(this string url, string browserPath = "")
/// <summary>
/// Opens search as a tab in the default browser chosen in Windows settings.
/// </summary>
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
Expand All @@ -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
{
Expand All @@ -118,4 +120,4 @@ public static void NewTabInBrowser(this string url, string browserPath = "")
OpenInBrowserTab(url, browserPath);
}
}
}
}
14 changes: 7 additions & 7 deletions Flow.Launcher/PublicAPIInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected List<Bookmark> 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;
Expand Down
35 changes: 22 additions & 13 deletions Plugins/Flow.Launcher.Plugin.BrowserBookmark/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,10 @@ public List<Result> 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
Expand All @@ -69,14 +64,10 @@ public List<Result> 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
Expand All @@ -85,6 +76,24 @@ public List<Result> 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];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this split mean?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a fancy way to extract the value between those chars

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, so you are getting the content between the parenthesis?

}
catch (Exception e)
{
return "";
}
}

private static Channel<byte> refreshQueue = Channel.CreateBounded<byte>(1);

Expand Down