mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add PATH environment variable to program source
This commit is contained in:
parent
d646380f6e
commit
13a8f82bfe
4 changed files with 64 additions and 3 deletions
|
|
@ -17,6 +17,7 @@ using System.Diagnostics;
|
|||
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Channels;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace Flow.Launcher.Plugin.Program.Programs
|
||||
{
|
||||
|
|
@ -275,6 +276,14 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
program.Valid = false;
|
||||
return program;
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +
|
||||
"|An unexpected error occurred in the calling method LnkProgram", e);
|
||||
|
||||
program.Valid = false;
|
||||
return program;
|
||||
}
|
||||
#if !DEBUG //Only do a catch all in production. This is so make developer aware of any unhandled exception and add the exception handling in.
|
||||
catch (Exception e)
|
||||
{
|
||||
|
|
@ -370,6 +379,32 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
return programs;
|
||||
}
|
||||
|
||||
private static IEnumerable<Win32> PATHPrograms(string[] suffixes)
|
||||
{
|
||||
var disabledProgramsList = Main._settings.DisabledProgramSources;
|
||||
|
||||
string? pathEnv = Environment.GetEnvironmentVariable("Path");
|
||||
if (String.IsNullOrEmpty(pathEnv)) {
|
||||
return Array.Empty<Win32>();
|
||||
}
|
||||
|
||||
var toFilter = new List<string>();
|
||||
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(x => x.ToLower()).Distinct();
|
||||
|
||||
foreach (var path in paths)
|
||||
{
|
||||
var p = ProgramPaths(path, suffixes);
|
||||
toFilter.AddRange(p);
|
||||
}
|
||||
var programs = ExceptDisabledSource(toFilter.Distinct())
|
||||
.Select(x => Extension(x) switch
|
||||
{
|
||||
ShortcutExtension => LnkProgram(x),
|
||||
_ => Win32Program(x)
|
||||
}).Where(x => x.Valid);
|
||||
return programs;
|
||||
}
|
||||
|
||||
private static IEnumerable<Win32> AppPathsPrograms(string[] suffixes)
|
||||
{
|
||||
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
|
||||
|
|
@ -522,6 +557,12 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
|
||||
}
|
||||
|
||||
if (settings.EnablePATHSource)
|
||||
{
|
||||
var path = PATHPrograms(settings.ProgramSuffixes);
|
||||
autoIndexPrograms = autoIndexPrograms.Concat(path);
|
||||
}
|
||||
|
||||
autoIndexPrograms = ProgramsHasher(autoIndexPrograms);
|
||||
|
||||
return programs.Concat(autoIndexPrograms).Distinct().ToArray();
|
||||
|
|
|
|||
|
|
@ -12,10 +12,11 @@ namespace Flow.Launcher.Plugin.Program
|
|||
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
|
||||
|
||||
public bool EnableStartMenuSource { get; set; } = true;
|
||||
|
||||
public bool EnableDescription { get; set; } = false;
|
||||
public bool HideAppsPath { get; set; } = true;
|
||||
public bool EnableRegistrySource { get; set; } = true;
|
||||
public bool EnablePATHSource { get; set; } = false;
|
||||
|
||||
public string CustomizedExplorer { get; set; } = Explorer;
|
||||
public string CustomizedArgs { get; set; } = ExplorerArgs;
|
||||
|
||||
|
|
|
|||
|
|
@ -54,10 +54,19 @@
|
|||
IsChecked="{Binding EnableDescription}"
|
||||
ToolTip="{DynamicResource flowlauncher_plugin_program_enable_description_tooltip}" />
|
||||
</StackPanel>
|
||||
|
||||
<Separator
|
||||
Height="1"
|
||||
BorderBrush="{DynamicResource Color03B}"
|
||||
BorderThickness="1" />
|
||||
<StackPanel Width="Auto" Orientation="Horizontal">
|
||||
<CheckBox
|
||||
Name="PATHEnabled"
|
||||
Margin="70,8,10,8"
|
||||
Content="Enable Path"
|
||||
IsChecked="{Binding EnablePATHSource}"
|
||||
ToolTip="" />
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Width="Auto"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -66,6 +66,16 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
}
|
||||
}
|
||||
|
||||
public bool EnablePATHSource
|
||||
{
|
||||
get => _settings.EnablePATHSource;
|
||||
set
|
||||
{
|
||||
_settings.EnablePATHSource = value;
|
||||
ReIndexing();
|
||||
}
|
||||
}
|
||||
|
||||
public string CustomizedExplorerPath
|
||||
{
|
||||
get => _settings.CustomizedExplorer;
|
||||
|
|
@ -360,4 +370,4 @@ namespace Flow.Launcher.Plugin.Program.Views
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue