浏览代码

add getRootWidgetSummaryTree call and use Future.then

/zxw-devTools
guanghuispark 3 年前
当前提交
e78d9dab
共有 4 个文件被更改,包括 170 次插入91 次删除
  1. 4
      com.unity.uiwidgets.devtools/Editor/v2/src/framework/framework_core.cs
  2. 69
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs
  3. 164
      com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs
  4. 24
      com.unity.uiwidgets.devtools/Editor/v2/src/service_manager.cs

4
com.unity.uiwidgets.devtools/Editor/v2/src/framework/framework_core.cs


{
public static void initGlobals()
{
// setGlobal(ServiceConnectionManager, ServiceConnectionManager());
// setGlobal(MessageBus, MessageBus());
Globals.setGlobal(typeof(ServiceConnectionManager), new ServiceConnectionManager());
// Globals.setGlobal(MessageBus, MessageBus());
Globals.setGlobal(typeof(FrameworkController), new FrameworkController());
}
}

69
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_controller.cs


try
{
// var group = _treeGroups.next;
var group = new ObjectGroup("inspector",inspectorService);
// var node = detailsSubtree
// ? group.getDetailsSubtree(subtreeRoot, subtreeDepth: subtreeDepth)
// : group.getRoot(treeType);
// RemoteDiagnosticsNode node = null;
// group.getRoot(treeType).then_<RemoteDiagnosticsNode>((v) =>
// {
// node = v;
// if (node == null || group.disposed) {
// return new SynchronousFuture(null);
// }
// _treeGroups.promoteNext();
// // clearValueToInspectorTreeNodeMapping();
// if (node != null) {
// InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
// node:inspectorTree.createNode(),
// diagnosticsNode: node,
// expandChildren: true,
// expandProperties: false
// );
// inspectorTree.root = rootNode;
// } else {
// inspectorTree.root = inspectorTree.createNode();
// }
// return FutureOr.nil;
// });
RemoteDiagnosticsNode node = group._getRoot(treeType);
if (node == null || group.disposed) {
return new SynchronousFuture(null);
}
_treeGroups.promoteNext();
// clearValueToInspectorTreeNodeMapping();
if (node != null) {
InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
node:inspectorTree.createNode(),
diagnosticsNode: node,
expandChildren: true,
expandProperties: false
);
inspectorTree.root = rootNode;
} else {
inspectorTree.root = inspectorTree.createNode();
}
var group = _treeGroups.next;
RemoteDiagnosticsNode node = null;
group.getRoot(treeType).then_<RemoteDiagnosticsNode>((v) =>
{
node = v;
if (node == null || group.disposed) {
return new SynchronousFuture(null);
}
_treeGroups.promoteNext();
// clearValueToInspectorTreeNodeMapping();
if (node != null) {
InspectorTreeNode rootNode = inspectorTree.setupInspectorTreeNode(
node:inspectorTree.createNode(),
diagnosticsNode: node,
expandChildren: true,
expandProperties: false
);
inspectorTree.root = rootNode;
} else {
inspectorTree.root = inspectorTree.createNode();
}
return FutureOr.nil;
});
// refreshSelection(newSelection, detailsSelection, setSubtreeRoot);
} catch (Exception e) {
Debug.Log(e);

164
com.unity.uiwidgets.devtools/Editor/v2/src/inspector/inspector_service.cs


{
groupName = $"{debugName}_${InspectorService.nextGroupId}";
InspectorService.nextGroupId++;
this.inspectorService = inspectorService;
}
/// Object group all objects in this arena are allocated with.

// EvalOnDartLibrary inspectorLibrary => inspectorService.inspectorLibrary;
public Future dispose() {
// var disposeComplete = invokeVoidServiceMethod("disposeGroup", groupName);
// disposed = true;

bool useDaemonApi => inspectorService.useDaemonApi;
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:

throw new Exception("Unexpected FlutterTreeType");
}
public RemoteDiagnosticsNode _getRoot(FlutterTreeType type) {
// There is no excuse to call this method on a disposed group.
D.assert(!disposed);
switch (type) {
case FlutterTreeType.widget:
return _getRootWidget();
case FlutterTreeType.renderObject:
return null;
Future<RemoteDiagnosticsNode> invokeServiceMethodReturningNode(string methodName) {
if (disposed) return null;
if (useDaemonApi) {
return parseDiagnosticsNodeDaemon(invokeServiceMethodDaemon(methodName));
throw new Exception("Unexpected FlutterTreeType");
// else {
// return parseDiagnosticsNodeObservatory(
// invokeServiceMethodObservatory(methodName));
// }
return null;
RemoteDiagnosticsNode _getRootWidget() {
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
Future<object> invokeServiceMethodDaemon(string methodName, string objectGroup = null) {
return invokeServiceMethodDaemonParams(methodName,
new Dictionary<string, object>(){
{"objectGroup",objectGroup ?? groupName}
}
);
}
Future<object> invokeServiceMethodDaemonParams(
string methodName,
Dictionary<string, object> _params
) {
if (methodName == "getRootWidgetSummaryTree")
{
return _callServiceExtensionLocal();
}
var callMethodName = $"ext.flutter.inspector.{methodName}";
if (!Globals.serviceManager.serviceExtensionManager
.isServiceExtensionAvailable(callMethodName)) {
return null;
}
return _callServiceExtension(callMethodName, _params);
}
Future<object> _callServiceExtension(
string extension, Dictionary<string, object> args) {
if (disposed)
{
return new SynchronousFuture<object>(null);
}
return null;
// return inspectorLibrary.addRequest(this, () => {
// var r = inspectorService.vmService.callServiceExtension(
// extension,
// isolateId: inspectorService.inspectorLibrary.isolateId,
// args: args
// );
// if (disposed) return null;
// var json = r.json;
// if (json["errorMessage"] != null) {
// throw new Exception($"{extension} -- {json["errorMessage"]}");
// }
// return json["result"];
// });
}
public Future<object> _callServiceExtensionLocal()
{
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";

{"description","this is a description"},
}
};
return new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null);
return new SynchronousFuture<object>(widgetTree);
}
Future<RemoteDiagnosticsNode> parseDiagnosticsNodeDaemon(
Future<object> json) {
if (disposed) return null;
return json.then((value) =>
{
var res = FutureOr.value(parseDiagnosticsNodeHelper((Dictionary<string,object>)value));
return res;
}).to<RemoteDiagnosticsNode>();
}
RemoteDiagnosticsNode parseDiagnosticsNodeHelper(
Dictionary<string, object> jsonElement) {
if (disposed) return null;
if (jsonElement == null) return null;
return new RemoteDiagnosticsNode(jsonElement, FutureOr.value(this), false, null);
// Future<RemoteDiagnosticsNode> parseDiagnosticsNodeObservatory(
// FutureOr<InstanceRef> instanceRefFuture) {
// return parseDiagnosticsNodeHelper(instanceRefToJson(instanceRefFuture));
// }
//
// Future<InstanceRef> invokeServiceMethodObservatory(string methodName) {
// return invokeServiceMethodObservatory1(methodName, groupName);
// }
//
// Future<InstanceRef> invokeServiceMethodObservatory1(
// string methodName, string arg1) {
// return inspectorLibrary.eval(
// "WidgetInspectorService.instance.$methodName('$arg1')",
// isAlive: this
// );
// }
// return invokeServiceMethodReturningNode('getRootWidgetSummaryTree');
return invokeServiceMethodReturningNode("getRootWidgetSummaryTree");
Dictionary<string, object> widgetTree = new Dictionary<string, object>();
widgetTree["hasChildren"] = true;
widgetTree["name"] = "inspector";
widgetTree["children"] = new List<object>()
{
new Text("text1"),
new Text("text2"),
new Text("text3"),
new Text("text4"),
new Text("text5"),
};
widgetTree["properties"] = new List<object>()
{
"properties_1",
"properties_2",
"properties_3",
"properties_4",
"properties_5",
};
return Future.value(FutureOr.value(new RemoteDiagnosticsNode(widgetTree,
inspectorService: FutureOr.value(inspectorService),
true,
null))).to<RemoteDiagnosticsNode>();
}

public ObjectGroup next {
get
{
// _next ??= inspectorService.createObjectGroup(debugName);
if (_next == null)
{
_next = inspectorService.createObjectGroup(debugName);
}
return _next;
}

{
var group = createObjectGroup("temp");
var root = group.getRoot(FlutterTreeType.widget);
return Future.value("aaa").to<string>();
return Future.value("null").to<string>();
ObjectGroup createObjectGroup(string debugName) {
public ObjectGroup createObjectGroup(string debugName) {
public bool useDaemonApi {
get
{
return true;
}
}
// static Future<InspectorService> create(VmService vmService) async {
// assert(_inspectorDependenciesLoaded);

24
com.unity.uiwidgets.devtools/Editor/v2/src/service_manager.cs


using System.Collections.Generic;
namespace Unity.UIWidgets.DevTools
{
public class ServiceConnectionManager

_isolateManager = new IsolateManager();
ServiceExtensionManager serviceExtensionManager = new ServiceExtensionManager();
isolateManager._serviceExtensionManager = serviceExtensionManager;
serviceExtensionManager._isolateManager = isolateManager;
_isolateManager = isolateManager;
_serviceExtensionManager = serviceExtensionManager;
public ServiceExtensionManager serviceExtensionManager =>
_serviceExtensionManager;
ServiceExtensionManager _serviceExtensionManager;
public ServiceExtensionManager _serviceExtensionManager;
}
public class ServiceExtensionManager
{
public IsolateManager _isolateManager;
List<string> _serviceExtensions = new List<string>();
List<string> _pendingServiceExtensions = new List<string>();
public bool isServiceExtensionAvailable(string name) {
return _serviceExtensions.Contains(name) ||
_pendingServiceExtensions.Contains(name);
}
}
}
正在加载...
取消
保存