mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-17 14:14:17 +01:00
Improve logic for Unregistering Listeners
This commit is contained in:
parent
e914f33990
commit
967c79fdd3
1 changed files with 28 additions and 32 deletions
|
|
@ -328,19 +328,15 @@ internal class AddonLifecyclePluginScoped : IDisposable, IServiceType, IAddonLif
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public void UnregisterListener(AddonEvent eventType, string addonName, IAddonLifecycle.AddonEventDelegate? handler = null)
|
public void UnregisterListener(AddonEvent eventType, string addonName, IAddonLifecycle.AddonEventDelegate? handler = null)
|
||||||
{
|
{
|
||||||
// This style is simpler to read imo. If the handler is null we want all entries,
|
this.eventListeners.RemoveAll(entry =>
|
||||||
// if they specified a handler then only the specific entries with that handler.
|
|
||||||
var targetListeners = this.eventListeners
|
|
||||||
.Where(entry => entry.EventType == eventType)
|
|
||||||
.Where(entry => entry.AddonName == addonName)
|
|
||||||
.Where(entry => handler is null || entry.FunctionDelegate == handler)
|
|
||||||
.ToArray(); // Make a copy so we don't mutate this list while removing entries.
|
|
||||||
|
|
||||||
foreach (var listener in targetListeners)
|
|
||||||
{
|
{
|
||||||
this.addonLifecycleService.UnregisterListener(listener);
|
if (entry.EventType != eventType) return false;
|
||||||
this.eventListeners.Remove(listener);
|
if (entry.AddonName != addonName) return false;
|
||||||
}
|
if (handler is not null && entry.FunctionDelegate != handler) return false;
|
||||||
|
|
||||||
|
this.addonLifecycleService.UnregisterListener(entry);
|
||||||
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue