mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
feat: add ActivePluginsChanged event to DPI (closes #1192)
This commit is contained in:
parent
fa73ccd3ee
commit
839519b2bb
4 changed files with 59 additions and 2 deletions
|
|
@ -294,7 +294,7 @@ public class ChatHandlers : IServiceType
|
|||
|
||||
this.hasAutoUpdatedPlugins = true;
|
||||
|
||||
Task.Run(() => pluginManager.UpdatePluginsAsync(true, !this.configuration.AutoUpdatePlugins)).ContinueWith(task =>
|
||||
Task.Run(() => pluginManager.UpdatePluginsAsync(true, !this.configuration.AutoUpdatePlugins, true)).ContinueWith(task =>
|
||||
{
|
||||
if (task.IsFaulted)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -88,11 +88,23 @@ public sealed class DalamudPluginInterface : IDisposable
|
|||
/// <param name="langCode">The new language code.</param>
|
||||
public delegate void LanguageChangedDelegate(string langCode);
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for events that listen to changes to the list of active plugins.
|
||||
/// </summary>
|
||||
/// <param name="kind">What action caused this event to be fired.</param>
|
||||
/// <param name="affectedThisPlugin">If this plugin was affected by the change.</param>
|
||||
public delegate void ActivePluginsChangedDelegate(PluginListInvalidationKind kind, bool affectedThisPlugin);
|
||||
|
||||
/// <summary>
|
||||
/// Event that gets fired when loc is changed
|
||||
/// </summary>
|
||||
public event LanguageChangedDelegate LanguageChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Event that is fired when the active list of plugins is changed.
|
||||
/// </summary>
|
||||
public event ActivePluginsChangedDelegate ActivePluginsChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the reason this plugin was loaded.
|
||||
/// </summary>
|
||||
|
|
@ -472,6 +484,16 @@ public sealed class DalamudPluginInterface : IDisposable
|
|||
// ignored
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatch the active plugins changed event.
|
||||
/// </summary>
|
||||
/// <param name="kind">What action caused this event to be fired.</param>
|
||||
/// <param name="affectedThisPlugin">If this plugin was affected by the change.</param>
|
||||
internal void NotifyActivePluginsChanged(PluginListInvalidationKind kind, bool affectedThisPlugin)
|
||||
{
|
||||
this.ActivePluginsChanged.Invoke(kind, affectedThisPlugin);
|
||||
}
|
||||
|
||||
private void OnLocalizationChanged(string langCode)
|
||||
{
|
||||
this.UiLanguage = langCode;
|
||||
|
|
|
|||
|
|
@ -1063,8 +1063,9 @@ Thanks and have fun!";
|
|||
/// </summary>
|
||||
/// <param name="ignoreDisabled">Ignore disabled plugins.</param>
|
||||
/// <param name="dryRun">Perform a dry run, don't install anything.</param>
|
||||
/// <param name="autoUpdate">If this action was performed as part of an auto-update.</param>
|
||||
/// <returns>Success or failure and a list of updated plugin metadata.</returns>
|
||||
public async Task<List<PluginUpdateStatus>> UpdatePluginsAsync(bool ignoreDisabled, bool dryRun)
|
||||
public async Task<List<PluginUpdateStatus>> UpdatePluginsAsync(bool ignoreDisabled, bool dryRun, bool autoUpdate = false)
|
||||
{
|
||||
Log.Information("Starting plugin update");
|
||||
|
||||
|
|
@ -1089,6 +1090,9 @@ Thanks and have fun!";
|
|||
}
|
||||
|
||||
this.NotifyInstalledPluginsChanged();
|
||||
this.NotifyPluginsForStateChange(
|
||||
autoUpdate ? PluginListInvalidationKind.AutoUpdate : PluginListInvalidationKind.Update,
|
||||
updatedList.Select(x => x.InternalName));
|
||||
|
||||
Log.Information("Plugin update OK.");
|
||||
|
||||
|
|
@ -1391,6 +1395,20 @@ Thanks and have fun!";
|
|||
this.OnInstalledPluginsChanged?.InvokeSafely();
|
||||
}
|
||||
|
||||
private void NotifyPluginsForStateChange(PluginListInvalidationKind kind, IEnumerable<string> affectedInternalNames)
|
||||
{
|
||||
foreach (var installedPlugin in this.InstalledPlugins)
|
||||
{
|
||||
if (!installedPlugin.IsLoaded || installedPlugin.DalamudInterface == null)
|
||||
continue;
|
||||
|
||||
installedPlugin.DalamudInterface.NotifyActivePluginsChanged(
|
||||
kind,
|
||||
// ReSharper disable once PossibleMultipleEnumeration
|
||||
affectedInternalNames.Contains(installedPlugin.Manifest.InternalName));
|
||||
}
|
||||
}
|
||||
|
||||
private static class Locs
|
||||
{
|
||||
public static string DalamudPluginUpdateSuccessful(string name, Version version) => Loc.Localize("DalamudPluginUpdateSuccessful", " 》 {0} updated to v{1}.").Format(name, version);
|
||||
|
|
|
|||
17
Dalamud/Plugin/PluginListInvalidationKind.cs
Normal file
17
Dalamud/Plugin/PluginListInvalidationKind.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
namespace Dalamud.Plugin;
|
||||
|
||||
/// <summary>
|
||||
/// Causes for a change to the plugin list.
|
||||
/// </summary>
|
||||
public enum PluginListInvalidationKind
|
||||
{
|
||||
/// <summary>
|
||||
/// An installer-initiated update reloaded plugins.
|
||||
/// </summary>
|
||||
Update,
|
||||
|
||||
/// <summary>
|
||||
/// An auto-update reloaded plugins.
|
||||
/// </summary>
|
||||
AutoUpdate,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue