diff --git a/Flow.Launcher.Core/Flow.Launcher.Core.csproj b/Flow.Launcher.Core/Flow.Launcher.Core.csproj
index 2b2bef4cf79..8d140844936 100644
--- a/Flow.Launcher.Core/Flow.Launcher.Core.csproj
+++ b/Flow.Launcher.Core/Flow.Launcher.Core.csproj
@@ -53,7 +53,7 @@
-
+
diff --git a/Flow.Launcher.Core/Plugin/PluginsLoader.cs b/Flow.Launcher.Core/Plugin/PluginsLoader.cs
index 3f998fa51b3..e5f44e4c458 100644
--- a/Flow.Launcher.Core/Plugin/PluginsLoader.cs
+++ b/Flow.Launcher.Core/Plugin/PluginsLoader.cs
@@ -18,8 +18,6 @@ namespace Flow.Launcher.Core.Plugin
{
public static class PluginsLoader
{
- public const string PATH = "PATH";
- public const string Python = "python";
public const string PythonExecutable = "pythonw.exe";
public static List Plugins(List metadatas, PluginsSettings settings)
@@ -117,119 +115,65 @@ public static IEnumerable PythonPlugins(List source,
if (!source.Any(o => o.Language.ToUpper() == AllowedLanguage.Python))
return new List();
- // Try setting Constant.PythonPath first, either from
- // PATH or from the given pythonDirectory
- if (string.IsNullOrEmpty(settings.PythonDirectory))
+ if (!string.IsNullOrEmpty(settings.PythonDirectory) && FilesFolders.LocationExists(settings.PythonDirectory))
+ return SetPythonPathForPluginPairs(source, Path.Combine(settings.PythonDirectory, PythonExecutable));
+
+ var pythonPath = string.Empty;
+
+ if (MessageBox.Show("Flow detected you have installed Python plugins, " +
+ "would you like to install Python to run them? " +
+ Environment.NewLine + Environment.NewLine +
+ "Click no if it's already installed, " +
+ "and you will be prompted to select the folder that contains the Python executable",
+ string.Empty, MessageBoxButtons.YesNo) == DialogResult.No
+ && string.IsNullOrEmpty(settings.PythonDirectory))
{
- var whereProcess = Process.Start(new ProcessStartInfo
+ var dlg = new FolderBrowserDialog
{
- FileName = "where.exe",
- Arguments = "pythonw",
- RedirectStandardOutput = true,
- CreateNoWindow = true,
- UseShellExecute = false
- });
-
- var pythonPath = whereProcess?.StandardOutput.ReadToEnd().Trim();
-
- if (!string.IsNullOrEmpty(pythonPath))
- {
- pythonPath = FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, pythonPath);
- }
-
- if (string.IsNullOrEmpty(pythonPath))
- {
- var paths = Environment.GetEnvironmentVariable(PATH);
-
- pythonPath = paths?
- .Split(';')
- .FirstOrDefault(p => p.ToLower().Contains(Python));
- }
+ SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
+ };
- if (!string.IsNullOrEmpty(pythonPath))
- {
- Constant.PythonPath = Path.Combine(pythonPath, PythonExecutable);
- settings.PythonDirectory =
- FilesFolders.GetPreviousExistingDirectory(FilesFolders.LocationExists, Constant.PythonPath);
- }
- else
+ var result = dlg.ShowDialog();
+ if (result == DialogResult.OK)
{
- Log.Error("PluginsLoader",
- "Failed to set Python path despite the environment variable PATH is found",
- "PythonPlugins");
+ string pythonDirectory = dlg.SelectedPath;
+ if (!string.IsNullOrEmpty(pythonDirectory))
+ {
+ pythonPath = Path.Combine(pythonDirectory, PythonExecutable);
+ if (File.Exists(pythonPath))
+ {
+ settings.PythonDirectory = pythonDirectory;
+ Constant.PythonPath = pythonPath;
+ }
+ else
+ {
+ MessageBox.Show("Can't find python in given directory");
+ }
+ }
}
}
else
{
- var path = Path.Combine(settings.PythonDirectory, PythonExecutable);
- if (File.Exists(path))
- {
- Constant.PythonPath = path;
- }
- else
- {
- Log.Error("PluginsLoader", $"Tried to automatically set from Settings.PythonDirectory " +
- $"but can't find python executable in {path}", "PythonPlugins");
- }
- }
+ var installedPythonDirectory = Path.Combine(DataLocation.DataDirectory(), "Python Embeddable");
- if (string.IsNullOrEmpty(settings.PythonDirectory))
- {
- if (MessageBox.Show("Flow detected you have installed Python plugins, " +
- "would you like to install Python to run them? " +
- Environment.NewLine + Environment.NewLine +
- "Click no if it's already installed, " +
- "and you will be prompted to select the folder that contains the Python executable",
- string.Empty, MessageBoxButtons.YesNo) == DialogResult.No
- && string.IsNullOrEmpty(settings.PythonDirectory))
- {
- var dlg = new FolderBrowserDialog
- {
- SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
- };
+ // Python 3.8.9 is used for Windows 7 compatibility
+ DroplexPackage.Drop(App.python_3_8_9_embeddable, installedPythonDirectory).Wait();
- var result = dlg.ShowDialog();
- if (result == DialogResult.OK)
- {
- string pythonDirectory = dlg.SelectedPath;
- if (!string.IsNullOrEmpty(pythonDirectory))
- {
- var pythonPath = Path.Combine(pythonDirectory, PythonExecutable);
- if (File.Exists(pythonPath))
- {
- settings.PythonDirectory = pythonDirectory;
- Constant.PythonPath = pythonPath;
- }
- else
- {
- MessageBox.Show("Can't find python in given directory");
- }
- }
- }
+ pythonPath = Path.Combine(installedPythonDirectory, PythonExecutable);
+ if (FilesFolders.FileExists(pythonPath))
+ {
+ settings.PythonDirectory = installedPythonDirectory;
+ Constant.PythonPath = pythonPath;
}
else
{
- DroplexPackage.Drop(App.python3_9_1).Wait();
-
- var installedPythonDirectory =
- Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
- @"Programs\Python\Python39");
- var pythonPath = Path.Combine(installedPythonDirectory, PythonExecutable);
- if (FilesFolders.FileExists(pythonPath))
- {
- settings.PythonDirectory = installedPythonDirectory;
- Constant.PythonPath = pythonPath;
- }
- else
- {
- Log.Error("PluginsLoader",
- $"Failed to set Python path after Droplex install, {pythonPath} does not exist",
- "PythonPlugins");
- }
+ Log.Error("PluginsLoader",
+ $"Failed to set Python path after Droplex install, {pythonPath} does not exist",
+ "PythonPlugins");
}
}
- if (string.IsNullOrEmpty(settings.PythonDirectory))
+ if (string.IsNullOrEmpty(settings.PythonDirectory) || string.IsNullOrEmpty(pythonPath))
{
MessageBox.Show(
"Unable to set Python executable path, please try from Flow's settings (scroll down to the bottom).");
@@ -240,16 +184,20 @@ public static IEnumerable PythonPlugins(List source,
return new List();
}
- return source
+ return SetPythonPathForPluginPairs(source, pythonPath);
+ }
+
+ private static IEnumerable SetPythonPathForPluginPairs(List source, string pythonPath)
+ => source
.Where(o => o.Language.ToUpper() == AllowedLanguage.Python)
.Select(metadata => new PluginPair
{
- Plugin = new PythonPlugin(Constant.PythonPath), Metadata = metadata
+ Plugin = new PythonPlugin(pythonPath),
+ Metadata = metadata
})
.ToList();
- }
- public static IEnumerable ExecutablePlugins(IEnumerable source)
+ public static IEnumerable ExecutablePlugins(IEnumerable source)
{
return source
.Where(o => o.Language.ToUpper() == AllowedLanguage.Executable)