Unverified Commit d50d9c5e authored by Kenzie Schmoll's avatar Kenzie Schmoll Committed by GitHub

Register flutterVersion service in flutter_tools. (#39524)

* Register getFlutterVersion service in flutter_tools.

* Add short revision ids to response.

* Rename method and remove obsolete comments.

* Fix broken test by adding sendPeerNotifications flag.

* Implement mockPeer.sendNotification.
parent 57e6042f
......@@ -20,6 +20,7 @@ import 'base/io.dart' as io;
import 'base/utils.dart';
import 'convert.dart' show base64;
import 'globals.dart';
import 'version.dart';
import 'vmservice_record_replay.dart';
/// Override `WebSocketConnector` in [context] to use a different constructor
......@@ -138,8 +139,6 @@ class VMService {
}
});
// If the Flutter Engine doesn't support service registration this will
// have no effect
_peer.sendNotification('registerService', <String, String>{
'service': 'reloadSources',
'alias': 'Flutter Tools',
......@@ -164,14 +163,25 @@ class VMService {
}
});
// If the Flutter Engine doesn't support service registration this will
// have no effect
_peer.sendNotification('registerService', <String, String>{
'service': 'hotRestart',
'alias': 'Flutter Tools',
});
}
_peer.registerMethod('flutterVersion', (rpc.Parameters params) async {
final FlutterVersion version = FlutterVersion();
final Map<String, Object> versionJson = version.toJson();
versionJson['frameworkRevisionShort'] = version.frameworkRevisionShort;
versionJson['engineRevisionShort'] = version.engineRevisionShort;
return versionJson;
});
_peer.sendNotification('registerService', <String, String>{
'service': 'flutterVersion',
'alias': 'Flutter Tools',
});
if (compileExpression != null) {
_peer.registerMethod('compileExpression', (rpc.Parameters params) async {
final String isolateId = params['isolateId'].asString;
......
......@@ -52,9 +52,12 @@ class MockPeer implements rpc.Peer {
@override
void sendNotification(String method, [ dynamic parameters ]) {
throw 'unexpected call to sendNotification';
// this does get called
sentNotifications.putIfAbsent(method, () => <dynamic>[]).add(parameters);
}
Map<String, List<dynamic>> sentNotifications = <String, List<dynamic>>{};
bool isolatesEnabled = false;
Future<void> _getVMLatch;
......@@ -192,6 +195,12 @@ void main() {
final MockPeer mockPeer = MockPeer();
expect(mockPeer.returnedFromSendRequest, 0);
final VMService vmService = VMService(mockPeer, null, null, null, null, null);
expect(mockPeer.sentNotifications, contains('registerService'));
final List<String> registeredServices =
mockPeer.sentNotifications['registerService']
.map((dynamic service) => (service as Map<String, String>)['service'])
.toList();
expect(registeredServices, contains('flutterVersion'));
vmService.getVM().then((void value) { done = true; });
expect(done, isFalse);
expect(mockPeer.returnedFromSendRequest, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment