flutter/packages/flutter_tools/tool/daemon_client.dart
Ian Hickson 449f4a6673
License update (#45373)
* Update project.pbxproj files to say Flutter rather than Chromium

Also, the templates now have an empty organization so that we don't cause people to give their apps a Flutter copyright.

* Update the copyright notice checker to require a standard notice on all files

* Update copyrights on Dart files. (This was a mechanical commit.)

* Fix weird license headers on Dart files that deviate from our conventions; relicense Shrine.

Some were already marked "The Flutter Authors", not clear why. Their
dates have been normalized. Some were missing the blank line after the
license. Some were randomly different in trivial ways for no apparent
reason (e.g. missing the trailing period).

* Clean up the copyrights in non-Dart files. (Manual edits.)

Also, make sure templates don't have copyrights.

* Fix some more ORGANIZATIONNAMEs
2019-11-27 15:04:02 -08:00

101 lines
3 KiB
Dart

// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'package:flutter_tools/src/base/common.dart';
Process daemon;
// To use, start from the console and enter:
// version: print version
// shutdown: terminate the server
// start: start an app
// stop: stop a running app
// devices: list devices
// emulators: list emulators
// launch: launch an emulator
Future<void> main() async {
daemon = await Process.start('dart', <String>['bin/flutter_tools.dart', 'daemon']);
print('daemon process started, pid: ${daemon.pid}');
daemon.stdout
.transform<String>(utf8.decoder)
.transform<String>(const LineSplitter())
.listen((String line) => print('<== $line'));
daemon.stderr.listen(stderr.add);
stdout.write('> ');
stdin.transform<String>(utf8.decoder).transform<String>(const LineSplitter()).listen((String line) {
final List<String> words = line.split(' ');
if (line == 'version' || line == 'v') {
_send(<String, dynamic>{'method': 'daemon.version'});
} else if (line == 'shutdown' || line == 'q') {
_send(<String, dynamic>{'method': 'daemon.shutdown'});
} else if (words.first == 'start') {
_send(<String, dynamic>{
'method': 'app.start',
'params': <String, dynamic>{
'deviceId': words[1],
'projectDirectory': words[2],
'launchMode': words[3],
},
});
} else if (words.first == 'stop') {
if (words.length > 1) {
_send(<String, dynamic>{
'method': 'app.stop',
'params': <String, dynamic>{'appId': words[1]},
});
} else {
_send(<String, dynamic>{'method': 'app.stop'});
}
} else if (words.first == 'restart') {
if (words.length > 1) {
_send(<String, dynamic>{
'method': 'app.restart',
'params': <String, dynamic>{'appId': words[1]},
});
} else {
_send(<String, dynamic>{'method': 'app.restart'});
}
} else if (line == 'devices') {
_send(<String, dynamic>{'method': 'device.getDevices'});
} else if (line == 'emulators') {
_send(<String, dynamic>{'method': 'emulator.getEmulators'});
} else if (words.first == 'emulator-launch') {
_send(<String, dynamic>{
'method': 'emulator.launch',
'params': <String, dynamic>{
'emulatorId': words[1],
},
});
} else if (line == 'enable') {
_send(<String, dynamic>{'method': 'device.enable'});
} else {
_send(<String, dynamic>{'method': line.trim()});
}
stdout.write('> ');
});
// Print in the callback can't fail.
unawaited(daemon.exitCode.then<void>((int code) {
print('daemon exiting ($code)');
exit(code);
}));
}
int id = 0;
void _send(Map<String, dynamic> map) {
map['id'] = id++;
final String str = '[${json.encode(map)}]';
daemon.stdin.writeln(str);
print('==> $str');
}