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`
This commit is contained in:
VictoriousRaptor 2023-02-07 01:46:34 +08:00 committed by GitHub
commit 90a48ee5f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -25,23 +25,29 @@ namespace Flow.Launcher.Plugin.Program.Programs
public string Name { get; set; }
public string UniqueIdentifier { get => _uid; set => _uid = value == null ? string.Empty : value.ToLowerInvariant(); } // For path comparison
public string IcoPath { get; set; }
/// <summary>
/// Path of the file. It's the path of .lnk and .url for .lnk and .url files.
/// </summary>
public string FullPath { get; set; }
/// <summary>
/// Path of the executable for .lnk, or the URL for .url. Arguments are included if any.
/// </summary>
public string LnkResolvedPath { get; set; }
/// <summary>
/// Path of the actual executable file. Args are included.
/// </summary>
public string ExecutablePath => LnkResolvedPath ?? FullPath;
public string ParentDirectory { get; set; }
/// <summary>
/// Name of the executable for .lnk files
/// </summary>
public string ExecutableName { get; set; }
public string Description { get; set; }
public bool Valid { get; set; }
public bool Enabled { get; set; }
@ -199,8 +205,8 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
var info = new ProcessStartInfo
{
FileName = FullPath,
WorkingDirectory = ParentDirectory,
FileName = FullPath,
WorkingDirectory = ParentDirectory,
UseShellExecute = true
};
@ -363,6 +369,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
{
return program;
}
foreach (var protocol in protocols)
{
if (url.StartsWith(protocol))
@ -418,10 +425,10 @@ namespace Flow.Launcher.Plugin.Program.Programs
if (!Directory.Exists(directory))
return Enumerable.Empty<string>();
return Directory.EnumerateFiles(directory, "*", new EnumerationOptions
{
IgnoreInaccessible = true, RecurseSubdirectories = recursive
}).Where(x => suffixes.Contains(Extension(x)));
return Directory.EnumerateFiles(
directory, "*",
new EnumerationOptions { IgnoreInaccessible = true, RecurseSubdirectories = recursive })
.Where(x => suffixes.Contains(Extension(x)));
}
private static string Extension(string path)
@ -450,14 +457,11 @@ namespace Flow.Launcher.Plugin.Program.Programs
private static IEnumerable<Win32> StartMenuPrograms(string[] suffixes, string[] protocols)
{
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
var paths1 = EnumerateProgramsInDir(directory1, suffixes);
var paths2 = EnumerateProgramsInDir(directory2, suffixes);
var allPrograms = GetStartMenuPaths()
.SelectMany(p => EnumerateProgramsInDir(p, suffixes))
.Distinct();
var toFilter = paths1.Concat(paths2);
var programs = ExceptDisabledSource(toFilter.Distinct())
var programs = ExceptDisabledSource(allPrograms)
.Select(x => GetProgramFromPath(x, protocols));
return programs;
}
@ -471,7 +475,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
}
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).DistinctBy(p => p.ToLowerInvariant());
var toFilter = paths.Where(x => commonParents.All(parent => !FilesFolders.PathContains(parent, x)))
.AsParallel()
.SelectMany(p => EnumerateProgramsInDir(p, suffixes, recursive: false));
@ -695,12 +699,10 @@ namespace Flow.Launcher.Plugin.Program.Programs
private static IEnumerable<string> GetStartMenuPaths()
{
var directory1 = Environment.GetFolderPath(Environment.SpecialFolder.Programs);
var directory2 = Environment.GetFolderPath(Environment.SpecialFolder.CommonPrograms);
return new[]
{
directory1, directory2
};
var userStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
var commonStartMenu = Environment.GetFolderPath(Environment.SpecialFolder.CommonStartMenu);
return new[] { userStartMenu, commonStartMenu };
}
public static void WatchProgramUpdate(Settings settings)