Flow.Launcher/Flow.Launcher.Infrastructure/UserSettings/PluginSettings.cs

84 lines
2.8 KiB
C#
Raw Normal View History

2022-10-23 09:05:12 +00:00
using System.Collections.Generic;
2020-04-21 09:12:17 +00:00
using Flow.Launcher.Plugin;
2020-04-21 09:12:17 +00:00
namespace Flow.Launcher.Infrastructure.UserSettings
{
public class PluginsSettings : BaseModel
{
private string pythonExecutablePath = string.Empty;
2022-11-21 22:20:27 +00:00
public string PythonExecutablePath {
get { return pythonExecutablePath; }
set
{
2022-11-21 22:20:27 +00:00
pythonExecutablePath = value;
Constant.PythonPath = value;
}
}
2022-10-23 09:05:12 +00:00
private string nodeExecutablePath = string.Empty;
2022-11-21 22:20:27 +00:00
public string NodeExecutablePath
{
2022-11-21 22:20:27 +00:00
get { return nodeExecutablePath; }
set
{
2022-11-21 22:20:27 +00:00
nodeExecutablePath = value;
Constant.NodePath = value;
}
}
2022-10-23 09:05:12 +00:00
public Dictionary<string, Plugin> Plugins { get; set; } = new Dictionary<string, Plugin>();
2016-05-12 01:45:35 +00:00
public void UpdatePluginSettings(List<PluginMetadata> metadatas)
{
foreach (var metadata in metadatas)
{
if (Plugins.ContainsKey(metadata.ID))
{
var settings = Plugins[metadata.ID];
2020-07-19 12:11:55 +00:00
if (string.IsNullOrEmpty(settings.Version))
settings.Version = metadata.Version;
if (settings.ActionKeywords?.Count > 0)
{
metadata.ActionKeywords = settings.ActionKeywords;
metadata.ActionKeyword = settings.ActionKeywords[0];
}
else
{
metadata.ActionKeywords = new List<string>();
metadata.ActionKeyword = string.Empty;
}
metadata.Disabled = settings.Disabled;
2021-01-05 08:11:38 +00:00
metadata.Priority = settings.Priority;
}
else
{
Plugins[metadata.ID] = new Plugin
{
ID = metadata.ID,
Name = metadata.Name,
2020-07-19 12:11:55 +00:00
Version = metadata.Version,
ActionKeywords = metadata.ActionKeywords,
2021-01-05 08:11:38 +00:00
Disabled = metadata.Disabled,
Priority = metadata.Priority
};
}
}
}
}
public class Plugin
{
public string ID { get; set; }
public string Name { get; set; }
2020-07-19 12:11:55 +00:00
public string Version { get; set; }
public List<string> ActionKeywords { get; set; } // a reference of the action keywords from plugin manager
2021-01-05 08:11:38 +00:00
public int Priority { get; set; }
/// <summary>
/// Used only to save the state of the plugin in settings
/// </summary>
public bool Disabled { get; set; }
}
}