Skip to content

Commit ccf8d87

Browse files
committed
Add support for hiding dulplicated windows apps
1 parent 1a54eed commit ccf8d87

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Plugins/Flow.Launcher.Plugin.Program/Main.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public class Main : ISettingProvider, IAsyncPlugin, IPluginI18n, IContextMenu, I
7272
private const string ExeUninstallerSuffix = ".exe";
7373
private const string InkUninstallerSuffix = ".lnk";
7474

75+
private const string WindowsAppPath = "c:\\program files\\windowsapps";
76+
7577
static Main()
7678
{
7779
}
@@ -90,11 +92,20 @@ public async Task<List<Result>> QueryAsync(Query query, CancellationToken token)
9092
{
9193
try
9294
{
95+
// Collect all UWP Windows app directories
96+
var uwpsDirectories = _settings.HideDulplicatedWindowsApp ? _uwps
97+
.Where(uwp => !string.IsNullOrEmpty(uwp.Location)) // Exclude invalid paths
98+
.Where(uwp => uwp.Location.StartsWith(WindowsAppPath, StringComparison.OrdinalIgnoreCase)) // Keep system apps
99+
.Select(uwp => uwp.Location.TrimEnd('\\')) // Remove trailing slash
100+
.Distinct(StringComparer.OrdinalIgnoreCase)
101+
.ToArray() : null;
102+
93103
return _win32s.Cast<IProgram>()
94104
.Concat(_uwps)
95105
.AsParallel()
96106
.WithCancellation(token)
97107
.Where(HideUninstallersFilter)
108+
.Where(p => HideDulplicatedWindowsAppFilter(p, uwpsDirectories))
98109
.Where(p => p.Enabled)
99110
.Select(p => p.Result(query.Search, Context.API))
100111
.Where(r => r?.Score > 0)
@@ -152,6 +163,23 @@ private bool HideUninstallersFilter(IProgram program)
152163
return true;
153164
}
154165

166+
private static bool HideDulplicatedWindowsAppFilter(IProgram program, string[] uwpsDirectories)
167+
{
168+
if (uwpsDirectories == null || uwpsDirectories.Length == 0) return true;
169+
if (program is UWPApp) return true;
170+
171+
var location = program.Location.TrimEnd('\\'); // Ensure trailing slash
172+
if (string.IsNullOrEmpty(location))
173+
return true; // Keep if location is invalid
174+
175+
if (!location.StartsWith(WindowsAppPath, StringComparison.OrdinalIgnoreCase))
176+
return true; // Keep if not a Windows app
177+
178+
// Check if the any Win32 executable directory contains UWP Windows app location matches
179+
return !uwpsDirectories.Any(uwpDirectory =>
180+
location.StartsWith(uwpDirectory, StringComparison.OrdinalIgnoreCase));
181+
}
182+
155183
public async Task InitAsync(PluginInitContext context)
156184
{
157185
Context = context;

Plugins/Flow.Launcher.Plugin.Program/Settings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ private void RemoveRedundantSuffixes()
121121
public bool EnableRegistrySource { get; set; } = true;
122122
public bool EnablePathSource { get; set; } = false;
123123
public bool EnableUWP { get; set; } = true;
124+
public bool HideDulplicatedWindowsApp { get; set; } = true;
124125

125126
internal const char SuffixSeparator = ';';
126127
}

0 commit comments

Comments
 (0)