Search in sources :

Example 1 with FlutterViewToolWindowManagerListener

use of io.flutter.toolwindow.FlutterViewToolWindowManagerListener in project flutter-intellij by flutter.

the class LabelInput method debugActiveHelper.

private void debugActiveHelper(FlutterApp app, @Nullable InspectorService inspectorService) {
    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 (toolWindow.isAvailable()) {
        updateToolWindowVisibility(toolWindow);
    } else {
        toolWindow.setAvailable(true, () -> {
            updateToolWindowVisibility(toolWindow);
        });
    }
    if (emptyContent != null) {
        final ContentManager contentManager = toolWindow.getContentManager();
        contentManager.removeContent(emptyContent, true);
        emptyContent = null;
    }
    toolWindow.setIcon(ExecutionUtil.getLiveIndicator(FlutterIcons.Flutter_13));
    if (FlutterSettings.getInstance().isEnableEmbeddedBrowsers()) {
        if (jxBrowserManager.getStatus().equals(JxBrowserStatus.INSTALLED)) {
            // Reset the URL since we may have an outdated one from a previous app run.
            embeddedBrowserOptional().ifPresent(EmbeddedBrowser::resetUrl);
        }
        if (toolWindow.isVisible()) {
            displayEmbeddedBrowser(app, inspectorService, toolWindow);
        } else {
            if (toolWindowListener == null) {
                toolWindowListener = new FlutterViewToolWindowManagerListener(myProject, toolWindow);
            }
            // If the window isn't visible yet, only executed embedded browser steps when it becomes visible.
            toolWindowListener.updateOnWindowFirstVisible(() -> {
                displayEmbeddedBrowser(app, inspectorService, toolWindow);
            });
        }
        return;
    }
    listenForRenderTreeActivations(toolWindow);
    addInspectorViewContent(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(() -> {
                if (inspectorService != null) {
                    Disposer.dispose(inspectorService);
                }
                if (toolWindow.isDisposed())
                    return;
                final ContentManager contentManager = toolWindow.getContentManager();
                onAppChanged(app);
                final PerAppState state = perAppViewState.remove(app);
                if (state != null) {
                    if (state.content != null) {
                        contentManager.removeContent(state.content, true);
                    }
                    state.dispose();
                }
                if (perAppViewState.isEmpty()) {
                    // No more applications are running.
                    updateForEmptyContent(toolWindow);
                }
            });
        }
    });
    onAppChanged(app);
    app.addStateListener(new FlutterApp.FlutterAppListener() {

        public void notifyAppRestarted() {
            // When we get a restart finished event, 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
            // to where they can 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 : FlutterApp(io.flutter.run.daemon.FlutterApp) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ContentManager(com.intellij.ui.content.ContentManager) FlutterViewToolWindowManagerListener(io.flutter.toolwindow.FlutterViewToolWindowManagerListener) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindow(com.intellij.openapi.wm.ToolWindow) Event(org.dartlang.vm.service.element.Event) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent)

Example 2 with FlutterViewToolWindowManagerListener

use of io.flutter.toolwindow.FlutterViewToolWindowManagerListener in project flutter-intellij by flutter.

the class LabelInput method setUpToolWindowListener.

@VisibleForTesting
protected void setUpToolWindowListener(FlutterApp app, InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded) {
    if (this.toolWindowListener == null) {
        this.toolWindowListener = new FlutterViewToolWindowManagerListener(myProject, toolWindow);
    }
    this.toolWindowListener.updateOnWindowOpen(() -> {
        devToolsInstallCount += 1;
        presentLabel(toolWindow, getInstallingDevtoolsLabel());
        openInspectorWithDevTools(app, inspectorService, toolWindow, isEmbedded, true);
    });
}
Also used : FlutterViewToolWindowManagerListener(io.flutter.toolwindow.FlutterViewToolWindowManagerListener) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

FlutterViewToolWindowManagerListener (io.flutter.toolwindow.FlutterViewToolWindowManagerListener)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 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