mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Prerequisites - Moved to PluginInfo and FeatureInfo
Features don't have instances until they are enabled so this made sense, Plugins followed suit for consistency's sake
This commit is contained in:
parent
0cfddcbbaf
commit
5cae14efd3
@ -78,11 +78,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IKernel? Kernel { get; internal set; }
|
public IKernel? Kernel { get; internal set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a list of prerequisites for this plugin feature
|
|
||||||
/// </summary>
|
|
||||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The PluginLoader backing this plugin
|
/// The PluginLoader backing this plugin
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -118,6 +113,16 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
return _features.FirstOrDefault(i => i.Instance is T)?.Instance as T;
|
return _features.FirstOrDefault(i => i.Instance is T)?.Instance as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Looks up the feature info the feature of type <typeparamref name="T" />
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of feature to find</typeparam>
|
||||||
|
/// <returns>If found, feature info of the feature</returns>
|
||||||
|
public PluginFeatureInfo? GetFeatureInfo<T>() where T : PluginFeature
|
||||||
|
{
|
||||||
|
return _features.FirstOrDefault(i => i.FeatureType == typeof(T));
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
@ -125,14 +130,6 @@ namespace Artemis.Core
|
|||||||
return Info.ToString();
|
return Info.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the prerequisites of this plugin are met
|
|
||||||
/// </summary>
|
|
||||||
public bool ArePrerequisitesMet()
|
|
||||||
{
|
|
||||||
return Prerequisites.All(p => p.IsMet());
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when the plugin is enabled
|
/// Occurs when the plugin is enabled
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -60,11 +60,6 @@ namespace Artemis.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public TimeSpan RenderTime { get; private set; }
|
public TimeSpan RenderTime { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets a list of prerequisites for this plugin feature
|
|
||||||
/// </summary>
|
|
||||||
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
|
||||||
|
|
||||||
internal PluginFeatureEntity Entity { get; set; } = null!; // Will be set right after construction
|
internal PluginFeatureEntity Entity { get; set; } = null!; // Will be set right after construction
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using Artemis.Core.DataModelExpansions;
|
using Artemis.Core.DataModelExpansions;
|
||||||
using Artemis.Core.DeviceProviders;
|
using Artemis.Core.DeviceProviders;
|
||||||
using Artemis.Core.LayerBrushes;
|
using Artemis.Core.LayerBrushes;
|
||||||
@ -128,6 +130,19 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _instance, value);
|
internal set => SetAndNotify(ref _instance, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a list of prerequisites for this plugin feature
|
||||||
|
/// </summary>
|
||||||
|
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the prerequisites of this feature are met
|
||||||
|
/// </summary>
|
||||||
|
public bool ArePrerequisitesMet()
|
||||||
|
{
|
||||||
|
return Prerequisites.All(p => p.IsMet());
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Linq;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
@ -117,6 +119,20 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _plugin, value);
|
internal set => SetAndNotify(ref _plugin, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a list of prerequisites for this plugin
|
||||||
|
/// </summary>
|
||||||
|
public List<PluginPrerequisite> Prerequisites { get; } = new();
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Determines whether the prerequisites of this plugin are met
|
||||||
|
/// </summary>
|
||||||
|
public bool ArePrerequisitesMet()
|
||||||
|
{
|
||||||
|
return Prerequisites.All(p => p.IsMet());
|
||||||
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -381,7 +381,7 @@ namespace Artemis.Core.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!plugin.ArePrerequisitesMet())
|
if (!plugin.Info.ArePrerequisitesMet())
|
||||||
throw new ArtemisPluginPrerequisiteException(plugin, null, "Cannot enable a plugin whose prerequisites aren't all met");
|
throw new ArtemisPluginPrerequisiteException(plugin, null, "Cannot enable a plugin whose prerequisites aren't all met");
|
||||||
|
|
||||||
// Create the Ninject child kernel and load the module
|
// Create the Ninject child kernel and load the module
|
||||||
|
|||||||
@ -27,12 +27,12 @@ namespace Artemis.UI.Screens.Plugins
|
|||||||
if (pluginOrFeature is Plugin plugin)
|
if (pluginOrFeature is Plugin plugin)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(plugin.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false)));
|
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(plugin.Info.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false)));
|
||||||
}
|
}
|
||||||
else if (pluginOrFeature is PluginFeature feature)
|
else if (pluginOrFeature is PluginFeature feature)
|
||||||
{
|
{
|
||||||
Feature = feature;
|
Feature = feature;
|
||||||
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(feature.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false)));
|
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(feature.Info.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, false)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new ArtemisUIException($"Expected plugin or feature to be passed to {nameof(PluginPrerequisitesInstallDialogViewModel)}");
|
throw new ArtemisUIException($"Expected plugin or feature to be passed to {nameof(PluginPrerequisitesInstallDialogViewModel)}");
|
||||||
@ -136,7 +136,10 @@ namespace Artemis.UI.Screens.Plugins
|
|||||||
protected override void OnInitialActivate()
|
protected override void OnInitialActivate()
|
||||||
{
|
{
|
||||||
CanInstall = false;
|
CanInstall = false;
|
||||||
Task.Run(() => CanInstall = !Plugin.ArePrerequisitesMet());
|
if (Plugin != null)
|
||||||
|
Task.Run(() => CanInstall = !Plugin.Info.ArePrerequisitesMet());
|
||||||
|
else
|
||||||
|
Task.Run(() => CanInstall = !Feature.Info.ArePrerequisitesMet());
|
||||||
|
|
||||||
base.OnInitialActivate();
|
base.OnInitialActivate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,12 +32,12 @@ namespace Artemis.UI.Screens.Plugins
|
|||||||
if (pluginOrFeature is Plugin plugin)
|
if (pluginOrFeature is Plugin plugin)
|
||||||
{
|
{
|
||||||
Plugin = plugin;
|
Plugin = plugin;
|
||||||
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(plugin.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, true)));
|
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(plugin.Info.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, true)));
|
||||||
}
|
}
|
||||||
else if (pluginOrFeature is PluginFeature feature)
|
else if (pluginOrFeature is PluginFeature feature)
|
||||||
{
|
{
|
||||||
Feature = feature;
|
Feature = feature;
|
||||||
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(feature.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, true)));
|
Prerequisites = new BindableCollection<PluginPrerequisiteViewModel>(feature.Info.Prerequisites.Select(p => prerequisitesVmFactory.PluginPrerequisiteViewModel(p, true)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw new ArtemisUIException($"Expected plugin or feature to be passed to {nameof(PluginPrerequisitesInstallDialogViewModel)}");
|
throw new ArtemisUIException($"Expected plugin or feature to be passed to {nameof(PluginPrerequisitesInstallDialogViewModel)}");
|
||||||
@ -144,7 +144,10 @@ namespace Artemis.UI.Screens.Plugins
|
|||||||
{
|
{
|
||||||
CanUninstall = false;
|
CanUninstall = false;
|
||||||
// Could be slow so take it off of the UI thread
|
// Could be slow so take it off of the UI thread
|
||||||
Task.Run(() => CanUninstall = Plugin.Prerequisites.Any(p => p.IsMet()));
|
if (Plugin != null)
|
||||||
|
Task.Run(() => CanUninstall = Plugin.Info.Prerequisites.Any(p => p.IsMet()));
|
||||||
|
else
|
||||||
|
Task.Run(() => CanUninstall = Feature.Info.Prerequisites.Any(p => p.IsMet()));
|
||||||
|
|
||||||
base.OnInitialActivate();
|
base.OnInitialActivate();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,13 +140,13 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
|
|
||||||
public async Task InstallPrerequisites()
|
public async Task InstallPrerequisites()
|
||||||
{
|
{
|
||||||
if (Plugin.Prerequisites.Any())
|
if (Plugin.Info.Prerequisites.Any())
|
||||||
await ShowPrerequisitesDialog(false);
|
await ShowPrerequisitesDialog(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RemovePrerequisites()
|
public async Task RemovePrerequisites()
|
||||||
{
|
{
|
||||||
if (Plugin.Prerequisites.Any(p => p.UninstallActions.Any()))
|
if (Plugin.Info.Prerequisites.Any(p => p.UninstallActions.Any()))
|
||||||
{
|
{
|
||||||
await ShowPrerequisitesDialog(true);
|
await ShowPrerequisitesDialog(true);
|
||||||
NotifyOfPropertyChange(nameof(IsEnabled));
|
NotifyOfPropertyChange(nameof(IsEnabled));
|
||||||
@ -179,6 +179,12 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
if (!confirmed)
|
if (!confirmed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// If the plugin or any of its features has uninstall actions, offer to run these
|
||||||
|
if (Plugin.Info.Prerequisites.Any(p => p.UninstallActions.Any()) || Plugin.Features.Any(f => f.Prerequisites.Any(fp => fp.UninstallActions.Any())))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_pluginManagementService.RemovePlugin(Plugin, false);
|
_pluginManagementService.RemovePlugin(Plugin, false);
|
||||||
@ -236,10 +242,10 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if all prerequisites are met async
|
// Check if all prerequisites are met async
|
||||||
if (!Plugin.ArePrerequisitesMet())
|
if (!Plugin.Info.ArePrerequisitesMet())
|
||||||
{
|
{
|
||||||
await ShowPrerequisitesDialog(false);
|
await ShowPrerequisitesDialog(false);
|
||||||
if (!Plugin.ArePrerequisitesMet())
|
if (!Plugin.Info.ArePrerequisitesMet())
|
||||||
{
|
{
|
||||||
CancelEnable();
|
CancelEnable();
|
||||||
return;
|
return;
|
||||||
@ -275,8 +281,8 @@ namespace Artemis.UI.Screens.Settings.Tabs.Plugins
|
|||||||
|
|
||||||
private void CheckPrerequisites()
|
private void CheckPrerequisites()
|
||||||
{
|
{
|
||||||
CanInstallPrerequisites = Plugin.Prerequisites.Any();
|
CanInstallPrerequisites = Plugin.Info.Prerequisites.Any();
|
||||||
CanRemovePrerequisites = Plugin.Prerequisites.Any(p => p.UninstallActions.Any());
|
CanRemovePrerequisites = Plugin.Info.Prerequisites.Any(p => p.UninstallActions.Any());
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task<object> ShowPrerequisitesDialog(bool uninstall)
|
private async Task<object> ShowPrerequisitesDialog(bool uninstall)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user