Search in sources :

Example 11 with FlutterDevice

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

the class LabelInput method addInspectorViewContent.

private void addInspectorViewContent(FlutterApp app, @Nullable InspectorService inspectorService, ToolWindow toolWindow) {
    final ContentManager contentManager = toolWindow.getContentManager();
    final SimpleToolWindowPanel toolWindowPanel = new SimpleToolWindowPanel(true);
    // TODO: Don't switch to JBRunnerTabs(Project, Disposable) until 2020.1.
    final JBRunnerTabs runnerTabs = new JBRunnerTabs(myProject, ActionManager.getInstance(), IdeFocusManager.getInstance(myProject), this);
    runnerTabs.setSelectionChangeHandler(this::onTabSelectionChange);
    final JPanel tabContainer = new JPanel(new BorderLayout());
    final String tabName;
    final FlutterDevice device = app.device();
    if (device == null) {
        tabName = app.getProject().getName();
    } else {
        final List<FlutterDevice> existingDevices = new ArrayList<>();
        for (FlutterApp otherApp : perAppViewState.keySet()) {
            existingDevices.add(otherApp.device());
        }
        tabName = device.getUniqueName(existingDevices);
    }
    final Content content = contentManager.getFactory().createContent(null, tabName, 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);
    if (emptyContent != null) {
        contentManager.removeContent(emptyContent, true);
        emptyContent = null;
    }
    contentManager.setSelectedContent(content);
    final PerAppState state = getOrCreateStateForApp(app);
    assert (state.content == null);
    state.content = content;
    final DefaultActionGroup toolbarGroup = createToolbar(toolWindow, app, inspectorService);
    toolWindowPanel.setToolbar(ActionManager.getInstance().createActionToolbar("FlutterViewToolbar", toolbarGroup, true).getComponent());
    toolbarGroup.add(new OverflowAction(getOrCreateStateForApp(app), 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);
    final boolean debugConnectionAvailable = app.getLaunchMode().supportsDebugConnection();
    final boolean hasInspectorService = inspectorService != null;
    // If the inspector is available (non-release mode), then show it.
    if (debugConnectionAvailable) {
        if (hasInspectorService) {
            final boolean detailsSummaryViewSupported = inspectorService.isDetailsSummaryViewSupported();
            addInspectorPanel(WIDGET_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.widget, app, inspectorService, toolWindow, toolbarGroup, true, detailsSummaryViewSupported);
            addInspectorPanel(RENDER_TAB_LABEL, runnerTabs, state, InspectorService.FlutterTreeType.renderObject, app, inspectorService, toolWindow, toolbarGroup, false, false);
        } else {
            // If in profile mode, add disabled tabs for the inspector.
            addDisabledTab(WIDGET_TAB_LABEL, runnerTabs, toolbarGroup);
            addDisabledTab(RENDER_TAB_LABEL, runnerTabs, toolbarGroup);
        }
    } else {
        // Add a message about the inspector not being available in release mode.
        final JBLabel label = new JBLabel("Inspector not available in release mode", SwingConstants.CENTER);
        label.setForeground(UIUtil.getLabelDisabledForeground());
        tabContainer.add(label, BorderLayout.CENTER);
    }
}
Also used : FlutterApp(io.flutter.run.daemon.FlutterApp) ContentManager(com.intellij.ui.content.ContentManager) SimpleToolWindowPanel(com.intellij.openapi.ui.SimpleToolWindowPanel) FlutterDevice(io.flutter.run.FlutterDevice) JBRunnerTabs(com.intellij.execution.ui.layout.impl.JBRunnerTabs) JBLabel(com.intellij.ui.components.JBLabel) Content(com.intellij.ui.content.Content)

Example 12 with FlutterDevice

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

the class DeviceSelectorAction method update.

@Override
public void update(final AnActionEvent e) {
    // Suppress device actions in all but the toolbars.
    final String place = e.getPlace();
    if (!Objects.equals(place, ActionPlaces.NAVIGATION_BAR_TOOLBAR) && !Objects.equals(place, ActionPlaces.MAIN_TOOLBAR)) {
        e.getPresentation().setVisible(false);
        return;
    }
    // Only show device menu when the device daemon process is running.
    final Project project = e.getProject();
    if (!isSelectorVisible(project)) {
        e.getPresentation().setVisible(false);
        return;
    }
    super.update(e);
    final Presentation presentation = e.getPresentation();
    if (!knownProjects.contains(project)) {
        knownProjects.add(project);
        final Application application = ApplicationManager.getApplication();
        application.getMessageBus().connect().subscribe(ProjectManager.TOPIC, new ProjectManagerListener() {

            @Override
            public void projectClosed(@NotNull Project closedProject) {
                knownProjects.remove(closedProject);
            }
        });
        deviceListener = () -> queueUpdate(project, e.getPresentation());
        DeviceService.getInstance(project).addListener(deviceListener);
        // Listen for android device changes, and rebuild the menu if necessary.
        emulatorListener = () -> queueUpdate(project, e.getPresentation());
        AndroidEmulatorManager.getInstance(project).addListener(emulatorListener);
        ProjectManager.getInstance().addProjectManagerListener(project, new ProjectManagerListener() {

            public void projectClosing(@NotNull Project project) {
                DeviceService.getInstance(project).removeListener(deviceListener);
                AndroidEmulatorManager.getInstance(project).removeListener(emulatorListener);
            }
        });
        update(project, presentation);
    }
    final DeviceService deviceService = DeviceService.getInstance(project);
    final FlutterDevice selectedDevice = deviceService.getSelectedDevice();
    final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();
    if (devices.isEmpty()) {
        final boolean isLoading = deviceService.getStatus() == DeviceService.State.LOADING;
        if (isLoading) {
            presentation.setText(FlutterBundle.message("devicelist.loading"));
        } else {
            presentation.setText("<no devices>");
        }
    } else if (selectedDevice == null) {
        presentation.setText("<no device selected>");
    } else if (selectedDeviceAction != null) {
        final Presentation template = selectedDeviceAction.getTemplatePresentation();
        presentation.setIcon(template.getIcon());
        presentation.setText(selectedDevice.presentationName());
        presentation.setEnabled(true);
    }
}
Also used : Project(com.intellij.openapi.project.Project) ProjectManagerListener(com.intellij.openapi.project.ProjectManagerListener) FlutterDevice(io.flutter.run.FlutterDevice) DeviceService(io.flutter.run.daemon.DeviceService) Application(com.intellij.openapi.application.Application)

Example 13 with FlutterDevice

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

the class DeviceSelection method withDevices.

/**
 * Returns a new snapshot with the devices changed and the selection updated appropriately.
 */
@NotNull
DeviceSelection withDevices(@NotNull List<FlutterDevice> newDevices) {
    final String selectedId = selection == null ? null : selection.deviceId();
    final Optional<FlutterDevice> selectedDevice = findById(newDevices, selectedId);
    // If there's no selected device, default the first ephemoral one in the list.
    final FlutterDevice firstEphemoral = newDevices.stream().filter(FlutterDevice::ephemeral).findFirst().orElse(null);
    return new DeviceSelection(ImmutableList.copyOf(newDevices), selectedDevice.orElse(firstEphemoral));
}
Also used : FlutterDevice(io.flutter.run.FlutterDevice) NotNull(org.jetbrains.annotations.NotNull)

Example 14 with FlutterDevice

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

the class BazelRunConfig method getState.

@NotNull
@Override
public LaunchState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
    final BazelFields launchFields = fields.copy();
    try {
        launchFields.checkRunnable(env.getProject());
    } catch (RuntimeConfigurationError e) {
        throw new ExecutionException(e);
    }
    final Workspace workspace = fields.getWorkspace(getProject());
    final VirtualFile workspaceRoot = workspace.getRoot();
    final RunMode mode = RunMode.fromEnv(env);
    final Module module = ModuleUtil.findModuleForFile(workspaceRoot, env.getProject());
    final LaunchState.CreateAppCallback createAppCallback = (@Nullable FlutterDevice device) -> {
        if (device == null)
            return null;
        final GeneralCommandLine command = getCommand(env, device);
        return FlutterApp.start(env, env.getProject(), module, mode, device, command, StringUtil.capitalize(mode.mode()) + "BazelApp", "StopBazelApp");
    };
    return new LaunchState(env, workspaceRoot, workspaceRoot, this, createAppCallback);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlutterDevice(io.flutter.run.FlutterDevice) RunMode(io.flutter.run.common.RunMode) LaunchState(io.flutter.run.LaunchState) ExecutionException(com.intellij.execution.ExecutionException) Module(com.intellij.openapi.module.Module) Workspace(io.flutter.bazel.Workspace) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with FlutterDevice

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

the class LaunchCommandsTest method producesCorrectCommandLineWithAdditionalArgs.

@Test
public void producesCorrectCommandLineWithAdditionalArgs() throws ExecutionException {
    final BazelFields fields = setupBazelFields("bazel_target", null, "additional_args", false);
    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("additional_args");
    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