1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Plugins - Don't load incompatible plugins

This commit is contained in:
Robert 2022-08-02 21:17:53 +02:00
parent dc17253518
commit 73a80ef476
4 changed files with 23 additions and 11 deletions

View File

@ -37,7 +37,7 @@ namespace Artemis.Core.Services
/// Loads the plugin located in the provided <paramref name="directory" />
/// </summary>
/// <param name="directory">The directory where the plugin is located</param>
Plugin LoadPlugin(DirectoryInfo directory);
Plugin? LoadPlugin(DirectoryInfo directory);
/// <summary>
/// Enables the provided <paramref name="plugin" />
@ -68,7 +68,7 @@ namespace Artemis.Core.Services
/// </summary>
/// <param name="fileName">The full path to the ZIP file that contains the plugin</param>
/// <returns>The resulting plugin</returns>
Plugin ImportPlugin(string fileName);
Plugin? ImportPlugin(string fileName);
/// <summary>
/// Unloads and permanently removes the provided plugin

View File

@ -292,7 +292,7 @@ namespace Artemis.Core.Services
}
}
public Plugin LoadPlugin(DirectoryInfo directory)
public Plugin? LoadPlugin(DirectoryInfo directory)
{
_logger.Verbose("Loading plugin from {directory}", directory.FullName);
@ -304,6 +304,9 @@ namespace Artemis.Core.Services
// PluginInfo contains the ID which we need to move on
PluginInfo pluginInfo = CoreJson.DeserializeObject<PluginInfo>(File.ReadAllText(metadataFile))!;
if (!pluginInfo.IsCompatible)
return null;
if (pluginInfo.Guid == Constants.CorePluginInfo.Guid)
throw new ArtemisPluginException($"Plugin {pluginInfo} cannot use reserved GUID {pluginInfo.Guid}");
@ -531,7 +534,7 @@ namespace Artemis.Core.Services
OnPluginDisabled(new PluginEventArgs(plugin));
}
public Plugin ImportPlugin(string fileName)
public Plugin? ImportPlugin(string fileName)
{
DirectoryInfo pluginDirectory = new(Constants.PluginsFolder);

View File

@ -13,7 +13,7 @@ namespace Artemis.UI.Screens.Plugins;
public class PluginSettingsViewModel : ActivatableViewModelBase
{
private Plugin _plugin;
private readonly Plugin _plugin;
private readonly IPluginManagementService _pluginManagementService;
private readonly INotificationService _notificationService;
@ -41,10 +41,13 @@ public class PluginSettingsViewModel : ActivatableViewModelBase
bool wasEnabled = _plugin.IsEnabled;
await Task.Run(() => _pluginManagementService.UnloadPlugin(_plugin));
_plugin = _pluginManagementService.LoadPlugin(_plugin.Directory);
if (wasEnabled)
await Task.Run(() => _pluginManagementService.EnablePlugin(_plugin, true, true));
_notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show();
Plugin? plugin = _pluginManagementService.LoadPlugin(_plugin.Directory);
if (plugin != null && wasEnabled)
{
await Task.Run(() => _pluginManagementService.EnablePlugin(plugin, true, true));
_notificationService.CreateNotification().WithTitle("Reloaded plugin.").Show();
}
else if (plugin == null)
_notificationService.CreateNotification().WithTitle("Failed to load plugin after unloading it.").Show();
}
}

View File

@ -82,7 +82,13 @@ namespace Artemis.UI.Screens.Settings
try
{
Plugin plugin = _pluginManagementService.ImportPlugin(files[0]);
Plugin? plugin = _pluginManagementService.ImportPlugin(files[0]);
if (plugin == null)
{
await _windowService.ShowConfirmContentDialog("Failed to import plugin", "Make sure it is compatible with the current platform.", "Close", null);
return;
}
SearchPluginInput = plugin.Info.Name;
// Wait for the VM to be created asynchronously (it would be better to respond to some event here)