Search in sources :

Example 1 with FlutterDevice

use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.

the class LaunchCommandsTest method producesCorrectCommandLineInReleaseMode.

@Test
public void producesCorrectCommandLineInReleaseMode() throws ExecutionException {
    final BazelFields fields = setupBazelFields("bazel_target", null, null, true);
    final FlutterDevice device = FlutterDevice.getTester();
    GeneralCommandLine launchCommand = fields.getLaunchCommand(projectFixture.getProject(), device, RunMode.RUN);
    final List<String> expectedCommandLine = new ArrayList<>();
    expectedCommandLine.add(platformize("/workspace/scripts/flutter-run.sh"));
    expectedCommandLine.add("--release");
    expectedCommandLine.add("--machine");
    expectedCommandLine.add("-d");
    expectedCommandLine.add("flutter-tester");
    expectedCommandLine.add("--devtools-server-address=http://http://localhost:1234");
    expectedCommandLine.add("bazel_target");
    assertThat(launchCommand.getCommandLineString(), equalTo(String.join(" ", expectedCommandLine)));
    // When release mode is enabled, using different RunModes has no effect.
    launchCommand = fields.getLaunchCommand(projectFixture.getProject(), device, RunMode.DEBUG);
    assertThat(launchCommand.getCommandLineString(), equalTo(String.join(" ", expectedCommandLine)));
    launchCommand = fields.getLaunchCommand(projectFixture.getProject(), device, RunMode.PROFILE);
    assertThat(launchCommand.getCommandLineList(null), equalTo(expectedCommandLine));
}
Also used : FlutterDevice(io.flutter.run.FlutterDevice) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with FlutterDevice

use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.

the class PerfViewAppState method addPerformanceViewContent.

private void addPerformanceViewContent(FlutterApp app, ToolWindow toolWindow) {
    final ContentManager contentManager = toolWindow.getContentManager();
    final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
    final FlutterDevice device = app.device();
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
        existingDevices.add(otherApp.device());
    }
    final String tabName = device.getUniqueName(existingDevices);
    // mainContentPanel contains the toolbar, perfViewsPanel, and the footer
    final JPanel mainContentPanel = new JPanel(new BorderLayout());
    final Content content = contentManager.getFactory().createContent(null, tabName, false);
    content.setComponent(mainContentPanel);
    content.putUserData(ToolWindow.SHOW_CONTENT_ICON, Boolean.TRUE);
    content.setIcon(FlutterIcons.Phone);
    contentManager.addContent(content);
    // perfViewsPanel contains the three performance views
    final JComponent perfViewsPanel = Box.createVerticalBox();
    perfViewsPanel.setBorder(JBUI.Borders.empty(0, 3));
    mainContentPanel.add(perfViewsPanel, BorderLayout.CENTER);
    if (emptyContent != null) {
        contentManager.removeContent(emptyContent, true);
        emptyContent = null;
    }
    toolWindow.setIcon(ExecutionUtil.getLiveIndicator(FlutterIcons.Flutter_13));
    final PerfViewAppState state = getOrCreateStateForApp(app);
    assert (state.content == null);
    state.content = content;
    final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, this);
    toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterPerfViewToolbar", toolbarGroup, true).getComponent());
    final ActionToolbar toolbar = ActionManager.getInstance().createActionToolbar("PerformanceToolbar", toolbarGroup, true);
    final JComponent toolbarComponent = toolbar.getComponent();
    toolbarComponent.setBorder(IdeBorderFactory.createBorder(SideBorder.BOTTOM));
    mainContentPanel.add(toolbarComponent, BorderLayout.NORTH);
    // devtools link and run mode footer
    final JPanel footer = new JPanel(new BorderLayout());
    footer.setBorder(new CompoundBorder(IdeBorderFactory.createBorder(SideBorder.TOP), JBUI.Borders.empty(5, 7)));
    final JLabel runModeLabel = new JBLabel("Run mode: " + app.getLaunchMode());
    if (app.getLaunchMode() == FlutterLaunchMode.DEBUG) {
        runModeLabel.setIcon(AllIcons.General.BalloonInformation);
        runModeLabel.setToolTipText("Note: debug mode frame rendering times are not indicative of release mode performance");
    }
    final LinkLabel<String> openDevtools = new LinkLabel<>("Open DevTools...", null);
    openDevtools.setListener((linkLabel, data) -> {
        AsyncUtils.whenCompleteUiThread(DevToolsService.getInstance(app.getProject()).getDevToolsInstance(), (instance, ex) -> {
            if (app.getProject().isDisposed()) {
                return;
            }
            if (ex != null) {
                LOG.error(ex);
                return;
            }
            BrowserLauncher.getInstance().browse((new DevToolsUrl(instance.host, instance.port, app.getConnector().getBrowserUrl(), null, false, null, null)).getUrlString(), null);
        });
    }, null);
    footer.add(runModeLabel, BorderLayout.WEST);
    footer.add(openDevtools, BorderLayout.EAST);
    mainContentPanel.add(footer, BorderLayout.SOUTH);
    final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
    final boolean isInProfileMode = app.getMode().isProfiling() || app.getLaunchMode().isProfiling();
    // If the inspector is available (non-release mode), then show it.
    if (debugConnectionAvailable) {
        state.disposable = Disposer.newDisposable();
        // Create the three FPS, memory, and widget recount areas.
        final PerfFPSPanel fpsPanel = new PerfFPSPanel(app, this);
        perfViewsPanel.add(fpsPanel);
        final PerfMemoryPanel memoryPanel = new PerfMemoryPanel(app, this);
        perfViewsPanel.add(memoryPanel);
        final PerfWidgetRebuildsPanel widgetRebuildsPanel = new PerfWidgetRebuildsPanel(app, this);
        perfViewsPanel.add(widgetRebuildsPanel);
        // If in profile mode, auto-open the performance tool window.
        if (isInProfileMode) {
            activateToolWindow();
        }
    } else {
        // Add a message about the inspector not being available in release mode.
        final JBLabel label = new JBLabel("Profiling is not available in release mode", SwingConstants.CENTER);
        label.setForeground(UIUtil.getLabelDisabledForeground());
        mainContentPanel.add(label, BorderLayout.CENTER);
    }
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) DevToolsUrl(io.flutter.devtools.DevToolsUrl) ContentManager(com.intellij.ui.content.ContentManager) ArrayList(java.util.ArrayList) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) ActionToolbar(com.intellij.openapi.actionSystem.ActionToolbar) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) FlutterDevice(io.flutter.run.FlutterDevice) JBLabel(com.intellij.ui.components.JBLabel) Content(com.intellij.ui.content.Content) LinkLabel(com.intellij.ui.components.labels.LinkLabel) CompoundBorder(javax.swing.border.CompoundBorder)

Example 3 with FlutterDevice

use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.

the class LabelInput method addBrowserInspectorViewContent.

private void addBrowserInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow, boolean isEmbedded, DevToolsInstance devToolsInstance) {
    assert (SwingUtilities.isEventDispatchThread());
    final ContentManager contentManager = toolWindow.getContentManager();
    final FlutterDevice device = app.device();
    final List<FlutterDevice> existingDevices = new ArrayList<>();
    for (FlutterApp otherApp : perAppViewState.keySet()) {
        existingDevices.add(otherApp.device());
    }
    final String tabName = device.getUniqueName(existingDevices);
    if (emptyContent != null) {
        contentManager.removeContent(emptyContent, true);
        emptyContent = null;
    }
    final String browserUrl = app.getConnector().getBrowserUrl();
    if (isEmbedded) {
        final String color = ColorUtil.toHex(UIUtil.getEditorPaneBackground());
        final DevToolsUrl devToolsUrl = new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", true, color, UIUtil.getFontSize(UIUtil.FontSize.NORMAL));
        // noinspection CodeBlock2Expr
        ApplicationManager.getApplication().invokeLater(() -> {
            embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.openPanel(contentManager, tabName, devToolsUrl, () -> {
                // If the embedded browser doesn't work, offer a link to open in the regular browser.
                final List<LabelInput> inputs = Arrays.asList(new LabelInput("The embedded browser failed to load."), openDevToolsLabel(app, inspectorService, toolWindow));
                presentClickableLabel(toolWindow, inputs);
            }));
        });
        if (!busSubscribed) {
            busConnection.subscribe(EditorColorsManager.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateColor(ColorUtil.toHex(UIUtil.getEditorPaneBackground()))));
            busConnection.subscribe(UISettingsListener.TOPIC, scheme -> embeddedBrowserOptional().ifPresent(embeddedBrowser -> embeddedBrowser.updateFontSize(UIUtil.getFontSize(UIUtil.FontSize.NORMAL))));
            busSubscribed = true;
        }
    } else {
        BrowserLauncher.getInstance().browse((new DevToolsUrl(devToolsInstance.host, devToolsInstance.port, browserUrl, "inspector", false, null, null).getUrlString()), null);
        presentLabel(toolWindow, "DevTools inspector has been opened in the browser.");
    }
}
Also used : Storage(com.intellij.openapi.components.Storage) UIUtil(com.intellij.util.ui.UIUtil) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) AllIcons(com.intellij.icons.AllIcons) Event(org.dartlang.vm.service.element.Event) PersistentStateComponent(com.intellij.openapi.components.PersistentStateComponent) FlutterInitializer(io.flutter.FlutterInitializer) TimeoutException(java.util.concurrent.TimeoutException) InspectorService(io.flutter.inspector.InspectorService) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) JBLabel(com.intellij.ui.components.JBLabel) SideBorder(com.intellij.ui.SideBorder) AsyncUtils(io.flutter.utils.AsyncUtils) JBUI(com.intellij.util.ui.JBUI) InspectorSourceLocation(io.flutter.inspector.InspectorSourceLocation) Disposer(com.intellij.openapi.util.Disposer) LinkLabel(com.intellij.ui.components.labels.LinkLabel) InspectorGroupManagerService(io.flutter.inspector.InspectorGroupManagerService) Logger(com.intellij.openapi.diagnostic.Logger) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) JxBrowserUtils(io.flutter.utils.JxBrowserUtils) ToolWindow(com.intellij.openapi.wm.ToolWindow) ColorUtil(com.intellij.ui.ColorUtil) UISettingsListener(com.intellij.ide.ui.UISettingsListener) NonInjectable(com.intellij.serviceContainer.NonInjectable) ActionCallback(com.intellij.openapi.util.ActionCallback) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) FlutterIcons(icons.FlutterIcons) Content(com.intellij.ui.content.Content) ServiceExtensions(io.flutter.vmService.ServiceExtensions) BrowserLauncher(com.intellij.ide.browsers.BrowserLauncher) FlutterBundle(io.flutter.FlutterBundle) Nullable(org.jetbrains.annotations.Nullable) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) XSourcePosition(com.intellij.xdebugger.XSourcePosition) ApplicationManager(com.intellij.openapi.application.ApplicationManager) ContentManager(com.intellij.ui.content.ContentManager) ExecutionUtil(com.intellij.execution.runners.ExecutionUtil) NotNull(org.jetbrains.annotations.NotNull) FlutterDevice(io.flutter.run.FlutterDevice) TabInfo(com.intellij.ui.tabs.TabInfo) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) ActiveRunnable(com.intellij.openapi.util.ActiveRunnable) java.util(java.util) LinkListener(com.intellij.ui.components.labels.LinkListener) CompletableFuture(java.util.concurrent.CompletableFuture) FlutterSettings(io.flutter.settings.FlutterSettings) MessageBusConnection(com.intellij.util.messages.MessageBusConnection) JBRunnerTabs(com.intellij.execution.ui.layout.impl.JBRunnerTabs) DevToolsUrl(io.flutter.devtools.DevToolsUrl) io.flutter.jxbrowser(io.flutter.jxbrowser) Project(com.intellij.openapi.project.Project) FlutterUtils(io.flutter.FlutterUtils) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) FlutterApp(io.flutter.run.daemon.FlutterApp) DiagnosticsNode(io.flutter.inspector.DiagnosticsNode) FlutterViewToolWindowManagerListener(io.flutter.toolwindow.FlutterViewToolWindowManagerListener) StringUtil(com.intellij.openapi.util.text.StringUtil) DevToolsService(io.flutter.run.daemon.DevToolsService) VmService(org.dartlang.vm.service.VmService) Disposable(com.intellij.openapi.Disposable) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) EventStream(io.flutter.utils.EventStream) IdeBorderFactory(com.intellij.ui.IdeBorderFactory) VisibleForTesting(com.google.common.annotations.VisibleForTesting) DevToolsInstance(io.flutter.run.daemon.DevToolsInstance) javax.swing(javax.swing) FlutterDevice(io.flutter.run.FlutterDevice) FlutterApp(io.flutter.run.daemon.FlutterApp) DevToolsUrl(io.flutter.devtools.DevToolsUrl) ContentManager(com.intellij.ui.content.ContentManager) List(java.util.List)

Example 4 with FlutterDevice

use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.

the class DeviceSelectorAction method updateActions.

private void updateActions(@NotNull Project project, Presentation presentation) {
    actions.clear();
    final DeviceService deviceService = DeviceService.getInstance(project);
    final FlutterDevice selectedDevice = deviceService.getSelectedDevice();
    final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();
    selectedDeviceAction = null;
    for (FlutterDevice device : devices) {
        final SelectDeviceAction deviceAction = new SelectDeviceAction(device, devices);
        actions.add(deviceAction);
        if (Objects.equals(device, selectedDevice)) {
            selectedDeviceAction = deviceAction;
            final Presentation template = deviceAction.getTemplatePresentation();
            presentation.setIcon(template.getIcon());
            // presentation.setText(deviceAction.presentationName());
            presentation.setEnabled(true);
        }
    }
    // Show the 'Open iOS Simulator' action.
    if (SystemInfo.isMac) {
        boolean simulatorOpen = false;
        for (AnAction action : actions) {
            if (action instanceof SelectDeviceAction) {
                final SelectDeviceAction deviceAction = (SelectDeviceAction) action;
                final FlutterDevice device = deviceAction.device;
                if (device.isIOS() && device.emulator()) {
                    simulatorOpen = true;
                }
            }
        }
        actions.add(new Separator());
        actions.add(new OpenSimulatorAction(!simulatorOpen));
    }
    // Add Open Android emulators actions.
    final List<OpenEmulatorAction> emulatorActions = OpenEmulatorAction.getEmulatorActions(project);
    if (!emulatorActions.isEmpty()) {
        actions.add(new Separator());
        actions.addAll(emulatorActions);
    }
    if (!FlutterModuleUtils.hasInternalDartSdkPath(project)) {
        actions.add(new Separator());
        actions.add(new RestartFlutterDaemonAction());
    }
    ActivityTracker.getInstance().inc();
}
Also used : FlutterDevice(io.flutter.run.FlutterDevice) DeviceService(io.flutter.run.daemon.DeviceService)

Example 5 with FlutterDevice

use of io.flutter.run.FlutterDevice in project flutter-intellij by flutter.

the class LaunchCommandsTest method producesCorrectCommandLineInRunMode.

@Test
public void producesCorrectCommandLineInRunMode() throws ExecutionException {
    final BazelFields fields = setupBazelFields();
    final FlutterDevice device = FlutterDevice.getTester();
    final GeneralCommandLine launchCommand = fields.getLaunchCommand(projectFixture.getProject(), device, RunMode.RUN);
    final List<String> expectedCommandLine = new ArrayList<>();
    expectedCommandLine.add(platformize("/workspace/scripts/flutter-run.sh"));
    expectedCommandLine.add("--machine");
    expectedCommandLine.add("-d");
    expectedCommandLine.add("flutter-tester");
    expectedCommandLine.add("--devtools-server-address=http://http://localhost:1234");
    expectedCommandLine.add("bazel_target");
    assertThat(launchCommand.getCommandLineList(null), equalTo(expectedCommandLine));
}
Also used : FlutterDevice(io.flutter.run.FlutterDevice) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

FlutterDevice (io.flutter.run.FlutterDevice)20 ArrayList (java.util.ArrayList)13 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)12 Test (org.junit.Test)12 SimpleToolWindowPanel (com.intellij.openapi.ui.SimpleToolWindowPanel)3 JBLabel (com.intellij.ui.components.JBLabel)3 Content (com.intellij.ui.content.Content)3 ContentManager (com.intellij.ui.content.ContentManager)3 FlutterApp (io.flutter.run.daemon.FlutterApp)3 JBRunnerTabs (com.intellij.execution.ui.layout.impl.JBRunnerTabs)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 LinkLabel (com.intellij.ui.components.labels.LinkLabel)2 DevToolsUrl (io.flutter.devtools.DevToolsUrl)2 NotNull (org.jetbrains.annotations.NotNull)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ExecutionException (com.intellij.execution.ExecutionException)1 ExecutionUtil (com.intellij.execution.runners.ExecutionUtil)1 AllIcons (com.intellij.icons.AllIcons)1 BrowserLauncher (com.intellij.ide.browsers.BrowserLauncher)1