update python directory to python file directory

This commit is contained in:
Jeremy 2022-10-25 21:03:01 +11:00
parent 5263bf50dd
commit 76c0f03bc2
6 changed files with 46 additions and 52 deletions

View file

@ -9,8 +9,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Flow.Launcher.Core.ExternalPlugins
@ -61,8 +59,8 @@ namespace Flow.Launcher.Core.ExternalPlugins
switch (languageType)
{
case AllowedLanguage.Python:
if (!string.IsNullOrEmpty(pluginSettings.PythonDirectory) && FilesFolders.LocationExists(pluginSettings.PythonDirectory))
return SetPathForPluginPairs($"{pluginSettings.PythonDirectory}\\{PythonExecutable}", languageType);
if (!string.IsNullOrEmpty(pluginSettings.PythonFilePath) && FilesFolders.FileExists(pluginSettings.PythonFilePath))
return SetPathForPluginPairs($"{pluginSettings.PythonFilePath}\\{PythonExecutable}", languageType);
break;
case AllowedLanguage.TypeScript:
@ -82,37 +80,39 @@ namespace Flow.Launcher.Core.ExternalPlugins
$"and you will be prompted to select the folder that contains the {environment} executable",
string.Empty, MessageBoxButtons.YesNo) == DialogResult.No)
{
var dlg = new OpenFileDialog
{
InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
Multiselect = false,
CheckFileExists = true,
CheckPathExists = true,
Title = $"Please select the {environment} executable"
};
var msg = $"Please select the {environment} executable";
var selectedFile = string.Empty;
var result = dlg.ShowDialog();
if (result == DialogResult.OK)
switch (languageType)
{
switch (languageType)
{
case AllowedLanguage.Python:
Constant.PythonPath = dlg.FileName;
pluginSettings.PythonDirectory = Constant.PythonPath;
break;
case AllowedLanguage.TypeScript:
case AllowedLanguage.JavaScript:
Constant.NodePath = dlg.FileName;
case AllowedLanguage.Python:
selectedFile = GetFileFromDialog(msg, "Python|pythonw.exe");
if (!string.IsNullOrEmpty(selectedFile))
{
Constant.PythonPath = selectedFile;
pluginSettings.PythonFilePath = Constant.PythonPath;
}
break;
case AllowedLanguage.TypeScript:
case AllowedLanguage.JavaScript:
selectedFile = GetFileFromDialog(msg);
if (!string.IsNullOrEmpty(selectedFile))
{
Constant.NodePath = selectedFile;
pluginSettings.NodeFilePath = Constant.NodePath;
break;
default:
break;
}
}
break;
default:
break;
}
else
{
// Nothing selected because user pressed cancel from the file dialog window
if (string.IsNullOrEmpty(selectedFile))
InstallEnvironment(languageType);
}
}
else
{
@ -121,19 +121,19 @@ namespace Flow.Launcher.Core.ExternalPlugins
switch (languageType)
{
case AllowedLanguage.Python when FilesFolders.FileExists(Constant.PythonPath) && !string.IsNullOrEmpty(pluginSettings.PythonDirectory):
return SetPathForPluginPairs(Constant.PythonPath, languageType);
case AllowedLanguage.Python when FilesFolders.FileExists(pluginSettings.PythonFilePath) && !string.IsNullOrEmpty(Constant.PythonPath):
return SetPathForPluginPairs(pluginSettings.PythonFilePath, languageType);
case AllowedLanguage.TypeScript when FilesFolders.FileExists(Constant.NodePath) && !string.IsNullOrEmpty(pluginSettings.NodeFilePath):
case AllowedLanguage.JavaScript when FilesFolders.FileExists(Constant.NodePath) && !string.IsNullOrEmpty(pluginSettings.NodeFilePath):
case AllowedLanguage.TypeScript when FilesFolders.FileExists(pluginSettings.NodeFilePath) && !string.IsNullOrEmpty(Constant.NodePath):
case AllowedLanguage.JavaScript when FilesFolders.FileExists(pluginSettings.NodeFilePath) && !string.IsNullOrEmpty(Constant.NodePath):
return SetPathForPluginPairs(pluginSettings.NodeFilePath, languageType);
default:
MessageBox.Show(
"Unable to set Python executable path, please try from Flow's settings (scroll down to the bottom).");
Log.Error("PluginsLoader",
$"Not able to successfully set Python path, the PythonDirectory variable is still an empty string.",
"PythonPlugins");
$"Not able to successfully set Python path, setting's PythonFilePath variable is still an empty string.",
"PluginEnvironment");
return new List<PluginPair>();
}
@ -142,17 +142,16 @@ namespace Flow.Launcher.Core.ExternalPlugins
private void InstallEnvironment(string languageType)
{
switch (languageType)
{
{//TODO: UPDATE TO USE CENTRALISED PLUGINENVIRONMENT FOLDER
case AllowedLanguage.Python:
var pythonDirPath = Path.Combine(DataLocation.DataDirectory(), "PythonEmbeddable");
FilesFolders.RemoveFolderIfExists(pythonDirPath);
// Python 3.8.9 is used for Windows 7 compatibility
DroplexPackage.Drop(App.python_3_8_9_embeddable, pythonDirPath).Wait();
pluginSettings.PythonDirectory = pythonDirPath;
Constant.PythonPath = Path.Combine(pythonDirPath, PythonExecutable);
pluginSettings.PythonFilePath = Constant.PythonPath;
break;
case AllowedLanguage.TypeScript:
@ -164,7 +163,6 @@ namespace Flow.Launcher.Core.ExternalPlugins
Constant.NodePath = Path.Combine(nodeDirPath, $"node-v16.18.0-win-x64\\{NodeExecutable}");
pluginSettings.NodeFilePath = Constant.NodePath;
break;
default:

View file

@ -1,17 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using Droplex;
using Flow.Launcher.Core.ExternalPlugins;
using Flow.Launcher.Infrastructure;
using Flow.Launcher.Infrastructure.Logger;
using Flow.Launcher.Infrastructure.UserSettings;
using Flow.Launcher.Plugin;
using Flow.Launcher.Plugin.SharedCommands;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
namespace Flow.Launcher.Core.Plugin

View file

@ -5,7 +5,7 @@ namespace Flow.Launcher.Infrastructure.UserSettings
{
public class PluginsSettings : BaseModel
{
public string PythonDirectory { get; set; } // IS FILE PATH BUT CHANGE NAME TO FILE PATH??
public string PythonFilePath { get; set; }
public string NodeFilePath { get; set; }

View file

@ -56,7 +56,7 @@
<system:String x:Key="defaultFileManagerToolTip">Select the file manager to use when opening the folder.</system:String>
<system:String x:Key="defaultBrowser">Default Web Browser</system:String>
<system:String x:Key="defaultBrowserToolTip">Setting for New Tab, New Window, Private Mode.</system:String>
<system:String x:Key="pythonDirectory">Python Directory</system:String>
<system:String x:Key="pythonFilePath">Python Path</system:String>
<system:String x:Key="nodeFilePath">Node.js Path</system:String>
<system:String x:Key="selectNodeExecutable">Please select the Node.js executable</system:String>
<system:String x:Key="selectPythonExecutable">Please select pythonw.exe</system:String>

View file

@ -905,17 +905,17 @@
<Border Margin="0,30,0,0" Style="{DynamicResource SettingGroupBox}">
<ItemsControl Style="{StaticResource SettingGrid}">
<StackPanel Style="{StaticResource TextPanel}">
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource pythonDirectory}" />
<TextBlock Style="{DynamicResource SettingTitleLabel}" Text="{DynamicResource pythonFilePath}" />
</StackPanel>
<StackPanel Grid.Column="2" Orientation="Horizontal">
<TextBox
Width="300"
Height="34"
Text="{Binding Settings.PluginSettings.PythonDirectory, TargetNullValue='No Setting'}" />
Text="{Binding Settings.PluginSettings.PythonFilePath, TargetNullValue='No Setting'}" />
<Button
Height="34"
Margin="10,10,18,10"
Click="OnSelectPythonDirectoryClick"
Click="OnSelectPythonFilePathClick"
Content="{DynamicResource select}" />
</StackPanel>
</ItemsControl>

View file

@ -70,7 +70,7 @@ namespace Flow.Launcher
InitializePosition();
}
private void OnSelectPythonDirectoryClick(object sender, RoutedEventArgs e)
private void OnSelectPythonFilePathClick(object sender, RoutedEventArgs e)
{
var selectedFile = PluginEnvironment.GetFileFromDialog(
InternationalizationManager.Instance.GetTranslation("selectPythonExecutable"),
@ -79,7 +79,7 @@ namespace Flow.Launcher
if (!string.IsNullOrEmpty(selectedFile))
{
Constant.PythonPath = selectedFile;
settings.PluginSettings.PythonDirectory = Constant.PythonPath;
settings.PluginSettings.PythonFilePath = Constant.PythonPath;
}
}