Skip to content

Commit 13a8f82

Browse files
Add PATH environment variable to program source
1 parent d646380 commit 13a8f82

File tree

4 files changed

+64
-3
lines changed

4 files changed

+64
-3
lines changed

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
1818
using System.Diagnostics.CodeAnalysis;
1919
using System.Threading.Channels;
20+
using System.Collections.ObjectModel;
2021

2122
namespace Flow.Launcher.Plugin.Program.Programs
2223
{
@@ -275,6 +276,14 @@ private static Win32 LnkProgram(string path)
275276
program.Valid = false;
276277
return program;
277278
}
279+
catch (FileNotFoundException e)
280+
{
281+
ProgramLogger.LogException($"|Win32|LnkProgram|{path}" +
282+
"|An unexpected error occurred in the calling method LnkProgram", e);
283+
284+
program.Valid = false;
285+
return program;
286+
}
278287
#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.
279288
catch (Exception e)
280289
{
@@ -370,6 +379,32 @@ private static IEnumerable<Win32> StartMenuPrograms(string[] suffixes)
370379
return programs;
371380
}
372381

382+
private static IEnumerable<Win32> PATHPrograms(string[] suffixes)
383+
{
384+
var disabledProgramsList = Main._settings.DisabledProgramSources;
385+
386+
string? pathEnv = Environment.GetEnvironmentVariable("Path");
387+
if (String.IsNullOrEmpty(pathEnv)) {
388+
return Array.Empty<Win32>();
389+
}
390+
391+
var toFilter = new List<string>();
392+
var paths = pathEnv.Split(";", StringSplitOptions.RemoveEmptyEntries).ToList().ConvertAll(x => x.ToLower()).Distinct();
393+
394+
foreach (var path in paths)
395+
{
396+
var p = ProgramPaths(path, suffixes);
397+
toFilter.AddRange(p);
398+
}
399+
var programs = ExceptDisabledSource(toFilter.Distinct())
400+
.Select(x => Extension(x) switch
401+
{
402+
ShortcutExtension => LnkProgram(x),
403+
_ => Win32Program(x)
404+
}).Where(x => x.Valid);
405+
return programs;
406+
}
407+
373408
private static IEnumerable<Win32> AppPathsPrograms(string[] suffixes)
374409
{
375410
// https://msdn.microsoft.com/en-us/library/windows/desktop/ee872121
@@ -522,6 +557,12 @@ public static Win32[] All(Settings settings)
522557
autoIndexPrograms = autoIndexPrograms.Concat(startMenu);
523558
}
524559

560+
if (settings.EnablePATHSource)
561+
{
562+
var path = PATHPrograms(settings.ProgramSuffixes);
563+
autoIndexPrograms = autoIndexPrograms.Concat(path);
564+
}
565+
525566
autoIndexPrograms = ProgramsHasher(autoIndexPrograms);
526567

527568
return programs.Concat(autoIndexPrograms).Distinct().ToArray();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ public class Settings
1212
public string[] ProgramSuffixes { get; set; } = {"appref-ms", "exe", "lnk"};
1313

1414
public bool EnableStartMenuSource { get; set; } = true;
15-
1615
public bool EnableDescription { get; set; } = false;
1716
public bool HideAppsPath { get; set; } = true;
1817
public bool EnableRegistrySource { get; set; } = true;
18+
public bool EnablePATHSource { get; set; } = false;
19+
1920
public string CustomizedExplorer { get; set; } = Explorer;
2021
public string CustomizedArgs { get; set; } = ExplorerArgs;
2122

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,19 @@
5454
IsChecked="{Binding EnableDescription}"
5555
ToolTip="{DynamicResource flowlauncher_plugin_program_enable_description_tooltip}" />
5656
</StackPanel>
57+
5758
<Separator
5859
Height="1"
5960
BorderBrush="{DynamicResource Color03B}"
6061
BorderThickness="1" />
62+
<StackPanel Width="Auto" Orientation="Horizontal">
63+
<CheckBox
64+
Name="PATHEnabled"
65+
Margin="70,8,10,8"
66+
Content="Enable Path"
67+
IsChecked="{Binding EnablePATHSource}"
68+
ToolTip="" />
69+
</StackPanel>
6170
</StackPanel>
6271
<StackPanel
6372
Width="Auto"

Plugins/Flow.Launcher.Plugin.Program/Views/ProgramSetting.xaml.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.IO;
33
using System.Linq;
44
using System.Threading.Tasks;
@@ -66,6 +66,16 @@ public bool EnableStartMenuSource
6666
}
6767
}
6868

69+
public bool EnablePATHSource
70+
{
71+
get => _settings.EnablePATHSource;
72+
set
73+
{
74+
_settings.EnablePATHSource = value;
75+
ReIndexing();
76+
}
77+
}
78+
6979
public string CustomizedExplorerPath
7080
{
7181
get => _settings.CustomizedExplorer;
@@ -360,4 +370,4 @@ private void Row_OnClick(object sender, RoutedEventArgs e)
360370
}
361371
}
362372
}
363-
}
373+
}

0 commit comments

Comments
 (0)