void () { for (Project project : ProjectUtilCore.getOpenProjects()) { subscribeToolWindowTopic(project); } ourConnection = ApplicationManager.getApplication().getMessageBus().connect(); ourConnection.subscribe(ProjectManager.TOPIC, new ProjectManagerListener() { @Override public void projectOpened(@NotNull Project project) { subscribeToolWindowTopic(project); } @Override public void projectClosed(@NotNull Project project) { forEachToolWindow(project, tw -> { if (tw != null) TouchBarsManager.unregister(tw.getComponent()); }); } }); }