Plugins - Added button to delete plugin settings

UI - Try to release SDKs on Windows logout/shutdown
Plugins UI - Increased width and fixed long feature names not wrapping
This commit is contained in:
Robert committed 2021-03-30 19:15:16 +02:00
1 parent 7a5f07c686
commit 1eebb1f247
15 files changed
+174 -116

No files matched your search

+4 -1
View File
@@ -1,4 +1,7 @@
using System.IO;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Artemis.Core.Services;
using Artemis.Storage;
using Artemis.Storage.Migrations.Interfaces;
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using Ninject.Activation;
using Serilog;
using Serilog.Core;
+82 -86
View File
@@ -88,6 +88,11 @@ namespace Artemis.Core
/// </summary>
internal PluginEntity Entity { get; set; }
/// <summary>
/// Populated when plugin settings are first loaded
/// </summary>
internal PluginSettings? Settings { get; set; }
/// <summary>
/// Resolves the relative path provided in the <paramref name="path" /> parameter to an absolute path
/// </summary>
@@ -101,7 +106,6 @@ namespace Artemis.Core
/// <summary>
/// Looks up the instance of the feature of type <typeparamref name="T" />
/// <para>Note: This method only returns instances of enabled features</para>
/// </summary>
/// <typeparam name="T">The type of feature to find</typeparam>
/// <returns>If found, the instance of the feature</returns>
@@ -116,6 +120,83 @@ namespace Artemis.Core
return Info.ToString();
}
/// <summary>
/// Occurs when the plugin is enabled
/// </summary>
public event EventHandler? Enabled;
/// <summary>
/// Occurs when the plugin is disabled
/// </summary>
public event EventHandler? Disabled;
/// <summary>
/// Occurs when an feature is loaded and added to the plugin
/// </summary>
public event EventHandler<PluginFeatureInfoEventArgs>? FeatureAdded;
/// <summary>
/// Occurs when an feature is disabled and removed from the plugin
/// </summary>
public event EventHandler<PluginFeatureInfoEventArgs>? FeatureRemoved;
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
foreach (PluginFeatureInfo feature in Features)
feature.Instance?.Dispose();
SetEnabled(false);
Kernel?.Dispose();
PluginLoader?.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
_features.Clear();
}
}
/// <summary>
/// Invokes the Enabled event
/// </summary>
protected virtual void OnEnabled()
{
Enabled?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Invokes the Disabled event
/// </summary>
protected virtual void OnDisabled()
{
Disabled?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Invokes the FeatureAdded event
/// </summary>
protected virtual void OnFeatureAdded(PluginFeatureInfoEventArgs e)
{
FeatureAdded?.Invoke(this, e);
}
/// <summary>
/// Invokes the FeatureRemoved event
/// </summary>
protected virtual void OnFeatureRemoved(PluginFeatureInfoEventArgs e)
{
FeatureRemoved?.Invoke(this, e);
}
internal void ApplyToEntity()
{
Entity.Id = Guid;
@@ -169,96 +250,11 @@ namespace Artemis.Core
return Entity.Features.Any(f => f.IsEnabled) || Features.Any(f => f.AlwaysEnabled);
}
#region IDisposable
/// <summary>
/// Releases the unmanaged resources used by the object and optionally releases the managed resources.
/// </summary>
/// <param name="disposing">
/// <see langword="true" /> to release both managed and unmanaged resources;
/// <see langword="false" /> to release only unmanaged resources.
/// </param>
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
foreach (PluginFeatureInfo feature in Features)
feature.Instance?.Dispose();
SetEnabled(false);
Kernel?.Dispose();
PluginLoader?.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
_features.Clear();
}
}
/// <inheritdoc />
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
#region Events
/// <summary>
/// Occurs when the plugin is enabled
/// </summary>
public event EventHandler? Enabled;
/// <summary>
/// Occurs when the plugin is disabled
/// </summary>
public event EventHandler? Disabled;
/// <summary>
/// Occurs when an feature is loaded and added to the plugin
/// </summary>
public event EventHandler<PluginFeatureInfoEventArgs>? FeatureAdded;
/// <summary>
/// Occurs when an feature is disabled and removed from the plugin
/// </summary>
public event EventHandler<PluginFeatureInfoEventArgs>? FeatureRemoved;
/// <summary>
/// Invokes the Enabled event
/// </summary>
protected virtual void OnEnabled()
{
Enabled?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Invokes the Disabled event
/// </summary>
protected virtual void OnDisabled()
{
Disabled?.Invoke(this, EventArgs.Empty);
}
/// <summary>
/// Invokes the FeatureAdded event
/// </summary>
protected virtual void OnFeatureAdded(PluginFeatureInfoEventArgs e)
{
FeatureAdded?.Invoke(this, e);
}
/// <summary>
/// Invokes the FeatureRemoved event
/// </summary>
protected virtual void OnFeatureRemoved(PluginFeatureInfoEventArgs e)
{
FeatureRemoved?.Invoke(this, e);
}
#endregion
}
}
@@ -17,6 +17,8 @@ namespace Artemis.Core
internal PluginSettings(Plugin plugin, IPluginRepository pluginRepository)
{
Plugin = plugin;
Plugin.Settings = this;
_pluginRepository = pluginRepository;
_settingEntities = new Dictionary<string, object>();
}
@@ -65,5 +67,10 @@ namespace Artemis.Core
return pluginSetting;
}
}
internal void ClearSettings()
{
_settingEntities.Clear();
}
}
}
@@ -74,7 +74,14 @@ namespace Artemis.Core.Services
/// Unloads and permanently removes the provided plugin
/// </summary>
/// <param name="plugin">The plugin to remove</param>
void RemovePlugin(Plugin plugin);
/// <param name="removeSettings"></param>
void RemovePlugin(Plugin plugin, bool removeSettings);
/// <summary>
/// Removes the settings of a disabled plugin
/// </summary>
/// <param name="plugin">The plugin whose settings to remove</param>
void RemovePluginSettings(Plugin plugin);
/// <summary>
/// Enables the provided plugin feature
@@ -134,8 +141,6 @@ namespace Artemis.Core.Services
/// <param name="pluginAction">The action to take</param>
void QueuePluginAction(Plugin plugin, PluginManagementAction pluginAction);
#region Events
/// <summary>
/// Occurs when built-in plugins are being loaded
/// </summary>
@@ -190,7 +195,5 @@ namespace Artemis.Core.Services
/// Occurs when a plugin feature has been disabled
/// </summary>
public event EventHandler<PluginFeatureEventArgs> PluginFeatureDisabled;
#endregion
}
}
@@ -479,7 +479,7 @@ namespace Artemis.Core.Services
if (existing != null)
try
{
RemovePlugin(existing);
RemovePlugin(existing, false);
}
catch (Exception e)
{
@@ -519,7 +519,7 @@ namespace Artemis.Core.Services
return LoadPlugin(directoryInfo);
}
public void RemovePlugin(Plugin plugin)
public void RemovePlugin(Plugin plugin, bool removeSettings)
{
DirectoryInfo directory = plugin.Directory;
lock (_plugins)
@@ -529,6 +529,16 @@ namespace Artemis.Core.Services
}
directory.Delete(true);
if (removeSettings)
RemovePluginSettings(plugin);
}
public void RemovePluginSettings(Plugin plugin)
{
if (plugin.IsEnabled)
throw new ArtemisCoreException("Cannot remove the settings of an enabled plugin");
_pluginRepository.RemoveSettings(plugin.Guid);
plugin.Settings?.ClearSettings();
}
#endregion