Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions Flow.Launcher.Plugin/Interfaces/IPublicAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ public interface IPublicAPI
/// </summary>
public void OpenUrl(Uri url, bool? inPrivate = null);

/// <summary>
/// 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.
/// Non-C# plugins can use this method.
/// </summary>
/// <param name="profileArg">Optional Profile name</param>
public void OpenUrl(string url, bool hasProfile, string profileArg);

/// <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.
Expand Down
14 changes: 11 additions & 3 deletions Flow.Launcher.Plugin/SharedCommands/SearchWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ 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 profileArg = "")
{
browserPath = string.IsNullOrEmpty(browserPath) ? GetDefaultBrowserPath() : browserPath;

Expand All @@ -93,7 +93,15 @@ public static void OpenInBrowserTab(this string url, string browserPath = "", bo
if (!string.IsNullOrEmpty(browserPath))
{
psi.FileName = browserPath;
psi.Arguments = (inPrivate ? $"{privateArg} " : "") + url;
if (inPrivate)
{
psi.Arguments = (inPrivate ? $"{privateArg} " : "") + url;
}
else
{
psi.Arguments = (!String.IsNullOrEmpty(profileArg) ? $"--profile-directory=\"{profileArg}\" " : "") + url;
}

}
else
{
Expand All @@ -118,4 +126,4 @@ public static void NewTabInBrowser(this string url, string browserPath = "")
OpenInBrowserTab(url, browserPath);
}
}
}
}
16 changes: 13 additions & 3 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 profileArg = "")
{
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
{
Expand All @@ -225,7 +225,7 @@ 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, profileArg);
}
else
{
Expand All @@ -243,7 +243,17 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
return;
}
}

public void OpenUrl(string url, bool hasProfile, string profileArg = "")
{
if (hasProfile)
{
OpenUri(new Uri(url), profileArg: profileArg);
}
else
{
OpenUri(new Uri(url));
}
}
public void OpenUrl(string url, bool? inPrivate = null)
{
OpenUri(new Uri(url), inPrivate);
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