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

Add hot reload button and support service registration. #90

Merged
merged 7 commits into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
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
35 changes: 34 additions & 1 deletion lib/service_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ServiceConnectionManager {
new StreamController<VmServiceWrapper>.broadcast();
final StreamController<Null> _connectionClosedController =
new StreamController<Null>.broadcast();
final Map<String, List<String>> methodsForService = {};

IsolateManager _isolateManager;
ServiceExtensionManager _serviceExtensionManager;
Expand All @@ -51,6 +52,30 @@ class ServiceConnectionManager {

Stream<Null> get onConnectionClosed => _connectionClosedController.stream;

Future<Response> callService(String name, {Map args}) {
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved
final registered = methodsForService[name] ?? const [];
if (registered.length != 1) {
throw Exception('Expected one registered service for $name but found '
'${registered.length}');
}
return service.callMethod(registered.first, args: args);
}

/// Call a service that may have been registered by multiple clients.
///
/// For example, a service to navigate a code editor to a specific line and
/// column might be registered by multiple code editors.
Future<List<Response>> callMulticastService(String name, {String isolateId, Map args}) {
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved
final registered = methodsForService[name] ?? const [];
if (registered.isNotEmpty) {
return Future.wait(registered.map((String method) {
return service.callMethod(method, isolateId: isolateId, args: args);
}));
} else {
return Future.value(const []);
}
}

Future<void> vmServiceOpened(
VmServiceWrapper service, Future<void> onClosed) async {
try {
Expand All @@ -62,6 +87,13 @@ class ServiceConnectionManager {
}

this.service = service;

service.onServiceEvent.listen((e) {
if (e.kind == EventKind.kServiceRegistered) {
methodsForService.putIfAbsent(e.service, () => []).add(e.method);
}
});

_isolateManager._service = service;
_serviceExtensionManager._service = service;

Expand All @@ -85,7 +117,8 @@ class ServiceConnectionManager {
'Timeline',
'Extension',
'_Graph',
'_Logging'
'_Logging',
'_Service',
];
await Future.wait(streamIds.map((id) => service.streamListen(id)));
} catch (e) {
Expand Down
11 changes: 11 additions & 0 deletions lib/ui/ui_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,14 @@ CoreElement createExtensionCheckBox(String extensionName) {
text,
]));
}

// TODO(kenzieschmoll): add hotRestart button, register method in flutter_tools.

CoreElement createHotReloadButton() {
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved
final PButton button = new PButton('Hot Reload')..small();
button.click(() async {
await serviceManager.callMulticastService('reloadSources',
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved
kenzieschmoll marked this conversation as resolved.
Show resolved Hide resolved
isolateId: serviceManager.isolateManager.selectedIsolate.id);
});
return button;
}