Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/io/flutter/run/OpenDevToolsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package io.flutter.run;

import com.intellij.execution.process.ProcessHandler;
import com.intellij.ide.browsers.BrowserLauncher;
import com.intellij.openapi.actionSystem.ActionUpdateThread;
import com.intellij.openapi.actionSystem.AnActionEvent;
Expand All @@ -26,12 +27,13 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Objects;

public class OpenDevToolsAction extends DumbAwareAction {
private static final @NotNull Logger LOG = PluginLogger.createLogger(OpenDevToolsAction.class);
private static final String title = "Open Flutter DevTools in Browser";
private final @Nullable ObservatoryConnector myConnector;
private @Nullable ObservatoryConnector myConnector;
private final Computable<Boolean> myIsApplicable;

public OpenDevToolsAction() {
Expand Down Expand Up @@ -72,6 +74,19 @@ public void actionPerformed(@NotNull final AnActionEvent event) {
return;
}

// This action is registered in plugin.xml with the default constructor.
// Therefore, if a user triggers this from the IDE, even if there is a
// running Flutter app myConnector will be null. In that case, check for a
// Flutter app first and use its connector instead.
// TODO(https://github.com/flutter/flutter-intellij/issues/8583): Open the
// running app instead of the first one listed in the project processes.
if (myConnector == null) {
final List<FlutterApp> apps = FlutterApp.allFromProjectProcess(project);
if (!apps.isEmpty()) {
myConnector = apps.get(0).getConnector();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to find the currently activated app instead of always using the first?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out a way to do that unfortunately 😮‍💨 I added a TODO though to capture that.

}
}

AsyncUtils.whenCompleteUiThread(Objects.requireNonNull(DevToolsService.getInstance(project).getDevToolsInstance()), (instance, ex) -> {
if (project.isDisposed()) {
return;
Expand Down
Loading