Search in sources :

Example 1 with VmServiceListenerAdapter

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;
            }
        }
    });
}
Also used : ToolWindow(com.intellij.openapi.wm.ToolWindow) FlutterApp(io.flutter.run.daemon.FlutterApp) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ContentManager(com.intellij.ui.content.ContentManager) Event(org.dartlang.vm.service.element.Event) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx)

Aggregations

ToolWindow (com.intellij.openapi.wm.ToolWindow)1 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)1 ToolWindowManagerEx (com.intellij.openapi.wm.ex.ToolWindowManagerEx)1 ContentManager (com.intellij.ui.content.ContentManager)1 ContentManagerEvent (com.intellij.ui.content.ContentManagerEvent)1 FlutterApp (io.flutter.run.daemon.FlutterApp)1 VmServiceListenerAdapter (io.flutter.utils.VmServiceListenerAdapter)1 Event (org.dartlang.vm.service.element.Event)1