use of io.flutter.utils.VmServiceListenerAdapter in project flutter-intellij by flutter.
the class ObservatoryActionGroup method debugActiveHelper.
private void debugActiveHelper(@NotNull FlutterApp app, @Nullable InspectorService inspectorService) {
if (FlutterSettings.getInstance().isOpenInspectorOnAppLaunch()) {
autoActivateToolWindow();
}
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
if (!(toolWindowManager instanceof ToolWindowManagerEx)) {
return;
}
final ToolWindow toolWindow = toolWindowManager.getToolWindow(FlutterView.TOOL_WINDOW_ID);
if (toolWindow == null) {
return;
}
if (isDisplayingEmptyContent()) {
removeEmptyContent(toolWindow);
}
listenForRenderTreeActivations(toolWindow);
addInspector(app, inspectorService, toolWindow);
app.getVmService().addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void connectionOpened() {
onAppChanged(app);
}
@Override
public void received(String streamId, Event event) {
if (StringUtil.equals(streamId, VmService.EXTENSION_STREAM_ID)) {
if (StringUtil.equals("Flutter.Frame", event.getExtensionKind())) {
handleFlutterFrame(app);
}
}
}
@Override
public void connectionClosed() {
ApplicationManager.getApplication().invokeLater(() -> {
final ContentManager contentManager = toolWindow.getContentManager();
onAppChanged(app);
final PerAppState state = perAppViewState.remove(app);
if (state != null && state.content != null) {
contentManager.removeContent(state.content, true);
}
if (perAppViewState.isEmpty()) {
// No more applications are running.
displayEmptyContent(toolWindow);
}
});
}
});
onAppChanged(app);
app.addStateListener(new FlutterApp.FlutterAppListener() {
public void notifyAppRestarted() {
// When we get a restart finishes, queue up a notification to the flutter view
// actions. We don't notify right away because the new isolate can take a little
// while to start up. We wait until we get the first frame event, which is
// enough of an indication that the isolate and flutter framework are initialized
// enough to receive service calls (for example, calls to restore various framework
// debugging settings).
final PerAppState state = getStateForApp(app);
if (state != null) {
state.sendRestartNotificationOnNextFrame = true;
}
}
});
}
Aggregations