Skip to content

Commit d83bf64

Browse files
authored
Fix "Open Flutter DevTools" action opening a instance DevTools disconnected from the VM service (#8585)
1 parent 5f0ea91 commit d83bf64

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/io/flutter/run/OpenDevToolsAction.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
package io.flutter.run;
77

8+
import com.intellij.execution.process.ProcessHandler;
89
import com.intellij.ide.browsers.BrowserLauncher;
910
import com.intellij.openapi.actionSystem.ActionUpdateThread;
1011
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -26,12 +27,13 @@
2627
import org.jetbrains.annotations.NotNull;
2728
import org.jetbrains.annotations.Nullable;
2829

30+
import java.util.List;
2931
import java.util.Objects;
3032

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

3739
public OpenDevToolsAction() {
@@ -72,6 +74,19 @@ public void actionPerformed(@NotNull final AnActionEvent event) {
7274
return;
7375
}
7476

77+
// This action is registered in plugin.xml with the default constructor.
78+
// Therefore, if a user triggers this from the IDE, even if there is a
79+
// running Flutter app myConnector will be null. In that case, check for a
80+
// Flutter app first and use its connector instead.
81+
// TODO(https://github.com/flutter/flutter-intellij/issues/8583): Open the
82+
// running app instead of the first one listed in the project processes.
83+
if (myConnector == null) {
84+
final List<FlutterApp> apps = FlutterApp.allFromProjectProcess(project);
85+
if (!apps.isEmpty()) {
86+
myConnector = apps.get(0).getConnector();
87+
}
88+
}
89+
7590
AsyncUtils.whenCompleteUiThread(Objects.requireNonNull(DevToolsService.getInstance(project).getDevToolsInstance()), (instance, ex) -> {
7691
if (project.isDisposed()) {
7792
return;

0 commit comments

Comments
 (0)