public List <Result> Query(Query query) { _cancellationTokenSource?.Cancel(); // cancel if already exist var cts = _cancellationTokenSource = new CancellationTokenSource(); var results = new List <Result>(); if (!string.IsNullOrEmpty(query.Search)) { var keyword = query.Search; try { var searchList = _api.Search(keyword, cts.Token, _settings.SortOption, maxCount: _settings.MaxSearchCount); if (searchList == null) { return(results); } foreach (var searchResult in searchList) { var r = CreateResult(keyword, searchResult); results.Add(r); } } catch (IPCErrorException) { results.Add(new Result { Title = _context.API.GetTranslation("flowlauncher_plugin_everything_is_not_running"), SubTitle = _context.API.GetTranslation("flowlauncher_plugin_everything_run_service"), IcoPath = "Images\\warning.png", Action = _ => { if (FilesFolders.FileExists(_settings.EverythingInstalledPath)) { FilesFolders.OpenPath(_settings.EverythingInstalledPath); } return(true); } }); } catch (Exception e) { _context.API.LogException("EverythingPlugin", "Query Error", e); results.Add(new Result { Title = _context.API.GetTranslation("flowlauncher_plugin_everything_query_error"), SubTitle = e.Message, Action = _ => { Clipboard.SetText(e.Message + "\r\n" + e.StackTrace); _context.API.ShowMsg(_context.API.GetTranslation("flowlauncher_plugin_everything_copied"), null, string.Empty); return(false); }, IcoPath = "Images\\error.png" }); } } return(results); }
public static IEnumerable <PluginPair> PythonPlugins(List <PluginMetadata> source, PluginsSettings settings) { if (!source.Any(o => o.Language.ToUpper() == AllowedLanguage.Python)) { return(new List <PluginPair>()); } 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, which " + "will need Python to run. Would you like to download Python? " + 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) }; var result = dlg.ShowDialog(); if (result == DialogResult.OK) { 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 installedPythonDirectory = Path.Combine(DataLocation.DataDirectory(), "PythonEmbeddable"); // Python 3.8.9 is used for Windows 7 compatibility DroplexPackage.Drop(App.python_3_8_9_embeddable, installedPythonDirectory).Wait(); 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"); } } 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)."); Log.Error("PluginsLoader", $"Not able to successfully set Python path, the PythonDirectory variable is still an empty string.", "PythonPlugins"); return(new List <PluginPair>()); } return(SetPythonPathForPluginPairs(source, pythonPath)); }