fix: find matching plugins when importing a profile

This commit is contained in:
goat 2023-09-21 19:08:58 +02:00
parent a9f6d6d104
commit 6e54c085fa
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B
3 changed files with 27 additions and 0 deletions

View file

@ -1299,6 +1299,9 @@ internal partial class PluginManager : IDisposable, IServiceType
}
// Perform a migration from InternalName to GUIDs. The plugin should definitely have a GUID here.
// This will also happen if you are installing a plugin with the installer, and that's intended!
// It means that, if you have a profile which has unsatisfied plugins, installing a matching plugin will
// enter it into the profiles it can match.
if (plugin.Manifest.WorkingPluginId == Guid.Empty)
throw new Exception("Plugin should have a WorkingPluginId at this point");
this.profileManager.MigrateProfilesToGuidsForPlugin(plugin.Manifest.InternalName, plugin.Manifest.WorkingPluginId);

View file

@ -246,6 +246,10 @@ internal class Profile
{
foreach (var plugin in this.modelV1.Plugins)
{
// TODO: What should happen if a profile has a GUID locked in, but the plugin
// is not installed anymore? That probably means that the user uninstalled the plugin
// and is now reinstalling it. We should still satisfy that and update the ID.
if (plugin.InternalName == internalName && plugin.WorkingPluginId == Guid.Empty)
{
plugin.WorkingPluginId = newGuid;

View file

@ -172,7 +172,27 @@ internal class ProfileManager : IServiceType
newModel.Guid = Guid.NewGuid();
newModel.Name = this.GenerateUniqueProfileName(newModel.Name.IsNullOrEmpty() ? "Unknown Collection" : newModel.Name);
if (newModel is ProfileModelV1 modelV1)
{
// Disable it
modelV1.IsEnabled = false;
// Try to find matching plugins for all plugins in the profile
var pm = Service<PluginManager>.Get();
foreach (var plugin in modelV1.Plugins)
{
var installedPlugin = pm.InstalledPlugins.FirstOrDefault(x => x.Manifest.InternalName == plugin.InternalName);
if (installedPlugin != null)
{
Log.Information("Satisfying plugin {InternalName} for profile {Name} with {Guid}", plugin.InternalName, newModel.Name, installedPlugin.Manifest.WorkingPluginId);
plugin.WorkingPluginId = installedPlugin.Manifest.WorkingPluginId;
}
else
{
Log.Warning("Couldn't find plugin {InternalName} for profile {Name}", plugin.InternalName, newModel.Name);
plugin.WorkingPluginId = Guid.Empty;
}
}
}
this.config.SavedProfiles!.Add(newModel);
this.config.QueueSave();