Skip to content

Commit

Permalink
feat: add ModuleLoaded event to ModuleManager
Browse files Browse the repository at this point in the history
fix: set ModuleDisabled to null when disposing ModuleManager
  • Loading branch information
Flyga-M committed Apr 12, 2024
1 parent 665a210 commit 6b3a4ce
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Blish HUD/GameServices/Modules/ModuleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class ModuleManager : IDisposable {
public event EventHandler<EventArgs> ModuleEnabled;
public event EventHandler<EventArgs> ModuleDisabled;

public event EventHandler<EventArgs> ModuleLoaded;

public void OnModuleLoaded(object _, EventArgs e) {
this.ModuleLoaded?.Invoke(this, e);
}

private Assembly _moduleAssembly;

private bool _forceAllowDependency = false;
Expand Down Expand Up @@ -84,6 +90,8 @@ public bool TryEnable() {
_dirtyNamespaces.Add(this.Manifest.Namespace);
}

this.ModuleInstance.ModuleLoaded += OnModuleLoaded;

this.Enabled = true;

try {
Expand Down Expand Up @@ -113,6 +121,10 @@ public void Disable() {

this.Enabled = false;

if (this.ModuleInstance != null) {
this.ModuleInstance.ModuleLoaded -= OnModuleLoaded;
}

try {
this.ModuleInstance?.Dispose();
} catch (Exception ex) {
Expand Down Expand Up @@ -246,7 +258,9 @@ public void Dispose() {
GameService.Module.UnregisterModule(this);

this.ModuleEnabled = null;
this.ModuleEnabled = null;
this.ModuleDisabled = null;

this.ModuleLoaded = null;

_moduleAssembly = null;

Expand Down

0 comments on commit 6b3a4ce

Please sign in to comment.