mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-13 12:14:16 +01:00
Fire ActivePluginsChanged after a plugin loaded/unloaded
This commit is contained in:
parent
b425ee0a2a
commit
6d69b74d0a
3 changed files with 36 additions and 15 deletions
|
|
@ -1294,6 +1294,25 @@ internal class PluginManager : IInternalDisposableService
|
|||
/// <returns>The calling plugin, or null.</returns>
|
||||
public LocalPlugin? FindCallingPlugin() => this.FindCallingPlugin(new StackTrace());
|
||||
|
||||
/// <summary>
|
||||
/// Notifies all plugins that the active plugins list changed.
|
||||
/// </summary>
|
||||
/// <param name="kind">The invalidation kind.</param>
|
||||
/// <param name="affectedInternalNames">The affected plugins.</param>
|
||||
public void NotifyPluginsForStateChange(PluginListInvalidationKind kind, IEnumerable<string> affectedInternalNames)
|
||||
{
|
||||
foreach (var installedPlugin in this.installedPluginsList)
|
||||
{
|
||||
if (!installedPlugin.IsLoaded || installedPlugin.DalamudInterface == null)
|
||||
continue;
|
||||
|
||||
installedPlugin.DalamudInterface.NotifyActivePluginsChanged(
|
||||
kind,
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
affectedInternalNames.Contains(installedPlugin.Manifest.InternalName));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the services that a plugin may have a dependency on.<br />
|
||||
/// This is required, as the lifetime of a plugin cannot be longer than PluginManager,
|
||||
|
|
@ -1823,20 +1842,6 @@ internal class PluginManager : IInternalDisposableService
|
|||
this.OnInstalledPluginsChanged?.InvokeSafely();
|
||||
}
|
||||
|
||||
private void NotifyPluginsForStateChange(PluginListInvalidationKind kind, IEnumerable<string> affectedInternalNames)
|
||||
{
|
||||
foreach (var installedPlugin in this.installedPluginsList)
|
||||
{
|
||||
if (!installedPlugin.IsLoaded || installedPlugin.DalamudInterface == null)
|
||||
continue;
|
||||
|
||||
installedPlugin.DalamudInterface.NotifyActivePluginsChanged(
|
||||
kind,
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
affectedInternalNames.Contains(installedPlugin.Manifest.InternalName));
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadAndStartLoadSyncPlugins()
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -395,6 +395,9 @@ internal class LocalPlugin : IAsyncDisposable
|
|||
this.dalamudInterface);
|
||||
this.State = PluginState.Loaded;
|
||||
Log.Information("Finished loading {PluginName}", this.InternalName);
|
||||
|
||||
var manager = Service<PluginManager>.Get();
|
||||
manager.NotifyPluginsForStateChange(PluginListInvalidationKind.Load, [this.manifest.InternalName]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
@ -470,6 +473,9 @@ internal class LocalPlugin : IAsyncDisposable
|
|||
|
||||
this.State = PluginState.Unloaded;
|
||||
Log.Information("Finished unloading {PluginName}", this.InternalName);
|
||||
|
||||
var manager = Service<PluginManager>.Get();
|
||||
manager.NotifyPluginsForStateChange(PluginListInvalidationKind.Unload, [this.manifest.InternalName]);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,10 +1,20 @@
|
|||
namespace Dalamud.Plugin;
|
||||
namespace Dalamud.Plugin;
|
||||
|
||||
/// <summary>
|
||||
/// Causes for a change to the plugin list.
|
||||
/// </summary>
|
||||
public enum PluginListInvalidationKind
|
||||
{
|
||||
/// <summary>
|
||||
/// A plugin was loaded.
|
||||
/// </summary>
|
||||
Load,
|
||||
|
||||
/// <summary>
|
||||
/// A plugin was unloaded.
|
||||
/// </summary>
|
||||
Unload,
|
||||
|
||||
/// <summary>
|
||||
/// An installer-initiated update reloaded plugins.
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue