|
5 | 5 | */ |
6 | 6 | package io.flutter.run; |
7 | 7 |
|
| 8 | +import com.intellij.execution.process.ProcessHandler; |
8 | 9 | import com.intellij.ide.browsers.BrowserLauncher; |
9 | 10 | import com.intellij.openapi.actionSystem.ActionUpdateThread; |
10 | 11 | import com.intellij.openapi.actionSystem.AnActionEvent; |
|
26 | 27 | import org.jetbrains.annotations.NotNull; |
27 | 28 | import org.jetbrains.annotations.Nullable; |
28 | 29 |
|
| 30 | +import java.util.List; |
29 | 31 | import java.util.Objects; |
30 | 32 |
|
31 | 33 | public class OpenDevToolsAction extends DumbAwareAction { |
32 | 34 | private static final @NotNull Logger LOG = PluginLogger.createLogger(OpenDevToolsAction.class); |
33 | 35 | private static final String title = "Open Flutter DevTools in Browser"; |
34 | | - private final @Nullable ObservatoryConnector myConnector; |
| 36 | + private @Nullable ObservatoryConnector myConnector; |
35 | 37 | private final Computable<Boolean> myIsApplicable; |
36 | 38 |
|
37 | 39 | public OpenDevToolsAction() { |
@@ -72,6 +74,19 @@ public void actionPerformed(@NotNull final AnActionEvent event) { |
72 | 74 | return; |
73 | 75 | } |
74 | 76 |
|
| 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 | + |
75 | 90 | AsyncUtils.whenCompleteUiThread(Objects.requireNonNull(DevToolsService.getInstance(project).getDevToolsInstance()), (instance, ex) -> { |
76 | 91 | if (project.isDisposed()) { |
77 | 92 | return; |
|
0 commit comments