Skip to content

Commit eeb9ea7

Browse files
committed
Code quality
1 parent 0e4e95a commit eeb9ea7

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

Flow.Launcher.Core/ExternalPlugins/Environments/AbstractPluginEnvironment.cs

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
using Flow.Launcher.Infrastructure.Logger;
2-
using Flow.Launcher.Infrastructure.UserSettings;
3-
using Flow.Launcher.Plugin;
4-
using Flow.Launcher.Plugin.SharedCommands;
5-
using System;
1+
using System;
62
using System.Collections.Generic;
73
using System.IO;
84
using System.Linq;
95
using System.Windows;
106
using System.Windows.Forms;
11-
using Flow.Launcher.Core.Resource;
127
using CommunityToolkit.Mvvm.DependencyInjection;
8+
using Flow.Launcher.Infrastructure.Logger;
9+
using Flow.Launcher.Infrastructure.UserSettings;
10+
using Flow.Launcher.Plugin;
11+
using Flow.Launcher.Plugin.SharedCommands;
1312

1413
namespace Flow.Launcher.Core.ExternalPlugins.Environments
1514
{
@@ -43,8 +42,11 @@ internal AbstractPluginEnvironment(List<PluginMetadata> pluginMetadataList, Plug
4342

4443
internal IEnumerable<PluginPair> Setup()
4544
{
45+
// If no plugin is using the language, return empty list
4646
if (!PluginMetadataList.Any(o => o.Language.Equals(Language, StringComparison.OrdinalIgnoreCase)))
47+
{
4748
return new List<PluginPair>();
49+
}
4850

4951
if (!string.IsNullOrEmpty(PluginsSettingsFilePath) && FilesFolders.FileExists(PluginsSettingsFilePath))
5052
{
@@ -56,24 +58,21 @@ internal IEnumerable<PluginPair> Setup()
5658
}
5759

5860
var noRuntimeMessage = string.Format(
59-
InternationalizationManager.Instance.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"),
61+
API.GetTranslation("runtimePluginInstalledChooseRuntimePrompt"),
6062
Language,
6163
EnvName,
6264
Environment.NewLine
6365
);
6466
if (API.ShowMsgBox(noRuntimeMessage, string.Empty, MessageBoxButton.YesNo) == MessageBoxResult.No)
6567
{
66-
var msg = string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
67-
string selectedFile;
68+
var msg = string.Format(API.GetTranslation("runtimePluginChooseRuntimeExecutable"), EnvName);
6869

69-
selectedFile = GetFileFromDialog(msg, FileDialogFilter);
70+
var selectedFile = GetFileFromDialog(msg, FileDialogFilter);
7071

71-
if (!string.IsNullOrEmpty(selectedFile))
72-
PluginsSettingsFilePath = selectedFile;
72+
if (!string.IsNullOrEmpty(selectedFile)) PluginsSettingsFilePath = selectedFile;
7373

7474
// Nothing selected because user pressed cancel from the file dialog window
75-
if (string.IsNullOrEmpty(selectedFile))
76-
InstallEnvironment();
75+
if (string.IsNullOrEmpty(selectedFile)) InstallEnvironment();
7776
}
7877
else
7978
{
@@ -86,7 +85,7 @@ internal IEnumerable<PluginPair> Setup()
8685
}
8786
else
8887
{
89-
API.ShowMsgBox(string.Format(InternationalizationManager.Instance.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
88+
API.ShowMsgBox(string.Format(API.GetTranslation("runtimePluginUnableToSetExecutablePath"), Language));
9089
Log.Error("PluginsLoader",
9190
$"Not able to successfully set {EnvName} path, setting's plugin executable path variable is still an empty string.",
9291
$"{Language}Environment");
@@ -99,13 +98,11 @@ internal IEnumerable<PluginPair> Setup()
9998

10099
private void EnsureLatestInstalled(string expectedPath, string currentPath, string installedDirPath)
101100
{
102-
if (expectedPath == currentPath)
103-
return;
101+
if (expectedPath == currentPath) return;
104102

105103
FilesFolders.RemoveFolderIfExists(installedDirPath, (s) => API.ShowMsgBox(s));
106104

107105
InstallEnvironment();
108-
109106
}
110107

111108
internal abstract PluginPair CreatePluginPair(string filePath, PluginMetadata metadata);
@@ -126,7 +123,7 @@ private IEnumerable<PluginPair> SetPathForPluginPairs(string filePath, string la
126123
return pluginPairs;
127124
}
128125

129-
private string GetFileFromDialog(string title, string filter = "")
126+
private static string GetFileFromDialog(string title, string filter = "")
130127
{
131128
var dlg = new OpenFileDialog
132129
{
@@ -140,7 +137,6 @@ private string GetFileFromDialog(string title, string filter = "")
140137

141138
var result = dlg.ShowDialog();
142139
return result == DialogResult.OK ? dlg.FileName : string.Empty;
143-
144140
}
145141

146142
/// <summary>
@@ -183,31 +179,33 @@ public static void PreStartPluginExecutablePathUpdate(Settings settings)
183179
else
184180
{
185181
if (IsUsingPortablePath(settings.PluginSettings.PythonExecutablePath, DataLocation.PythonEnvironmentName))
182+
{
186183
settings.PluginSettings.PythonExecutablePath
187184
= GetUpdatedEnvironmentPath(settings.PluginSettings.PythonExecutablePath);
185+
}
188186

189187
if (IsUsingPortablePath(settings.PluginSettings.NodeExecutablePath, DataLocation.NodeEnvironmentName))
188+
{
190189
settings.PluginSettings.NodeExecutablePath
191190
= GetUpdatedEnvironmentPath(settings.PluginSettings.NodeExecutablePath);
191+
}
192192
}
193193
}
194194

195195
private static bool IsUsingPortablePath(string filePath, string pluginEnvironmentName)
196196
{
197-
if (string.IsNullOrEmpty(filePath))
198-
return false;
197+
if (string.IsNullOrEmpty(filePath)) return false;
199198

200199
// DataLocation.PortableDataPath returns the current portable path, this determines if an out
201200
// of date path is also a portable path.
202-
var portableAppEnvLocation = $"UserData\\{DataLocation.PluginEnvironments}\\{pluginEnvironmentName}";
201+
var portableAppEnvLocation = Path.Combine("UserData", DataLocation.PluginEnvironments, pluginEnvironmentName);
203202

204203
return filePath.Contains(portableAppEnvLocation);
205204
}
206205

207206
private static bool IsUsingRoamingPath(string filePath)
208207
{
209-
if (string.IsNullOrEmpty(filePath))
210-
return false;
208+
if (string.IsNullOrEmpty(filePath)) return false;
211209

212210
return filePath.StartsWith(DataLocation.RoamingDataPath);
213211
}
@@ -217,7 +215,7 @@ private static string GetUpdatedEnvironmentPath(string filePath)
217215
var index = filePath.IndexOf(DataLocation.PluginEnvironments);
218216

219217
// get the substring after "Environments" because we can not determine it dynamically
220-
var ExecutablePathSubstring = filePath.Substring(index + DataLocation.PluginEnvironments.Count());
218+
var ExecutablePathSubstring = filePath[(index + DataLocation.PluginEnvironments.Length)..];
221219
return $"{DataLocation.PluginEnvironmentsPath}{ExecutablePathSubstring}";
222220
}
223221
}

0 commit comments

Comments
 (0)