Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for stream to be available before loadSelection #5286

Merged
merged 3 commits into from
Feb 25, 2021
Merged
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
63 changes: 40 additions & 23 deletions src/io/flutter/inspector/InspectorGroupManagerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import io.flutter.run.FlutterAppManager;
import io.flutter.run.daemon.FlutterApp;
import io.flutter.utils.AsyncUtils;
import io.flutter.utils.StreamSubscription;
import io.flutter.vmService.ServiceExtensions;
import org.dartlang.vm.service.VmService;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -136,6 +138,7 @@ default void onSelectionChanged(DiagnosticsNode selection) {
private DiagnosticsNode selection;
private InspectorService inspectorService;
private InspectorObjectGroupManager selectionGroups;
private StreamSubscription<Boolean> onStructuredErrorsStream;

public InspectorGroupManagerService(Project project) {
FlutterAppManager.getInstance(project).getActiveAppAsStream().listen(
Expand Down Expand Up @@ -249,29 +252,39 @@ public void notifyVmServiceAvailable(VmService vmService) {
inspectorService = service;
selection = null;
selectionGroups = new InspectorObjectGroupManager(inspectorService, "selection");
loadSelection();

if (app != InspectorGroupManagerService.this.app) return;

service.addClient(new InspectorService.InspectorServiceClient() {
@Override
public void onInspectorSelectionChanged(boolean uiAlreadyUpdated, boolean textEditorUpdated) {
loadSelection();
}

@Override
public void onFlutterFrame() {
invokeOnAllListeners(Listener::onFlutterFrame);
}

@Override
public CompletableFuture<?> onForceRefresh() {
requestRepaint(true);
// Return null instead of a CompletableFuture as the
// InspectorService should not wait for our client to be ready.
return null;
}
});
// TODO (helin24): The specific stream we're checking here doesn't matter; we need a frame to be available before running
// loadSelection and other tasks.
if (onStructuredErrorsStream != null) {
Disposer.dispose(onStructuredErrorsStream);
}
onStructuredErrorsStream =
app.getVMServiceManager().hasServiceExtension(ServiceExtensions.toggleShowStructuredErrors.getExtension(), (hasData) -> {
if (hasData) {
loadSelection();

if (app != InspectorGroupManagerService.this.app) return;

service.addClient(new InspectorService.InspectorServiceClient() {
@Override
public void onInspectorSelectionChanged(boolean uiAlreadyUpdated, boolean textEditorUpdated) {
loadSelection();
}

@Override
public void onFlutterFrame() {
invokeOnAllListeners(Listener::onFlutterFrame);
}

@Override
public CompletableFuture<?> onForceRefresh() {
requestRepaint(true);
// Return null instead of a CompletableFuture as the
// InspectorService should not wait for our client to be ready.
return null;
}
});
}
});
});
}
};
Expand Down Expand Up @@ -304,5 +317,9 @@ public void dispose() {
}
this.app = null;
appListener = null;
if (onStructuredErrorsStream != null) {
Disposer.dispose(onStructuredErrorsStream);
onStructuredErrorsStream = null;
}
}
}