Skip to content

Commit 90a48ee

Browse files
Merge pull request #1864 from TheBestPessimist/program_plugin_search_in_start_menu
Read the list of programs from `Start Menu` folder instead of `Start Menu/Programs`
2 parents d40ff12 + 30b73e5 commit 90a48ee

File tree

1 file changed

+22
-20
lines changed
  • Plugins/Flow.Launcher.Plugin.Program/Programs

1 file changed

+22
-20
lines changed

Plugins/Flow.Launcher.Plugin.Program/Programs/Win32.cs

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,29 @@ public class Win32 : IProgram, IEquatable<Win32>
2525
public string Name { get; set; }
2626
public string UniqueIdentifier { get => _uid; set => _uid = value == null ? string.Empty : value.ToLowerInvariant(); } // For path comparison
2727
public string IcoPath { get; set; }
28+
2829
/// <summary>
2930
/// Path of the file. It's the path of .lnk and .url for .lnk and .url files.
3031
/// </summary>
3132
public string FullPath { get; set; }
33+
3234
/// <summary>
3335
/// Path of the executable for .lnk, or the URL for .url. Arguments are included if any.
3436
/// </summary>
3537
public string LnkResolvedPath { get; set; }
38+
3639
/// <summary>
3740
/// Path of the actual executable file. Args are included.
3841
/// </summary>
3942
public string ExecutablePath => LnkResolvedPath ?? FullPath;
43+
4044
public string ParentDirectory { get; set; }
45+
4146
/// <summary>
4247
/// Name of the executable for .lnk files
4348
/// </summary>
4449
public string ExecutableName { get; set; }
50+
4551
public string Description { get; set; }
4652
public bool Valid { get; set; }
4753
public bool Enabled { get; set; }
@@ -199,8 +205,8 @@ public List<Result> ContextMenus(IPublicAPI api)
199205
{
200206
var info = new ProcessStartInfo
201207
{
202-
FileName = FullPath,
203-
WorkingDirectory = ParentDirectory,
208+
FileName = FullPath,
209+
WorkingDirectory = ParentDirectory,
204210
UseShellExecute = true
205211
};
206212

@@ -363,6 +369,7 @@ private static Win32 UrlProgram(string path, string[] protocols)
363369
{
364370
return program;
365371
}
372+
366373
foreach (var protocol in protocols)
367374
{
368375
if (url.StartsWith(protocol))
@@ -418,10 +425,10 @@ private static IEnumerable<string> EnumerateProgramsInDir(string directory, stri
418425
if (!Directory.Exists(directory))
419426
return Enumerable.Empty<string>();
420427

421-
return Directory.EnumerateFiles(directory, "*", new EnumerationOptions
422-
{
423-
IgnoreInaccessible = true, RecurseSubdirectories = recursive
424-
}).Where(x => suffixes.Contains(Extension(x)));
428+
return Directory.EnumerateFiles(
429+
directory, "*",
430+
new EnumerationOptions { IgnoreInaccessible = true, RecurseSubdirectories = recursive })
431+
.Where(x => suffixes.Contains(Extension(x)));
425432
}
426433

427434
private static string Extension(string path)
@@ -450,14 +457,11 @@ private static IEnumerable<Win32> UnregisteredPrograms(List<string> directories,
450457

451458
private static IEnumerable<Win32> StartMenuPrograms(string[] suffixes, string[] protocols)
452459
{
453-
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
454-
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
455-
var paths1 = EnumerateProgramsInDir(directory1, suffixes);
456-
var paths2 = EnumerateProgramsInDir(directory2, suffixes);
457-
458-
var toFilter = paths1.Concat(paths2);
460+
var allPrograms = GetStartMenuPaths()
461+
.SelectMany(p => EnumerateProgramsInDir(p, suffixes))
462+
.Distinct();
459463

460-
var programs = ExceptDisabledSource(toFilter.Distinct())
464+
var programs = ExceptDisabledSource(allPrograms)
461465
.Select(x => GetProgramFromPath(x, protocols));
462466
return programs;
463467
}
@@ -471,7 +475,7 @@ private static IEnumerable<Win32> PATHPrograms(string[] suffixes, string[] proto
471475
}
472476

473477
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant());
474-
478+
475479
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.PathContains(parent, x)))
476480
.AsParallel()
477481
.SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false));
@@ -695,12 +699,10 @@ public override bool Equals(object obj)
695699

696700
private static IEnumerable<string> GetStartMenuPaths()
697701
{
698-
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
699-
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
700-
return new[]
701-
{
702-
directory1, directory2
703-
};
702+
var userStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
703+
var commonStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
704+
705+
return new[] { userStartMenu, commonStartMenu };
704706
}
705707

706708
public static void WatchProgramUpdate(Settings settings)

0 commit comments

Comments
 (0)