2022-10-23 09:05:12 +00:00
|
|
|
|
using System.Collections.Generic;
|
2025-03-30 06:41:44 +00:00
|
|
|
|
using System.Text.Json.Serialization;
|
2020-04-21 09:12:17 +00:00
|
|
|
|
using Flow.Launcher.Plugin;
|
2014-07-01 14:19:46 +00:00
|
|
|
|
|
2020-04-21 09:12:17 +00:00
|
|
|
|
namespace Flow.Launcher.Infrastructure.UserSettings
|
2014-07-01 14:19:46 +00:00
|
|
|
|
{
|
2016-05-23 21:08:13 +00:00
|
|
|
|
public class PluginsSettings : BaseModel
|
2016-05-05 00:57:03 +00:00
|
|
|
|
{
|
2022-12-02 08:27:04 +00:00
|
|
|
|
private string pythonExecutablePath = string.Empty;
|
2025-03-30 05:57:35 +00:00
|
|
|
|
public string PythonExecutablePath
|
|
|
|
|
|
{
|
|
|
|
|
|
get => pythonExecutablePath;
|
2022-10-25 10:54:00 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2022-11-21 22:20:27 +00:00
|
|
|
|
pythonExecutablePath = value;
|
2022-10-25 10:54:00 +00:00
|
|
|
|
Constant.PythonPath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-23 09:05:12 +00:00
|
|
|
|
|
2022-12-02 08:27:04 +00:00
|
|
|
|
private string nodeExecutablePath = string.Empty;
|
2022-11-21 22:20:27 +00:00
|
|
|
|
public string NodeExecutablePath
|
2022-10-25 10:54:00 +00:00
|
|
|
|
{
|
2025-03-30 05:57:35 +00:00
|
|
|
|
get => nodeExecutablePath;
|
2022-10-25 10:54:00 +00:00
|
|
|
|
set
|
|
|
|
|
|
{
|
2022-11-21 22:20:27 +00:00
|
|
|
|
nodeExecutablePath = value;
|
2022-10-25 10:54:00 +00:00
|
|
|
|
Constant.NodePath = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-10-23 09:05:12 +00:00
|
|
|
|
|
2025-03-30 06:41:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Only used for serialization
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public Dictionary<string, Plugin> Plugins { get; set; } = new();
|
2016-05-05 00:57:03 +00:00
|
|
|
|
|
2025-03-30 06:41:44 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Update plugin settings with metadata.
|
|
|
|
|
|
/// FL will get default values from metadata first and then load settings to metadata
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="metadatas">Parsed plugin metadatas</param>
|
2016-05-12 01:45:35 +00:00
|
|
|
|
public void UpdatePluginSettings(List<PluginMetadata> metadatas)
|
2016-05-05 00:57:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
foreach (var metadata in metadatas)
|
|
|
|
|
|
{
|
2025-02-24 03:35:41 +00:00
|
|
|
|
if (Plugins.TryGetValue(metadata.ID, out var settings))
|
2016-05-05 00:57:03 +00:00
|
|
|
|
{
|
2025-03-30 06:41:44 +00:00
|
|
|
|
// If settings exist, update settings & metadata value
|
|
|
|
|
|
// update settings values with metadata
|
2020-07-19 12:11:55 +00:00
|
|
|
|
if (string.IsNullOrEmpty(settings.Version))
|
2025-03-30 06:41:44 +00:00
|
|
|
|
{
|
2020-07-19 12:11:55 +00:00
|
|
|
|
settings.Version = metadata.Version;
|
2025-03-30 06:41:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
settings.DefaultActionKeywords = metadata.ActionKeywords; // metadata provides default values
|
2025-03-31 05:26:09 +00:00
|
|
|
|
settings.DefaultSearchDelayTime = metadata.SearchDelayTime; // metadata provides default values
|
2020-07-19 12:11:55 +00:00
|
|
|
|
|
2025-03-30 06:41:44 +00:00
|
|
|
|
// update metadata values with settings
|
2016-05-05 00:57:03 +00:00
|
|
|
|
if (settings.ActionKeywords?.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
metadata.ActionKeywords = settings.ActionKeywords;
|
|
|
|
|
|
metadata.ActionKeyword = settings.ActionKeywords[0];
|
|
|
|
|
|
}
|
2021-05-25 12:20:22 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
metadata.ActionKeywords = new List<string>();
|
|
|
|
|
|
metadata.ActionKeyword = string.Empty;
|
|
|
|
|
|
}
|
2016-05-22 04:30:38 +00:00
|
|
|
|
metadata.Disabled = settings.Disabled;
|
2021-01-05 08:11:38 +00:00
|
|
|
|
metadata.Priority = settings.Priority;
|
2025-03-31 05:26:09 +00:00
|
|
|
|
metadata.SearchDelayTime = settings.SearchDelayTime;
|
2025-05-04 03:26:00 +00:00
|
|
|
|
metadata.HomeDisabled = settings.HomeDisabled;
|
2016-05-05 00:57:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-03-30 06:41:44 +00:00
|
|
|
|
// If settings does not exist, create a new one
|
2016-05-05 00:57:03 +00:00
|
|
|
|
Plugins[metadata.ID] = new Plugin
|
|
|
|
|
|
{
|
|
|
|
|
|
ID = metadata.ID,
|
|
|
|
|
|
Name = metadata.Name,
|
2020-07-19 12:11:55 +00:00
|
|
|
|
Version = metadata.Version,
|
2025-03-30 06:41:44 +00:00
|
|
|
|
DefaultActionKeywords = metadata.ActionKeywords, // metadata provides default values
|
|
|
|
|
|
ActionKeywords = metadata.ActionKeywords, // use default value
|
2021-01-05 08:11:38 +00:00
|
|
|
|
Disabled = metadata.Disabled,
|
2025-05-04 03:26:00 +00:00
|
|
|
|
HomeDisabled = metadata.HomeDisabled,
|
2025-03-18 01:11:15 +00:00
|
|
|
|
Priority = metadata.Priority,
|
2025-03-31 05:26:09 +00:00
|
|
|
|
DefaultSearchDelayTime = metadata.SearchDelayTime, // metadata provides default values
|
|
|
|
|
|
SearchDelayTime = metadata.SearchDelayTime, // use default value
|
2016-05-05 00:57:03 +00:00
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-30 05:59:06 +00:00
|
|
|
|
|
|
|
|
|
|
public Plugin GetPluginSettings(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Plugins.TryGetValue(id, out var plugin))
|
|
|
|
|
|
{
|
|
|
|
|
|
return plugin;
|
2025-03-30 06:41:44 +00:00
|
|
|
|
}
|
2025-03-30 05:59:06 +00:00
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Plugin RemovePluginSettings(string id)
|
|
|
|
|
|
{
|
|
|
|
|
|
Plugins.Remove(id, out var plugin);
|
|
|
|
|
|
return plugin;
|
|
|
|
|
|
}
|
2016-05-05 00:57:03 +00:00
|
|
|
|
}
|
2025-03-30 05:57:35 +00:00
|
|
|
|
|
2016-05-05 00:57:03 +00:00
|
|
|
|
public class Plugin
|
2014-07-01 14:19:46 +00:00
|
|
|
|
{
|
|
|
|
|
|
public string ID { get; set; }
|
2025-03-30 05:57:35 +00:00
|
|
|
|
|
2014-07-01 14:19:46 +00:00
|
|
|
|
public string Name { get; set; }
|
2025-03-30 05:57:35 +00:00
|
|
|
|
|
2020-07-19 12:11:55 +00:00
|
|
|
|
public string Version { get; set; }
|
2025-03-30 06:41:44 +00:00
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
|
public List<string> DefaultActionKeywords { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
// a reference of the action keywords from plugin manager
|
|
|
|
|
|
public List<string> ActionKeywords { get; set; }
|
|
|
|
|
|
|
2021-01-05 08:11:38 +00:00
|
|
|
|
public int Priority { get; set; }
|
2025-03-30 06:41:44 +00:00
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2025-04-07 06:16:17 +00:00
|
|
|
|
public int? DefaultSearchDelayTime { get; set; }
|
2025-03-30 06:41:44 +00:00
|
|
|
|
|
2025-04-07 06:16:17 +00:00
|
|
|
|
public int? SearchDelayTime { get; set; }
|
2020-02-22 09:02:07 +00:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Used only to save the state of the plugin in settings
|
|
|
|
|
|
/// </summary>
|
2014-07-01 14:19:46 +00:00
|
|
|
|
public bool Disabled { get; set; }
|
2025-05-04 03:26:00 +00:00
|
|
|
|
public bool HomeDisabled { get; set; }
|
2014-07-01 14:19:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|