Dynamic plugin using ProjectManagerListener

Answered

My plugin is using ProjectManagerListener and it works correctly when the IDE starts but it's not called when the plugin is installed while the IDE is active. I'm not seeing anything about this listener not being suitable for dynamic plugins in the documentation. What is the correct way to trigger ProjectManagerListener.projectOpened when a plugin is installed without an IDE restart?

5 comments
Comment actions Permalink

And you do actually open a project after installation of your plugin?

If yes, please clarify:
1) IDE version
2) how do you register your listener? via plugin plugin.xml?

 

 

 

 

 

 

 

 

0
Comment actions Permalink

That's what I'm saying, the project was opened before installing the plugin. If I close the project and open it again it works fine. I'd like to know how to trigger the listener if someone installs the plugin after the project has been opened. Is there another listener I should use to manually trigger my project opened logic?

I'm using IntelliJ 2022.1.2 with the following plugin.xml:

<applicationListeners>
<listener class="com.example.demo.PluginProjectListener" topic="com.intellij.openapi.project.ProjectManagerListener"/>
</applicationListeners>
0
Comment actions Permalink

AFAIU this is expected behavior. The currently opened project is not "opened explicitly" upon installation of a new plugin. AFAIU this should work instead https://plugins.jetbrains.com/docs/intellij/plugin-components.html#project-open

0
Comment actions Permalink

Thanks for the response. I guessed that was expected behavior.

Apologies if I'm being dense, but what then is the recommended way to get the opened project for dynamic plugins? The link you provided says "Plugins using Components do not support dynamic loading". So shouldn't I avoid that functionality if I want my plugin to support dynamic loading?

0
Comment actions Permalink

Sorry I wasn't clear. I recommended switching to StartupActivity EP mentioned in the linked paragraph.

0

Please sign in to leave a comment.