Method to disable plugin when requirements aren't met
Answered
I have a plugin that only makes sense when working within a specific architecture at my company. If you're working in a different system, it is misleading and annoying.
Is there a way on startup, once I've detected that we're not within the architecture, to shutdown the plugin for that project?
Please sign in to leave a comment.
I'd suggest declaring an application service which will do such check and contain information that conditions are met - and then provide it for the other parts of your plugin.
You may also try to register ProjectManagerListener or ApplicationLoadListener to do such checks
There is a PluginManagerCore.disablePlugin(String id) method available but it may require a restart of the IDE.
Would I then need to call out to the application service in all the inspections, toolboxes etc, to see if it's disabled for that project and end the operations if it is?
If the condition check result will be performed once and cached, that'd be not a problem.
I assume that such conditions may be fulfilled in the next IDE run or when another project will be opened, right?
Yes, it's possible that across the projects opened, some will fulfil the conditions and some won't. Great, I'll implement like that then, thanks.
So if conditions are project dependent, use projectService instead of applicationService.
I currently have a project component, as per
Should I migrate this to a project service?
Plugin components are deprecated now - check our docs about Plugin Components. The proper way of the implementation is linked in my first answer.
Cool, I'll do that, thanks.