From 24e2b238d46702de2bf9fd4ebcafbc3fc95f4f46 Mon Sep 17 00:00:00 2001 From: Danny Tuppeny Date: Mon, 28 May 2018 22:02:53 +0100 Subject: [PATCH] Send an event at startup with the protocol version and pid (#17873) * Send an event at startup with the protocol version and pid The pid will help with some of the issues of terminate the process when launched through a shell script and the version will allow clients to make decisions about supported features. I've also bumped the protocol version number for two reasons: 1. This change 2. We didn't increase it when we added the previous emulator commands --- packages/flutter_tools/lib/src/commands/daemon.dart | 10 +++++++++- packages/flutter_tools/test/commands/daemon_test.dart | 7 +++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/daemon.dart b/packages/flutter_tools/lib/src/commands/daemon.dart index 21373f93352..6cdb2aa267c 100644 --- a/packages/flutter_tools/lib/src/commands/daemon.dart +++ b/packages/flutter_tools/lib/src/commands/daemon.dart @@ -28,7 +28,7 @@ import '../runner/flutter_command.dart'; import '../tester/flutter_tester.dart'; import '../vmservice.dart'; -const String protocolVersion = '0.2.0'; +const String protocolVersion = '0.3.0'; /// A server process command. This command will start up a long-lived server. /// It reads JSON-RPC based commands from stdin, executes them, and returns @@ -242,6 +242,14 @@ class DaemonDomain extends Domain { registerHandler('version', version); registerHandler('shutdown', shutdown); + sendEvent( + 'daemon.connected', + { + 'version': protocolVersion, + 'pid': pid, + }, + ); + _subscription = daemon.notifyingLogger.onMessage.listen((LogMessage message) { if (daemon.logToStdout) { if (message.level == 'status') { diff --git a/packages/flutter_tools/test/commands/daemon_test.dart b/packages/flutter_tools/test/commands/daemon_test.dart index 6389c0d79a8..1a8a45ee6fe 100644 --- a/packages/flutter_tools/test/commands/daemon_test.dart +++ b/packages/flutter_tools/test/commands/daemon_test.dart @@ -209,7 +209,8 @@ void main() { notifyingLogger: notifyingLogger, ); - final Map response = await responses.stream.first; + final Map response = + await responses.stream.skipWhile(_isConnectedEvent).first; expect(response['event'], 'daemon.showMessage'); expect(response['params'], isMap); expect(response['params'], containsPair('level', 'warning')); @@ -249,7 +250,7 @@ void main() { daemon.deviceDomain.addDeviceDiscoverer(discoverer); discoverer.addDevice(new MockAndroidDevice()); - return responses.stream.first.then((Map response) { + return responses.stream.skipWhile(_isConnectedEvent).first.then((Map response) { expect(response['event'], 'device.added'); expect(response['params'], isMap); @@ -322,6 +323,8 @@ void main() { bool _notEvent(Map map) => map['event'] == null; +bool _isConnectedEvent(Map map) => map['event'] == 'daemon.connected'; + class MockAndroidWorkflow extends AndroidWorkflow { MockAndroidWorkflow({ this.canListDevices: true });