Search in sources :

Example 1 with SdkAttachConfig

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

the class AttachDebuggerAction method onAttachTermination.

private static void onAttachTermination(@NotNull Project project, @NotNull Consumer<Project> runner) {
    final MessageBusConnection connection = project.getMessageBus().connect();
    // Need an ExecutionListener to clean up project-scoped state when the Stop button is clicked.
    connection.subscribe(ExecutionManager.EXECUTION_TOPIC, new ExecutionListener() {

        Object handler;

        @Override
        public void processStarted(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler) {
            if (env.getRunProfile() instanceof SdkAttachConfig) {
                this.handler = handler;
            }
        }

        @Override
        public void processTerminated(@NotNull String executorId, @NotNull ExecutionEnvironment env, @NotNull ProcessHandler handler, int exitCode) {
            if (this.handler == handler) {
                runner.accept(project);
                connection.disconnect();
            }
        }
    });
}
Also used : MessageBusConnection(com.intellij.util.messages.MessageBusConnection) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessHandler(com.intellij.execution.process.ProcessHandler) SdkAttachConfig(io.flutter.run.SdkAttachConfig)

Example 2 with SdkAttachConfig

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

the class AttachDebuggerAction method startCommand.

@Override
public void startCommand(@NotNull Project project, @NotNull FlutterSdk sdk, @Nullable PubRoot root, @NotNull DataContext context) {
    // NOTE: When making changes here, consider making similar changes to RunFlutterAction.
    FlutterInitializer.sendAnalyticsAction(this);
    RunConfiguration configuration = findRunConfig(project);
    if (configuration == null) {
        final RunnerAndConfigurationSettings settings = RunManagerEx.getInstanceEx(project).getSelectedConfiguration();
        if (settings == null) {
            showSelectConfigDialog();
            return;
        }
        configuration = settings.getConfiguration();
        if (!(configuration instanceof SdkRunConfig)) {
            if (project.isDefault() || !FlutterSdkUtil.hasFlutterModules(project)) {
                return;
            }
            showSelectConfigDialog();
            return;
        }
    }
    final SdkAttachConfig sdkRunConfig = new SdkAttachConfig((SdkRunConfig) configuration);
    final Executor executor = RunFlutterAction.getExecutor(ToolWindowId.DEBUG);
    if (executor == null) {
        return;
    }
    final ExecutionEnvironmentBuilder builder = ExecutionEnvironmentBuilder.create(executor, sdkRunConfig);
    final ExecutionEnvironment env = builder.activeTarget().dataContext(context).build();
    FlutterLaunchMode.addToEnvironment(env, FlutterLaunchMode.DEBUG);
    if (project.getUserData(ATTACH_IS_ACTIVE) == null) {
        project.putUserData(ATTACH_IS_ACTIVE, ThreeState.fromBoolean(false));
        onAttachTermination(project, (p) -> p.putUserData(ATTACH_IS_ACTIVE, null));
    }
    ProgramRunnerUtil.executeConfiguration(env, false, true);
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) SdkRunConfig(io.flutter.run.SdkRunConfig) ExecutionEnvironmentBuilder(com.intellij.execution.runners.ExecutionEnvironmentBuilder) SdkAttachConfig(io.flutter.run.SdkAttachConfig)

Aggregations

ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 SdkAttachConfig (io.flutter.run.SdkAttachConfig)2 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ExecutionEnvironmentBuilder (com.intellij.execution.runners.ExecutionEnvironmentBuilder)1 MessageBusConnection (com.intellij.util.messages.MessageBusConnection)1 SdkRunConfig (io.flutter.run.SdkRunConfig)1