mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Implemented features
Core - Removed Stylet dependency for #500
This commit is contained in:
1 parent
b56966c585
commit
e812929215
139 files changed
+1635
-1106
No files matched your search
@@ -2,7 +2,6 @@
|
||||
using Artemis.Storage.Entities.Plugins;
|
||||
using Artemis.Storage.Repositories.Interfaces;
|
||||
using Newtonsoft.Json;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@@ -10,17 +9,18 @@ namespace Artemis.Core
|
||||
/// Represents a setting tied to a plugin of type <typeparamref name="T" />
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The value type of the setting</typeparam>
|
||||
public class PluginSetting<T> : PropertyChangedBase
|
||||
public class PluginSetting<T> : CorePropertyChanged
|
||||
{
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private readonly PluginInfo _pluginInfo;
|
||||
// TODO: Why? Should have included that...
|
||||
// ReSharper disable once NotAccessedField.Local
|
||||
private readonly Plugin _plugin;
|
||||
private readonly IPluginRepository _pluginRepository;
|
||||
private readonly PluginSettingEntity _pluginSettingEntity;
|
||||
private T _value;
|
||||
|
||||
internal PluginSetting(PluginInfo pluginInfo, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity)
|
||||
internal PluginSetting(Plugin plugin, IPluginRepository pluginRepository, PluginSettingEntity pluginSettingEntity)
|
||||
{
|
||||
_pluginInfo = pluginInfo;
|
||||
_plugin = plugin;
|
||||
_pluginRepository = pluginRepository;
|
||||
_pluginSettingEntity = pluginSettingEntity;
|
||||
|
||||
@@ -52,7 +52,7 @@ namespace Artemis.Core
|
||||
|
||||
_value = value;
|
||||
OnSettingChanged();
|
||||
NotifyOfPropertyChange(nameof(Value));
|
||||
OnPropertyChanged(nameof(Value));
|
||||
|
||||
if (AutoSave)
|
||||
Save();
|
||||
|
||||
@@ -14,17 +14,17 @@ namespace Artemis.Core
|
||||
private readonly IPluginRepository _pluginRepository;
|
||||
private readonly Dictionary<string, object> _settingEntities;
|
||||
|
||||
internal PluginSettings(PluginInfo pluginInfo, IPluginRepository pluginRepository)
|
||||
internal PluginSettings(Plugin plugin, IPluginRepository pluginRepository)
|
||||
{
|
||||
PluginInfo = pluginInfo;
|
||||
Plugin = plugin;
|
||||
_pluginRepository = pluginRepository;
|
||||
_settingEntities = new Dictionary<string, object>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the info of the plugin this setting belongs to
|
||||
/// Gets the plugin these settings belong to
|
||||
/// </summary>
|
||||
public PluginInfo PluginInfo { get; }
|
||||
public Plugin Plugin { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the setting with the provided name. If the setting does not exist yet, it is created.
|
||||
@@ -41,15 +41,15 @@ namespace Artemis.Core
|
||||
if (_settingEntities.ContainsKey(name))
|
||||
return (PluginSetting<T>) _settingEntities[name];
|
||||
// Try to find in database
|
||||
PluginSettingEntity settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, PluginInfo.Guid);
|
||||
PluginSettingEntity settingEntity = _pluginRepository.GetSettingByNameAndGuid(name, Plugin.Guid);
|
||||
// If not found, create a new one
|
||||
if (settingEntity == null)
|
||||
{
|
||||
settingEntity = new PluginSettingEntity {Name = name, PluginGuid = PluginInfo.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
settingEntity = new PluginSettingEntity {Name = name, PluginGuid = Plugin.Guid, Value = JsonConvert.SerializeObject(defaultValue)};
|
||||
_pluginRepository.AddSetting(settingEntity);
|
||||
}
|
||||
|
||||
PluginSetting<T> pluginSetting = new PluginSetting<T>(PluginInfo, _pluginRepository, settingEntity);
|
||||
PluginSetting<T> pluginSetting = new PluginSetting<T>(Plugin, _pluginRepository, settingEntity);
|
||||
|
||||
// This overrides null with the default value, I'm not sure if that's desirable because you
|
||||
// might expect something to go null and you might not
|
||||
|
||||
Reference in new issue
Block a user