Skip to content
Merged
Changes from 2 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
14 changes: 13 additions & 1 deletion src/io/flutter/run/OpenDevToolsAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,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 +73,17 @@ 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.
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