mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-15 21:24:16 +01:00
Merge pull request #556 from goatcorp/populatePlugins
fix: populate available plugins in SetPluginReposFromConfigAsync
This commit is contained in:
commit
a31c8aefc1
1 changed files with 23 additions and 40 deletions
|
|
@ -41,10 +41,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
private readonly DirectoryInfo devPluginDirectory;
|
private readonly DirectoryInfo devPluginDirectory;
|
||||||
private readonly BannedPlugin[] bannedPlugins;
|
private readonly BannedPlugin[] bannedPlugins;
|
||||||
|
|
||||||
private readonly List<LocalPlugin> installedPlugins = new();
|
|
||||||
private List<RemotePluginManifest> availablePlugins = new();
|
|
||||||
private List<AvailablePluginUpdate> updatablePlugins = new();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
/// Initializes a new instance of the <see cref="PluginManager"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -130,7 +126,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
foreach (var plugin in this.installedPlugins.ToArray())
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
@ -159,14 +155,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
.Select(repo => new PluginRepository(repo.Url, repo.IsEnabled)));
|
.Select(repo => new PluginRepository(repo.Url, repo.IsEnabled)));
|
||||||
|
|
||||||
this.Repos = repos;
|
this.Repos = repos;
|
||||||
|
await this.ReloadPluginMastersAsync(notify);
|
||||||
if (notify)
|
|
||||||
this.NotifyAvailablePluginsChanged();
|
|
||||||
|
|
||||||
foreach (var repo in repos)
|
|
||||||
{
|
|
||||||
await repo.ReloadPluginMasterAsync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -284,10 +273,8 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
var aggregate = new List<Exception>();
|
var aggregate = new List<Exception>();
|
||||||
|
|
||||||
for (var i = 0; i < this.installedPlugins.Count; i++)
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
var plugin = this.installedPlugins[i];
|
|
||||||
|
|
||||||
if (plugin.IsLoaded)
|
if (plugin.IsLoaded)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
|
@ -312,29 +299,31 @@ namespace Dalamud.Plugin.Internal
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reload the PluginMaster for each repo, filter, and event that the list has updated.
|
/// Reload the PluginMaster for each repo, filter, and event that the list has updated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="notify">Whether to notify that available plugins have changed afterwards.</param>
|
||||||
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
|
||||||
public async Task ReloadPluginMastersAsync()
|
public async Task ReloadPluginMastersAsync(bool notify = true)
|
||||||
{
|
{
|
||||||
foreach (var repo in this.Repos)
|
await Task.WhenAll(this.Repos.Select(repo => repo.ReloadPluginMasterAsync()));
|
||||||
{
|
|
||||||
await repo.ReloadPluginMasterAsync();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.RefilterPluginMasters();
|
this.RefilterPluginMasters(notify);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Apply visibility and eligibility filters to the available plugins, then event that the list has updated.
|
/// Apply visibility and eligibility filters to the available plugins, then event that the list has updated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void RefilterPluginMasters()
|
/// <param name="notify">Whether to notify that available plugins have changed afterwards.</param>
|
||||||
|
public void RefilterPluginMasters(bool notify = true)
|
||||||
{
|
{
|
||||||
this.availablePlugins = this.Repos
|
this.AvailablePlugins = this.Repos
|
||||||
.SelectMany(repo => repo.PluginMaster)
|
.SelectMany(repo => repo.PluginMaster)
|
||||||
.Where(this.IsManifestEligible)
|
.Where(this.IsManifestEligible)
|
||||||
.Where(this.IsManifestVisible)
|
.Where(this.IsManifestVisible)
|
||||||
.ToList();
|
.ToImmutableList();
|
||||||
|
|
||||||
this.NotifyAvailablePluginsChanged();
|
if (notify)
|
||||||
|
{
|
||||||
|
this.NotifyAvailablePluginsChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -581,7 +570,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.installedPlugins.Add(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Add(plugin);
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -594,7 +583,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
if (plugin.State != PluginState.Unloaded)
|
if (plugin.State != PluginState.Unloaded)
|
||||||
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded");
|
throw new InvalidPluginOperationException($"Unable to remove {plugin.Name}, not unloaded");
|
||||||
|
|
||||||
this.installedPlugins.Remove(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
|
||||||
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
PluginLocations.Remove(plugin.AssemblyName.FullName);
|
||||||
|
|
||||||
this.NotifyInstalledPluginsChanged();
|
this.NotifyInstalledPluginsChanged();
|
||||||
|
|
@ -707,9 +696,9 @@ namespace Dalamud.Plugin.Internal
|
||||||
var updatedList = new List<PluginUpdateStatus>();
|
var updatedList = new List<PluginUpdateStatus>();
|
||||||
|
|
||||||
// Prevent collection was modified errors
|
// Prevent collection was modified errors
|
||||||
for (var i = 0; i < this.updatablePlugins.Count; i++)
|
foreach (var plugin in this.UpdatablePlugins)
|
||||||
{
|
{
|
||||||
var result = await this.UpdateSinglePluginAsync(this.updatablePlugins[i], false, dryRun);
|
var result = await this.UpdateSinglePluginAsync(plugin, false, dryRun);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
updatedList.Add(result);
|
updatedList.Add(result);
|
||||||
}
|
}
|
||||||
|
|
@ -767,7 +756,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
plugin.Disable();
|
plugin.Disable();
|
||||||
this.installedPlugins.Remove(plugin);
|
this.InstalledPlugins = this.InstalledPlugins.Remove(plugin);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
@ -939,15 +928,13 @@ namespace Dalamud.Plugin.Internal
|
||||||
{
|
{
|
||||||
var updatablePlugins = new List<AvailablePluginUpdate>();
|
var updatablePlugins = new List<AvailablePluginUpdate>();
|
||||||
|
|
||||||
for (var i = 0; i < this.installedPlugins.Count; i++)
|
foreach (var plugin in this.InstalledPlugins)
|
||||||
{
|
{
|
||||||
var plugin = this.installedPlugins[i];
|
|
||||||
|
|
||||||
var installedVersion = plugin.IsTesting
|
var installedVersion = plugin.IsTesting
|
||||||
? plugin.Manifest.TestingAssemblyVersion
|
? plugin.Manifest.TestingAssemblyVersion
|
||||||
: plugin.Manifest.AssemblyVersion;
|
: plugin.Manifest.AssemblyVersion;
|
||||||
|
|
||||||
var updates = this.availablePlugins
|
var updates = this.AvailablePlugins
|
||||||
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
|
.Where(remoteManifest => plugin.Manifest.InternalName == remoteManifest.InternalName)
|
||||||
.Select(remoteManifest =>
|
.Select(remoteManifest =>
|
||||||
{
|
{
|
||||||
|
|
@ -969,7 +956,7 @@ namespace Dalamud.Plugin.Internal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updatablePlugins = updatablePlugins;
|
this.UpdatablePlugins = updatablePlugins.ToImmutableList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NotifyAvailablePluginsChanged()
|
private void NotifyAvailablePluginsChanged()
|
||||||
|
|
@ -978,8 +965,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.AvailablePlugins = ImmutableList.CreateRange(this.availablePlugins);
|
|
||||||
this.UpdatablePlugins = ImmutableList.CreateRange(this.updatablePlugins);
|
|
||||||
this.OnAvailablePluginsChanged?.Invoke();
|
this.OnAvailablePluginsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -994,8 +979,6 @@ namespace Dalamud.Plugin.Internal
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.InstalledPlugins = ImmutableList.CreateRange(this.installedPlugins);
|
|
||||||
this.UpdatablePlugins = ImmutableList.CreateRange(this.updatablePlugins);
|
|
||||||
this.OnInstalledPluginsChanged?.Invoke();
|
this.OnInstalledPluginsChanged?.Invoke();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue