Starting background task upon IDE load
Answered
Could someone please point me to a documentation where I can learn how to run a background task as soon as the IDE with my plugin installed loads?
My use case is this: I would like to start watching for external changes to all project files (for example from another editor or an external compile task) as soon as the project loads.
I am starting the watcher via
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() { ... });
but can't find what extension point would be best to trigger this code from so it starts automatically upon IDE initialisation.
Please sign in to leave a comment.
So far I have solved my problem by extending ApplicationLoadListener with
public class MyPlugin implements ApplicationLoadListener {
@Override
public void beforeApplicationLoaded(@NotNull Application application, @NotNull String configPath) {
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect();
connection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {
public void projectOpened(@NotNull Project project) {
System.out.println(project.getName() + " opened, its url is " + project.getPresentableUrl());
// TODO: start files watcher in a thread using ApplicationManager.executeOnPooledThread
}
public void projectClosed(@NotNull Project project) {
System.out.println("Project closed. Boy bye.");
// TODO: cleanup
}
});
}
}
Would this be the recommended way in my use case?
Instead of registering the ApplicationLoadListener that programmatically registers ProjectManagerListeners, try to register later one directly: