Skip to content

Commit

Permalink
added "open in new window" action
Browse files Browse the repository at this point in the history
davidegiacometti committed May 8, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent e407ce0 commit 20a1ad7
Showing 3 changed files with 67 additions and 15 deletions.
23 changes: 19 additions & 4 deletions Community.PowerToys.Run.Plugin.EdgeFavorite/Helpers/EdgeHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Davide Giacometti. All rights reserved.
// Copyright (c) Davide Giacometti. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
@@ -10,16 +10,31 @@ namespace Community.PowerToys.Run.Plugin.EdgeFavorite.Helpers
{
public static class EdgeHelpers
{
public static void OpenInEdge(FavoriteItem favorite, bool inPrivate)
public static void OpenInEdge(FavoriteItem favorite, bool inPrivate, bool newWindow)
{
var args = $"{favorite.Url}";
OpenInEdgeInternal(favorite.Profile, favorite.Url!, inPrivate, newWindow);
}

public static void OpenInEdge(ProfileInfo profileInfo, string urls, bool inPrivate, bool newWindow)
{
OpenInEdgeInternal(profileInfo, urls, inPrivate, newWindow);
}

private static void OpenInEdgeInternal(ProfileInfo profileInfo, string urls, bool inPrivate, bool newWindow)
{
var args = urls;

if (inPrivate)
{
args += " -inprivate";
}

args += $" -profile-directory=\"{favorite.Profile.Directory}\"";
if (newWindow)
{
args += " -new-window";
}

args += $" -profile-directory=\"{profileInfo.Directory}\"";

try
{
57 changes: 47 additions & 10 deletions Community.PowerToys.Run.Plugin.EdgeFavorite/Models/FavoriteItem.cs
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ public Result CreateResult(IPublicAPI api, string actionKeyword, bool showProfil
QueryTextDisplay = searchTree ? Path : Name,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, false);
EdgeHelpers.OpenInEdge(this, false, false);
return true;
},
ToolTipData = new ToolTipData(Name, Url),
@@ -129,22 +129,32 @@ public List<ContextMenuResult> CreateContextMenuResult()
new()
{
Title = $"Open all ({childFavoritesCount}) (Ctrl+O)",
Glyph = "\xE8A7",
Glyph = "\xE737",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.O,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, false),
Action = _ => OpenAll(childFavorites, false, false),
},
new()
{
Title = $"Open all ({childFavoritesCount}) in InPrivate (Ctrl+P)",
Title = $"Open all ({childFavoritesCount}) in new window (Ctrl+N)",
Glyph = "\xE8A7",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.N,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, false, true),
},
new()
{
Title = $"Open all ({childFavoritesCount}) in InPrivate window (Ctrl+P)",
Glyph = "\xE727",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.P,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ => OpenAll(childFavorites, true),
Action = _ => OpenAll(childFavorites, true, false),
},
};
}
@@ -177,15 +187,29 @@ public List<ContextMenuResult> CreateContextMenuResult()
},
new()
{
Title = "Open in InPrivate (Ctrl+P)",
Title = "Open in new window (Ctrl+N)",
Glyph = "\xE8A7",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.N,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, false, true);
return true;
},
},
new()
{
Title = "Open in InPrivate window (Ctrl+P)",
Glyph = "\xE727",
FontFamily = "Segoe Fluent Icons,Segoe MDL2 Assets",
AcceleratorKey = Key.P,
AcceleratorModifiers = ModifierKeys.Control,
PluginName = _pluginName,
Action = _ =>
{
EdgeHelpers.OpenInEdge(this, true);
EdgeHelpers.OpenInEdge(this, true, false);
return true;
},
},
@@ -209,11 +233,24 @@ public static void SetIcons(Theme theme)
}
}

private static bool OpenAll(IEnumerable<FavoriteItem> favorites, bool inPrivate)
private static bool OpenAll(FavoriteItem[] favorites, bool inPrivate, bool newWindow)
{
foreach (var favorite in favorites)
if (favorites.Length == 0)
{
EdgeHelpers.OpenInEdge(favorite, inPrivate);
throw new InvalidOperationException("Favorites cannot be empty.");
}

// If there is no need to open in a new window, starting multiple processes is preferred to avoid long command line arguments
if (newWindow)
{
EdgeHelpers.OpenInEdge(favorites[0].Profile, string.Join(" ", favorites.Select(f => f.Url!)), inPrivate, newWindow);
}
else
{
foreach (var favorite in favorites)
{
EdgeHelpers.OpenInEdge(favorite, inPrivate, false);
}
}

return true;
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.5.0</Version>
<Version>0.5.1</Version>
</PropertyGroup>

<ItemGroup>

0 comments on commit 20a1ad7

Please sign in to comment.