use of org.dartlang.vm.service.element.Event in project flutter-intellij by flutter.
the class ObservatoryActionGroup method debugActiveHelper.
private void debugActiveHelper(@NotNull FlutterApp app, @Nullable InspectorService inspectorService) {
if (FlutterSettings.getInstance().isOpenInspectorOnAppLaunch()) {
autoActivateToolWindow();
}
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
if (!(toolWindowManager instanceof ToolWindowManagerEx)) {
return;
}
final ToolWindow toolWindow = toolWindowManager.getToolWindow(FlutterView.TOOL_WINDOW_ID);
if (toolWindow == null) {
return;
}
if (isDisplayingEmptyContent()) {
removeEmptyContent(toolWindow);
}
listenForRenderTreeActivations(toolWindow);
addInspector(app, inspectorService, toolWindow);
app.getVmService().addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void connectionOpened() {
onAppChanged(app);
}
@Override
public void received(String streamId, Event event) {
if (StringUtil.equals(streamId, VmService.EXTENSION_STREAM_ID)) {
if (StringUtil.equals("Flutter.Frame", event.getExtensionKind())) {
handleFlutterFrame(app);
}
}
}
@Override
public void connectionClosed() {
ApplicationManager.getApplication().invokeLater(() -> {
final ContentManager contentManager = toolWindow.getContentManager();
onAppChanged(app);
final PerAppState state = perAppViewState.remove(app);
if (state != null && state.content != null) {
contentManager.removeContent(state.content, true);
}
if (perAppViewState.isEmpty()) {
// No more applications are running.
displayEmptyContent(toolWindow);
}
});
}
});
onAppChanged(app);
app.addStateListener(new FlutterApp.FlutterAppListener() {
public void notifyAppRestarted() {
// When we get a restart finishes, queue up a notification to the flutter view
// actions. We don't notify right away because the new isolate can take a little
// while to start up. We wait until we get the first frame event, which is
// enough of an indication that the isolate and flutter framework are initialized
// enough to receive service calls (for example, calls to restore various framework
// debugging settings).
final PerAppState state = getStateForApp(app);
if (state != null) {
state.sendRestartNotificationOnNextFrame = true;
}
}
});
}
use of org.dartlang.vm.service.element.Event in project intellij-plugins by JetBrains.
the class VmServiceBase method processResponse.
/**
* Process the response from the VM service and forward that response to the consumer associated
* with the response id.
*/
void processResponse(String jsonText) {
if (jsonText == null || jsonText.isEmpty()) {
return;
}
// Decode the JSON
JsonObject json;
try {
json = (JsonObject) new JsonParser().parse(jsonText);
} catch (Exception e) {
Logging.getLogger().logError("Parse response failed: " + jsonText, e);
return;
}
// Forward events
JsonElement idElem = json.get(ID);
if (idElem == null) {
String method;
try {
method = json.get(METHOD).getAsString();
} catch (Exception e) {
Logging.getLogger().logError("Event missing " + METHOD, e);
return;
}
if (!"streamNotify".equals(method)) {
Logging.getLogger().logError("Unknown event " + METHOD + ": " + method);
return;
}
JsonObject params;
try {
params = json.get(PARAMS).getAsJsonObject();
} catch (Exception e) {
Logging.getLogger().logError("Event missing " + PARAMS, e);
return;
}
String streamId;
try {
streamId = params.get(STREAM_ID).getAsString();
} catch (Exception e) {
Logging.getLogger().logError("Event missing " + STREAM_ID, e);
return;
}
Event event;
try {
event = new Event(params.get(EVENT).getAsJsonObject());
} catch (Exception e) {
Logging.getLogger().logError("Event missing " + EVENT, e);
return;
}
forwardEvent(streamId, event);
return;
}
// Get the consumer associated with this response
String id;
try {
id = idElem.getAsString();
} catch (Exception e) {
Logging.getLogger().logError("Response missing " + ID, e);
return;
}
Consumer consumer = consumerMap.remove(id);
if (consumer == null) {
Logging.getLogger().logError("No consumer associated with " + ID + ": " + id);
return;
}
// Forward the response if the request was successfully executed
JsonElement resultElem = json.get(RESULT);
if (resultElem != null) {
JsonObject result;
try {
result = resultElem.getAsJsonObject();
} catch (Exception e) {
Logging.getLogger().logError("Response has invalid " + RESULT, e);
return;
}
String responseType;
try {
responseType = result.get(TYPE).getAsString();
} catch (Exception e) {
Logging.getLogger().logError("Response missing " + TYPE, e);
return;
}
forwardResponse(consumer, responseType, result);
return;
}
// Forward an error if the request failed
resultElem = json.get(ERROR);
if (resultElem != null) {
JsonObject error;
try {
error = resultElem.getAsJsonObject();
} catch (Exception e) {
Logging.getLogger().logError("Response has invalid " + RESULT, e);
return;
}
consumer.onError(new RPCError(error));
return;
}
Logging.getLogger().logError("Response missing " + RESULT + " and " + ERROR);
}
Aggregations