mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Plugin info - Implemented property changed
Plugins - Improved enable failure detection Plugins UI - Show an indicator on plugins that failed to enable Plugins UI - Show a progress indicator on plugins that are enabling UI - Added reusable Snackbar (not the Dutch kind with kroketten)
This commit is contained in:
1 parent
28bcfcc95a
commit
a47eedf1c2
18 files changed
+399
-179
No files matched your search
@@ -52,13 +52,30 @@ namespace Artemis.Core.Plugins.Abstract
|
||||
if (enable && !Enabled)
|
||||
{
|
||||
Enabled = true;
|
||||
EnablePlugin();
|
||||
PluginInfo.Enabled = true;
|
||||
|
||||
// If enable failed, put it back in a disabled state
|
||||
try
|
||||
{
|
||||
EnablePlugin();
|
||||
}
|
||||
catch
|
||||
{
|
||||
Enabled = false;
|
||||
PluginInfo.Enabled = false;
|
||||
throw;
|
||||
}
|
||||
|
||||
OnPluginEnabled();
|
||||
}
|
||||
else if (!enable && Enabled)
|
||||
{
|
||||
Enabled = false;
|
||||
PluginInfo.Enabled = false;
|
||||
|
||||
// Even if disable failed, still leave it in a disabled state to avoid more issues
|
||||
DisablePlugin();
|
||||
|
||||
OnPluginDisabled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,24 @@ using Artemis.Core.Plugins.Abstract;
|
||||
using Artemis.Storage.Entities.Plugins;
|
||||
using McMaster.NETCore.Plugins;
|
||||
using Newtonsoft.Json;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.Core.Plugins.Models
|
||||
{
|
||||
public class PluginInfo
|
||||
[JsonObject(MemberSerialization.OptIn)]
|
||||
public class PluginInfo : PropertyChangedBase
|
||||
{
|
||||
private Guid _guid;
|
||||
private string _name;
|
||||
private string _description;
|
||||
private string _icon;
|
||||
private Version _version;
|
||||
private string _main;
|
||||
private DirectoryInfo _directory;
|
||||
private Plugin _instance;
|
||||
private bool _enabled;
|
||||
private bool _lastEnableSuccessful;
|
||||
|
||||
internal PluginInfo()
|
||||
{
|
||||
}
|
||||
@@ -18,77 +31,125 @@ namespace Artemis.Core.Plugins.Models
|
||||
/// The plugins GUID
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public Guid Guid { get; internal set; }
|
||||
public Guid Guid
|
||||
{
|
||||
get => _guid;
|
||||
internal set => SetAndNotify(ref _guid, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The name of the plugin
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public string Name { get; internal set; }
|
||||
public string Name
|
||||
{
|
||||
get => _name;
|
||||
internal set => SetAndNotify(ref _name, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A short description of the plugin
|
||||
/// </summary>
|
||||
public string Description { get; set; }
|
||||
[JsonProperty]
|
||||
public string Description
|
||||
{
|
||||
get => _description;
|
||||
set => SetAndNotify(ref _description, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The plugins display icon that's shown in the settings see <see href="https://materialdesignicons.com" /> for
|
||||
/// available
|
||||
/// icons
|
||||
/// </summary>
|
||||
public string Icon { get; set; }
|
||||
[JsonProperty]
|
||||
public string Icon
|
||||
{
|
||||
get => _icon;
|
||||
set => SetAndNotify(ref _icon, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The version of the plugin
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public Version Version { get; internal set; }
|
||||
public Version Version
|
||||
{
|
||||
get => _version;
|
||||
internal set => SetAndNotify(ref _version, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main entry DLL, should contain a class implementing Plugin
|
||||
/// </summary>
|
||||
[JsonProperty(Required = Required.Always)]
|
||||
public string Main { get; internal set; }
|
||||
public string Main
|
||||
{
|
||||
get => _main;
|
||||
internal set => SetAndNotify(ref _main, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The plugins root directory
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public DirectoryInfo Directory { get; internal set; }
|
||||
public DirectoryInfo Directory
|
||||
{
|
||||
get => _directory;
|
||||
internal set => SetAndNotify(ref _directory, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A reference to the type implementing Plugin, available after successful load
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public Plugin Instance { get; internal set; }
|
||||
public Plugin Instance
|
||||
{
|
||||
get => _instance;
|
||||
internal set => SetAndNotify(ref _instance, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the user enabled the plugin or not
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public bool Enabled { get; internal set; }
|
||||
public bool Enabled
|
||||
{
|
||||
get => _enabled;
|
||||
internal set => SetAndNotify(ref _enabled, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether the last time the plugin loaded, it loaded correctly
|
||||
/// </summary>
|
||||
public bool LastEnableSuccessful
|
||||
{
|
||||
get => _lastEnableSuccessful;
|
||||
internal set => SetAndNotify(ref _lastEnableSuccessful, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The PluginLoader backing this plugin
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
internal PluginLoader PluginLoader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The assembly the plugin code lives in
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
internal Assembly Assembly { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The entity representing the plugin
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
internal PluginEntity PluginEntity { get; set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{nameof(Guid)}: {Guid}, {nameof(Name)}: {Name}, {nameof(Version)}: {Version}";
|
||||
return $"{Name} v{Version} - {Guid}";
|
||||
}
|
||||
|
||||
internal void ApplyToEntity()
|
||||
{
|
||||
PluginEntity.Id = Guid;
|
||||
PluginEntity.IsEnabled = Enabled;
|
||||
PluginEntity.LastEnableSuccessful = LastEnableSuccessful;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user