mastodon-sc / mastodon

Mastodon – a large-scale tracking and track-editing framework for large, multi-view images.
BSD 2-Clause "Simplified" License
66 stars 20 forks source link

Notify MastodonPlugins about a Mastodon project being closed #237

Closed maarzt closed 1 year ago

maarzt commented 1 year ago

Problem

Currently there is no way for a MastodonPlugin to get notified when the Mastodon project is closed. This means it cannot free resources, that are associated with the Mastodon project or do other operations like storing settings etc. that would usually be done when closing a project.

This is a problem for the Lineage Registration plugin in mastodon-tomancak. The plugin keeps a list of opened Mastodon projects. But a Mastodon project is never removed from that list because the plugin simply doesn't know if a project gets closed or not.

Potential Solution (deprecated)

The MastodonPlugin interface has a method that is called whenever a new Mastodon project is opened:

https://github.com/mastodon-sc/mastodon/blob/a965612e7890ec624232fc69c7431badd65c18d3/src/main/java/org/mastodon/app/plugin/MastodonPlugin.java#L51

We could add a similar method:

void closingAppPluginModel( final M pluginAppModel )`

that is called whenever the Mastodon project is closed.

Preferred Solution

Add closingListerners to the AppModel. A plugin can listen to the AppModel and would be notified when the AppModel is closed.

tinevez commented 1 year ago

I would like to make the AppModel final in an instance, to diminish the amount of logic dealing with mutable AppModel field. Maybe we could add a listener system instead? Inside the AppModel?

maarzt commented 1 year ago

This issue was closed in #245