Skip to content

Commit

Permalink
fix: reregister Penumbra events on update
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-is-cute committed Mar 24, 2024
1 parent 916d490 commit a18a166
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions PenumbraIpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ internal class PenumbraIpc : IDisposable {

// events

/// <inheritdoc cref="Penumbra.Api.Ipc.Initialized" />
private EventSubscriber InitializedEvent { get; set; }

/// <inheritdoc cref="Penumbra.Api.Ipc.ModAdded" />
private EventSubscriber<string>? ModAddedEvent { get; set; }

Expand Down Expand Up @@ -91,15 +94,27 @@ internal PenumbraIpc(Plugin plugin) {
}

public void Dispose() {
this.UnregisterEvents();
}

private void ReregisterEvents() {
this.UnregisterEvents();
this.RegisterEvents();
}

private void UnregisterEvents() {
this.PreSettingsDrawEvent?.Dispose();
this.PreSettingsTabBarDrawEvent?.Dispose();
this.PostEnabledDrawEvent?.Dispose();
this.ModMovedEvent?.Dispose();
this.ModDeletedEvent?.Dispose();
this.ModAddedEvent?.Dispose();
this.InitializedEvent?.Dispose();
}

private void RegisterEvents() {
this.InitializedEvent = Penumbra.Api.Ipc.Initialized.Subscriber(this.Plugin.Interface, this.ReregisterEvents);

this.ModAddedEvent = Penumbra.Api.Ipc.ModAdded.Subscriber(this.Plugin.Interface, _ => {
Task.Run(async () => await this.Plugin.State.UpdatePackages());
});
Expand Down

0 comments on commit a18a166

Please sign in to comment.