Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module SettingsView.Unload() not called when switching between Module Settings tab and other tabs of the blish settings window #956

Open
Taschenbuch opened this issue Apr 10, 2024 · 0 comments

Comments

@Taschenbuch
Copy link
Contributor

Taschenbuch commented Apr 10, 2024

occurs in Blish 1.1.1

observed behavior

View.Unload() method is never called on the custom settings view created by overriding Module.GetSettingsView() when switching between the Module Settings tab and other tabs of the blish settings window. As a consequence when in View.Build() an event is subscribed to, it cannot be unsubscribed in View.Unload(). This leads to an additional event subscription each time the module settings tab is selected.

Example:

Module class

public override IView GetSettingsView()
{
    return new ModuleSettingsView(_service);
}

ModuleSettingsView class

public class ModuleSettingsView : View
{
    public ModuleSettingsView(Service service)
    {
        _service = service;
    }

    protected override async void Build(Container buildPanel) // called each time the module settings tab is opened
    {
        _service.MyEvent += OnMyEvent;
    }

    protected override void Unload() // never called
    {
        _service.MyEvent -= OnMyEvent;
    }
}

expected behavior

View.Unload() is called when

  • the module settings tab is left by switching to another tab of blish settings window
  • the blish settings window is closed
  • "Disable Module" is clicked

workaround until fixed

Module class

private ModuleSettingsView _moduleSettingsView;

public override IView GetSettingsView()
{
    _moduleSettingsView ??= new ModuleSettingsView(_service); 
    return _moduleSettingsView;
}

ModuleSettingsView class

public class ModuleSettingsView : View
{
    public ModuleSettingsView(Service service)
    {
        _service = service;
    }

    protected override async void Build(Container buildPanel) // called each time the module settings tab is opened
    {
        _service.MyEvent -= OnMyEvent;
        _service.MyEvent += OnMyEvent;
    }
}

relevant discord discussion:

https://discord.com/channels/531175899588984842/599270434642460753/1227691731231838360

Tharylia added a commit to Tharylia/Blish-HUD that referenced this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant