Can a plugin tell if another one is present?

I'm tinkering with a plugin that periodically sends information to the printer's LCD display. I'd like to be able to tell if another plugin (DisplayLayerProgress) is also installed, because I could have my plugin do something extra with information which I can get from event payloads.

Is there a way to determine at (or shortly after) startup if a particular plugin is present or not, so I can set up my data structures appropriately? Some test I can use in on_startup() or, better, on_after_startup()?

I don't see anything in the REST API for this.

This appears to be part of the core system.

The PluginManager is the central component for finding, loading and accessing plugins provided to the system.

It is able to discover plugins both through possible file system locations as well as customizable entry points.

Specifically get_plugin appears to be available.

1 Like

That looks promising - I'll try it out later in the week. Thanks!

This is the code you are looking for:

		if "DisplayLayerProgress" in self._plugin_manager.plugins:
			plugin = self._plugin_manager.plugins["DisplayLayerProgress"]
			if plugin != None and plugin.enabled == True:
				self._displayLayerProgressPluginImplementation = plugin.implementation
			else:
				self._displayLayerProgressPluginImplementationState = "disabled"
		else:
			self._displayLayerProgressPluginImplementationState = "missing"

See https://github.com/OllisGit/OctoPrint-PrintJobHistory for an implementation with a popup dialog for the user (last screenshot)

2 Likes

That will do nicely - thank you!