This commit is contained in:
Jack Ye 2026-03-10 03:55:21 +00:00 committed by GitHub
commit 8581890cc2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 46 additions and 6 deletions

View file

@ -40,6 +40,12 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
PluginSettings = pluginSettings;
}
/// <summary>
/// Resolves the configured runtime executable path to an absolute path.
/// Supports both absolute paths and relative paths (relative to ProgramDirectory).
/// </summary>
private string ResolvedPluginsSettingsFilePath => DataLocation.ResolveAbsolutePath(PluginsSettingsFilePath);
internal IEnumerable<PluginPair> Setup()
{
// If no plugin is using the language, return empty list
@ -48,13 +54,16 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
return new List<PluginPair>();
}
if (!string.IsNullOrEmpty(PluginsSettingsFilePath) && FilesFolders.FileExists(PluginsSettingsFilePath))
var resolvedPath = ResolvedPluginsSettingsFilePath;
if (!string.IsNullOrEmpty(resolvedPath) && FilesFolders.FileExists(resolvedPath))
{
// Ensure latest only if user is using Flow's environment setup.
if (PluginsSettingsFilePath.StartsWith(EnvPath, StringComparison.OrdinalIgnoreCase))
EnsureLatestInstalled(ExecutablePath, PluginsSettingsFilePath, EnvPath);
if (resolvedPath.StartsWith(EnvPath, StringComparison.OrdinalIgnoreCase))
EnsureLatestInstalled(ExecutablePath, resolvedPath, EnvPath);
return SetPathForPluginPairs(PluginsSettingsFilePath, Language);
// Ensure the path is updated in settings in case environment was updated
resolvedPath = ResolvedPluginsSettingsFilePath;
return SetPathForPluginPairs(resolvedPath, Language);
}
var noRuntimeMessage = Localize.runtimePluginInstalledChooseRuntimePrompt(Language, EnvName, Environment.NewLine);
@ -103,9 +112,11 @@ namespace Flow.Launcher.Core.ExternalPlugins.Environments
InstallEnvironment();
}
if (FilesFolders.FileExists(PluginsSettingsFilePath))
// Ensure the path is updated when user has chosen to install or select environment executable
resolvedPath = ResolvedPluginsSettingsFilePath;
if (FilesFolders.FileExists(resolvedPath))
{
return SetPathForPluginPairs(PluginsSettingsFilePath, Language);
return SetPathForPluginPairs(resolvedPath, Language);
}
else
{

View file

@ -42,5 +42,34 @@ namespace Flow.Launcher.Infrastructure.UserSettings
public const string PluginEnvironments = "Environments";
public const string PluginDeleteFile = "NeedDelete.txt";
public static readonly string PluginEnvironmentsPath = Path.Combine(DataDirectory(), PluginEnvironments);
/// <summary>
/// Resolves a path that may be relative to an absolute path.
/// If the path is already absolute, returns it as-is.
/// If the path is not rooted (as determined by <see cref="Path.IsPathRooted(string)"/>), resolves it relative to ProgramDirectory.
/// </summary>
/// <param name="path">The path to resolve</param>
/// <returns>An absolute path</returns>
public static string ResolveAbsolutePath(string path)
{
if (string.IsNullOrEmpty(path))
return path;
// If already absolute, return as-is
if (Path.IsPathFullyQualified(path))
return path;
// Resolve relative to ProgramDirectory, handling invalid path formats gracefully
try
{
return Path.GetFullPath(Path.Combine(Constant.ProgramDirectory, path));
}
catch (System.Exception)
{
// If the path cannot be resolved (invalid characters, format, or too long),
// return the original path to avoid crashing the application.
return path;
}
}
}
}