Search in sources :

Example 1 with FlutterApp

use of io.flutter.run.daemon.FlutterApp 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)

Example 2 with FlutterApp

use of io.flutter.run.daemon.FlutterApp in project flutter-intellij by flutter.

the class ObservatoryActionGroup method addInspector.

private void addInspector(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
    final ContentManager contentManager = toolWindow.getContentManager();
    final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
    final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), null, this);
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
        existingDevices.add(otherApp.device());
    }
    final JPanel tabContainer = new JPanel(new BorderLayout());
    final Content content = contentManager.getFactory().createContent(null, app.device().getUniqueName(existingDevices), false);
    tabContainer.add(runnerTabs.getComponent(), BorderLayout.CENTER);
    content.setComponent(tabContainer);
    content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
    content.setIcon(FlutterIcons.Phone);
    contentManager.addContent(content);
    final PerAppState state = getOrCreateStateForApp(app);
    assert (state.content == null);
    state.content = content;
    final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, runnerTabs);
    toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());
    // If the inspector is available (non-profile mode), then show it.
    if (inspectorService != null) {
        addInspectorPanel("Widgets", runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true);
        addInspectorPanel("Render Tree", runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false);
    } else {
        toolbarGroup.add(new OverflowAction(this, app));
        final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("InspectorToolbar", toolbarGroup, true);
        final JComponent toolbarComponent = toolbar.getComponent();
        toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
        tabContainer.add(toolbarComponent, BorderLayout.NORTH);
        // Add a message about the inspector not being available in profile mode.
        final JBLabel label = new JBLabel("Widget info not available in profile mode", SwingConstants.CENTER);
        label.setForeground(UIUtil.getLabelDisabledForeground());
        tabContainer.add(label, BorderLayout.CENTER);
    }
    final boolean isVertical = !toolWindow.getAnchor().isHorizontal();
    if (isVertical) {
        final JPanel dashboardsPanel = new JPanel(new BorderLayout());
        tabContainer.add(dashboardsPanel, BorderLayout.SOUTH);
        if (FlutterSettings.getInstance().isShowHeapDisplay()) {
            dashboardsPanel.add(FPSDisplay.createJPanelView(runnerTabs, app), BorderLayout.NORTH);
            dashboardsPanel.add(HeapDisplay.createJPanelView(runnerTabs, app), BorderLayout.SOUTH);
        }
    }
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) ContentManager(com.intellij.ui.content.ContentManager) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) FlutterDevice(io.flutter.run.daemon.FlutterDevice) JBRunnerTabs(com.intellij.execution.ui.layout.impl.JBRunnerTabs) JBLabel(com.intellij.ui.components.JBLabel) Content(com.intellij.ui.content.Content)

Example 3 with FlutterApp

use of io.flutter.run.daemon.FlutterApp in project flutter-intellij by flutter.

the class SdkRunConfig method getState.

@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final SdkFields launchFields = fields.copy();
    try {
        launchFields.checkRunnable(env.getProject());
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final MainFile mainFile = MainFile.verify(launchFields.getFilePath(), env.getProject()).get();
    final Project project = env.getProject();
    final RunMode mode = RunMode.fromEnv(env);
    final Module module = ModuleUtil.findModuleForFile(mainFile.getFile(), env.getProject());
    final LaunchState.Callback callback = (device) -> {
        if (device == null)
            return null;
        final GeneralCommandLine command = fields.createFlutterSdkRunCommand(project, device, mode);
        final FlutterApp app = FlutterApp.start(env, project, module, mode, device, command, StringUtil.capitalize(mode.mode()) + "App", "StopApp");
        // Stop the app if the Flutter SDK changes.
        final FlutterSdkManager.Listener sdkListener = new FlutterSdkManager.Listener() {

            @Override
            public void flutterSdkRemoved() {
                app.shutdownAsync();
            }
        };
        FlutterSdkManager.getInstance(project).addListener(sdkListener);
        Disposer.register(project, () -> FlutterSdkManager.getInstance(project).removeListener(sdkListener));
        return app;
    };
    final LaunchState launcher = new LaunchState(env, mainFile.getAppDir(), mainFile.getFile(), this, callback);
    // Set up additional console filters.
    final TextConsoleBuilder builder = launcher.getConsoleBuilder();
    builder.addFilter(new DartConsoleFilter(env.getProject(), mainFile.getFile()));
    if (module != null) {
        builder.addFilter(new FlutterConsoleFilter(module));
    }
    return launcher;
}
Also used : XmlSerializer(com.intellij.util.xmlb.XmlSerializer) RunConfigurationWithSuppressedDefaultRunAction(com.intellij.execution.runners.RunConfigurationWithSuppressedDefaultRunAction) ExecutionException(com.intellij.execution.ExecutionException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) InvalidDataException(com.intellij.openapi.util.InvalidDataException) com.intellij.execution.configurations(com.intellij.execution.configurations) UndoRefactoringElementAdapter(com.intellij.refactoring.listeners.UndoRefactoringElementAdapter) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ModuleUtil(com.intellij.openapi.module.ModuleUtil) DartConsoleFilter(com.jetbrains.lang.dart.ide.runner.DartConsoleFilter) Disposer(com.intellij.openapi.util.Disposer) PsiElement(com.intellij.psi.PsiElement) SkipDefaultValuesSerializationFilters(com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) SettingsEditor(com.intellij.openapi.options.SettingsEditor) FlutterApp(io.flutter.run.daemon.FlutterApp) FlutterSdkManager(io.flutter.sdk.FlutterSdkManager) RunMode(io.flutter.run.daemon.RunMode) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) Executor(com.intellij.execution.Executor) Nullable(org.jetbrains.annotations.Nullable) PsiDirectory(com.intellij.psi.PsiDirectory) PathUtil(com.intellij.util.PathUtil) WriteExternalException(com.intellij.openapi.util.WriteExternalException) FlutterConsoleFilter(io.flutter.console.FlutterConsoleFilter) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) Element(org.jdom.Element) FlutterApp(io.flutter.run.daemon.FlutterApp) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) FlutterConsoleFilter(io.flutter.console.FlutterConsoleFilter) DartConsoleFilter(com.jetbrains.lang.dart.ide.runner.DartConsoleFilter) Project(com.intellij.openapi.project.Project) TextConsoleBuilder(com.intellij.execution.filters.TextConsoleBuilder) FlutterSdkManager(io.flutter.sdk.FlutterSdkManager) RunMode(io.flutter.run.daemon.RunMode) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with FlutterApp

use of io.flutter.run.daemon.FlutterApp in project flutter-intellij by flutter.

the class StackLayout method createJPanelView.

public static JPanel createJPanelView(Disposable parentDisposable, FlutterApp app) {
    final JPanel panel = new JPanel(new StackLayout());
    panel.setDoubleBuffered(true);
    panel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    panel.setPreferredSize(new Dimension(100, HeapDisplay.PANEL_HEIGHT));
    assert app.getPerfService() != null;
    final FlutterFramesMonitor flutterFramesMonitor = app.getPerfService().getFlutterFramesMonitor();
    final FPSPanel fpsPanel = new FPSPanel(flutterFramesMonitor);
    final JPanel labelsPanel = new JPanel();
    labelsPanel.setOpaque(false);
    labelsPanel.setLayout(new BoxLayout(labelsPanel, BoxLayout.X_AXIS));
    panel.add(fpsPanel);
    panel.add(labelsPanel);
    final JBLabel fpsLabel = new JBLabel();
    fpsLabel.setAlignmentY(Component.TOP_ALIGNMENT);
    fpsLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    fpsLabel.setForeground(UIUtil.getLabelDisabledForeground());
    fpsLabel.setOpaque(false);
    fpsLabel.setBorder(JBUI.Borders.empty(4));
    final JBLabel elapsedLabel = new JBLabel("", SwingConstants.RIGHT);
    elapsedLabel.setAlignmentY(Component.TOP_ALIGNMENT);
    elapsedLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    elapsedLabel.setForeground(UIUtil.getLabelDisabledForeground());
    elapsedLabel.setOpaque(false);
    elapsedLabel.setBorder(JBUI.Borders.empty(4));
    labelsPanel.add(fpsLabel);
    labelsPanel.add(Box.createHorizontalGlue());
    labelsPanel.add(elapsedLabel);
    final FlutterFramesMonitor.Listener listener = event -> {
        fpsPanel.update();
        final int ms = Math.round(event.elapsedMicros / 1000.0f);
        elapsedLabel.setText(ms + "ms");
        SwingUtilities.invokeLater(elapsedLabel::repaint);
        fpsLabel.setText(df.format(flutterFramesMonitor.getFPS()) + " FPS");
        SwingUtilities.invokeLater(fpsLabel::repaint);
    };
    flutterFramesMonitor.addListener(listener);
    Disposer.register(parentDisposable, () -> flutterFramesMonitor.removeListener(listener));
    return panel;
}
Also used : CustomComponentAction(com.intellij.openapi.actionSystem.ex.CustomComponentAction) UIUtil(com.intellij.util.ui.UIUtil) java.util(java.util) DecimalFormat(java.text.DecimalFormat) Presentation(com.intellij.openapi.actionSystem.Presentation) AnAction(com.intellij.openapi.actionSystem.AnAction) JBLabel(com.intellij.ui.components.JBLabel) Disposable(com.intellij.openapi.Disposable) Path2D(java.awt.geom.Path2D) java.awt(java.awt) SideBorder(com.intellij.ui.SideBorder) List(java.util.List) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) JBUI(com.intellij.util.ui.JBUI) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Disposer(com.intellij.openapi.util.Disposer) FlutterFramesMonitor(io.flutter.perf.FlutterFramesMonitor) NotNull(org.jetbrains.annotations.NotNull) FlutterApp(io.flutter.run.daemon.FlutterApp) javax.swing(javax.swing) JBLabel(com.intellij.ui.components.JBLabel) FlutterFramesMonitor(io.flutter.perf.FlutterFramesMonitor)

Example 5 with FlutterApp

use of io.flutter.run.daemon.FlutterApp in project flutter-intellij by flutter.

the class FlutterReloadManager method handleSaveAllNotification.

private void handleSaveAllNotification(@Nullable Editor editor) {
    if (!mySettings.isReloadOnSave() || editor == null) {
        return;
    }
    if (handlingSave.get()) {
        return;
    }
    final AnAction reloadAction = ProjectActions.getAction(myProject, ReloadFlutterApp.ID);
    final FlutterApp app = getApp(reloadAction);
    if (app == null) {
        return;
    }
    if (!app.isStarted() || app.isReloading()) {
        return;
    }
    if (!(editor instanceof EditorEx)) {
        return;
    }
    final EditorEx editorEx = (EditorEx) editor;
    final VirtualFile file = editorEx.getVirtualFile();
    // Add an arbitrary 125ms delay to allow analysis to catch up. This delay gives the analysis server a
    // small pause to return error results in the (relatively infrequent) case where the user makes a bad
    // edit and immediately hits save.
    final int reloadDelayMs = 125;
    handlingSave.set(true);
    JobScheduler.getScheduler().schedule(() -> {
        if (hasErrors(app.getProject(), app.getModule(), editor.getDocument())) {
            handlingSave.set(false);
            showAnalysisNotification("Reload not performed", "Analysis issues found", true);
        } else {
            final Notification notification = showRunNotification(app, null, "Reloading…", false);
            app.performHotReload(supportsPauseAfterReload()).thenAccept(result -> {
                notification.expire();
                if (!result.ok()) {
                    showRunNotification(app, "Hot Reload Error", result.getMessage(), true);
                } else if (result.isRestartRecommended()) {
                    showRunNotification(app, "Reloading…", RESTART_SUGGESTED_TEXT, false);
                }
            }).whenComplete((aVoid, throwable) -> handlingSave.set(false));
        }
    }, reloadDelayMs, TimeUnit.MILLISECONDS);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) PsiErrorElement(com.intellij.psi.PsiErrorElement) HyperlinkEvent(javax.swing.event.HyperlinkEvent) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnalysisErrorSeverity(org.dartlang.analysis.server.protocol.AnalysisErrorSeverity) Document(com.intellij.openapi.editor.Document) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) DartProblemsView(com.jetbrains.lang.dart.ide.errorTreeView.DartProblemsView) Map(java.util.Map) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) ProjectActions(io.flutter.actions.ProjectActions) Method(java.lang.reflect.Method) HintUtil(com.intellij.codeInsight.hint.HintUtil) ReflectionUtil(com.intellij.util.ReflectionUtil) DartServerData(com.jetbrains.lang.dart.analyzer.DartServerData) FlutterIcons(icons.FlutterIcons) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) Collectors(java.util.stream.Collectors) NotificationListener(com.intellij.notification.NotificationListener) NotificationType(com.intellij.notification.NotificationType) InvocationTargetException(java.lang.reflect.InvocationTargetException) Notification(com.intellij.notification.Notification) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ServiceManager(com.intellij.openapi.components.ServiceManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) FlutterAppAction(io.flutter.actions.FlutterAppAction) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) LightweightHint(com.intellij.ui.LightweightHint) DataContext(com.intellij.openapi.actionSystem.DataContext) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Computable(com.intellij.openapi.util.Computable) HashMap(java.util.HashMap) SearchScope(com.intellij.psi.search.SearchScope) ReloadFlutterApp(io.flutter.actions.ReloadFlutterApp) AtomicReference(java.util.concurrent.atomic.AtomicReference) FlutterSettings(io.flutter.settings.FlutterSettings) AnActionListener(com.intellij.openapi.actionSystem.ex.AnActionListener) NotificationGroup(com.intellij.notification.NotificationGroup) ActionManagerEx(com.intellij.openapi.actionSystem.ex.ActionManagerEx) ToolWindowId(com.intellij.openapi.wm.ToolWindowId) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) FlutterDevice(io.flutter.run.daemon.FlutterDevice) PubRoot(io.flutter.pub.PubRoot) JobScheduler(com.intellij.concurrency.JobScheduler) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) FlutterApp(io.flutter.run.daemon.FlutterApp) ProjectAndLibrariesScope(com.intellij.psi.search.ProjectAndLibrariesScope) RunMode(io.flutter.run.daemon.RunMode) PubRoots(io.flutter.pub.PubRoots) DartAnalysisServerService(com.jetbrains.lang.dart.analyzer.DartAnalysisServerService) DeviceService(io.flutter.run.daemon.DeviceService) AnAction(com.intellij.openapi.actionSystem.AnAction) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) Editor(com.intellij.openapi.editor.Editor) SystemInfo(com.intellij.openapi.util.SystemInfo) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) DartPluginCapabilities(com.jetbrains.lang.dart.DartPluginCapabilities) HintManagerImpl(com.intellij.codeInsight.hint.HintManagerImpl) VfsUtil(com.intellij.openapi.vfs.VfsUtil) HintManager(com.intellij.codeInsight.hint.HintManager) SaveAllAction(com.intellij.ide.actions.SaveAllAction) javax.swing(javax.swing) ReloadFlutterApp(io.flutter.actions.ReloadFlutterApp) FlutterApp(io.flutter.run.daemon.FlutterApp) EditorEx(com.intellij.openapi.editor.ex.EditorEx) AnAction(com.intellij.openapi.actionSystem.AnAction) LightweightHint(com.intellij.ui.LightweightHint) Notification(com.intellij.notification.Notification)

Aggregations

FlutterApp (io.flutter.run.daemon.FlutterApp)4 AnAction (com.intellij.openapi.actionSystem.AnAction)2 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 Module (com.intellij.openapi.module.Module)2 Project (com.intellij.openapi.project.Project)2 Disposer (com.intellij.openapi.util.Disposer)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 ToolWindowManager (com.intellij.openapi.wm.ToolWindowManager)2 PsiFile (com.intellij.psi.PsiFile)2 JBLabel (com.intellij.ui.components.JBLabel)2 ContentManager (com.intellij.ui.content.ContentManager)2 NotNull (org.jetbrains.annotations.NotNull)2 HintManager (com.intellij.codeInsight.hint.HintManager)1 HintManagerImpl (com.intellij.codeInsight.hint.HintManagerImpl)1 HintUtil (com.intellij.codeInsight.hint.HintUtil)1 JobScheduler (com.intellij.concurrency.JobScheduler)1 ExecutionException (com.intellij.execution.ExecutionException)1 Executor (com.intellij.execution.Executor)1 com.intellij.execution.configurations (com.intellij.execution.configurations)1 TextConsoleBuilder (com.intellij.execution.filters.TextConsoleBuilder)1