AddonLifcycle Unregistration Fix (#1776)

closes #1768
This commit is contained in:
MidoriKami 2024-04-22 12:38:12 -07:00 committed by GitHub
parent 4f68809ab0
commit 1f0b616e2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 17 additions and 5 deletions

View file

@ -134,6 +134,9 @@ internal unsafe class AddonLifecycle : IInternalDisposableService
/// <param name="listener">The listener to unregister.</param>
internal void UnregisterListener(AddonLifecycleEventListener listener)
{
// Set removed state to true immediately, then lazily remove it from the EventListeners list on next Framework Update.
listener.Removed = true;
this.framework.RunOnTick(() =>
{
this.EventListeners.Remove(listener);
@ -168,6 +171,10 @@ internal unsafe class AddonLifecycle : IInternalDisposableService
if (listener.EventType != eventType)
continue;
// If the listener is pending removal, and is waiting until the next Framework Update, don't invoke listener.
if (listener.Removed)
continue;
// Match on string.empty for listeners that want events for all addons.
if (!string.IsNullOrWhiteSpace(listener.AddonName) && !args.IsAddon(listener.AddonName))
continue;

View file

@ -26,6 +26,11 @@ internal class AddonLifecycleEventListener
/// </summary>
public string AddonName { get; init; }
/// <summary>
/// Gets or sets a value indicating whether this event has been unregistered.
/// </summary>
public bool Removed { get; set; }
/// <summary>
/// Gets the event type this listener is looking for.
/// </summary>

View file

@ -90,7 +90,7 @@ public sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
private readonly DalamudConfiguration configuration;
private bool shownBacking = true;
private SeString? textBacking = null;
private SeString? textBacking;
/// <summary>
/// Initializes a new instance of the <see cref="DtrBarEntry"/> class.
@ -153,18 +153,18 @@ public sealed unsafe class DtrBarEntry : IDisposable, IDtrBarEntry
/// <summary>
/// Gets a value indicating whether this entry should be removed.
/// </summary>
internal bool ShouldBeRemoved { get; private set; } = false;
internal bool ShouldBeRemoved { get; private set; }
/// <summary>
/// Gets or sets a value indicating whether this entry is dirty.
/// </summary>
internal bool Dirty { get; set; } = false;
internal bool Dirty { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this entry has just been added.
/// </summary>
internal bool Added { get; set; } = false;
internal bool Added { get; set; }
/// <inheritdoc/>
public bool TriggerClickAction()
{